From 364e9ffdd241567a2a0507e40fcc02d13bfea280 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 13 Sep 2020 21:39:10 +0200 Subject: [PATCH] use single view mode button system, similar to channels --- .../gui/Posted/PostedListWidgetWithModel.cpp | 29 +++++++++++------- .../gui/Posted/PostedListWidgetWithModel.h | 1 + .../gui/Posted/PostedListWidgetWithModel.ui | 30 ++++--------------- 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index bcc7ae431..1e2c648b6 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -67,6 +67,10 @@ Q_DECLARE_METATYPE(RsPostedPost); // Delegate used to paint into the table of thumbnails +//=================================================================================================================================== +//== PostedPostDelegate == +//=================================================================================================================================== + std::ostream& operator<<(std::ostream& o,const QSize& s) { return o << s.width() << " x " << s.height() ; } void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const @@ -189,6 +193,10 @@ void PostedPostDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptio editor->setGeometry(option.rect); } +//=================================================================================================================================== +//== PostedListWidgetWithModel == +//=================================================================================================================================== + /** Constructor */ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedId, QWidget *parent) : GxsMessageFrameWidget(rsPosted, parent), @@ -214,8 +222,7 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts())); connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&))); - connect(ui->cardViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); - connect(ui->classicViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); + connect(ui->viewModeButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); connect(mPostedPostsModel,SIGNAL(boardPostsLoaded()),this,SLOT(postPostLoad())); @@ -251,9 +258,8 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI settingsChanged(); setGroupId(postedId); - ui->classicViewButton->setChecked(true); // inits both button checking consistency and delegate display mode variables. - - mPostedPostsModel->updateBoard(postedId); + mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); + switchDisplayMode(); // makes everything consistent and chooses classic view as default mEventHandlerId = 0; // Needs to be asynced because this function is called by another thread! @@ -265,18 +271,21 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI void PostedListWidgetWithModel::switchDisplayMode() { - if(sender() == ui->classicViewButton) + if(mPostedPostsDelegate->getDisplayMode() == BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW) { - whileBlocking(ui->cardViewButton)->setChecked(false); + ui->viewModeButton->setIcon(FilesDefs::getIconFromQtResourcePath(":images/classic.png")); + ui->viewModeButton->setToolTip(tr("Click to switch to card view")); + mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT); } else { - whileBlocking(ui->classicViewButton)->setChecked(false); + ui->viewModeButton->setIcon(FilesDefs::getIconFromQtResourcePath(":images/card.png")); + ui->viewModeButton->setToolTip(tr("Click to switch to compact view")); + mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); } - - forceRedraw(); + mPostedPostsModel->triggerRedraw(); } void PostedListWidgetWithModel::updateSorting(int s) diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index 60e2b510d..71cedaec1 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -55,6 +55,7 @@ public: void setCellWidth(int pix) { mCellWidthPix = pix; } void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; } + BoardPostDisplayWidget::DisplayMode getDisplayMode() const { return mDisplayMode; } public slots: void expandItem(RsGxsMessageId msgId,bool expanded); diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui index a3c43aaa6..12601ee74 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.ui @@ -350,6 +350,9 @@ p, li { white-space: pre-wrap; } + + 1 + 24 @@ -411,7 +414,7 @@ p, li { white-space: pre-wrap; } 0 - + true @@ -438,29 +441,6 @@ p, li { white-space: pre-wrap; } - - - - Card View - - - - :/images/card.png:/images/card.png - - - - 24 - 24 - - - - true - - - true - - - @@ -561,8 +541,8 @@ p, li { white-space: pre-wrap; } - +