From 2cce3963cbf86131be3075b7798aa9779ad2671c Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 12 Aug 2020 14:06:43 +0200 Subject: [PATCH] fixed expanding of compact items in boards --- .../src/gui/Posted/BoardPostDisplayWidget.cpp | 17 ++++++-- .../src/gui/Posted/BoardPostDisplayWidget.h | 5 ++- .../src/gui/Posted/BoardPostDisplayWidget.ui | 6 +++ .../gui/Posted/PostedListWidgetWithModel.cpp | 38 ++++++++++++------ .../gui/Posted/PostedListWidgetWithModel.h | 40 +++++++++++-------- 5 files changed, 70 insertions(+), 36 deletions(-) diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index 7be0a157a..73d323a58 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -47,8 +47,8 @@ const char *BoardPostDisplayWidget::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2 //== Base class BoardPostDisplayWidget == //=================================================================================================================================== -BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,QWidget *parent) - : QWidget(parent),mPost(post),dmode(mode),mExpanded(false),ui(new Ui::BoardPostDisplayWidget()) +BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,bool expanded,QWidget *parent) + : QWidget(parent),mPost(post),dmode(mode),mExpanded(expanded),ui(new Ui::BoardPostDisplayWidget()) { ui->setupUi(this); setup(); @@ -167,12 +167,14 @@ void BoardPostDisplayWidget::setup() ui->frame_picture->show(); ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png"))); ui->expandButton->setToolTip(tr("Hide")); + ui->expandButton->setChecked(true); } else { ui->frame_picture->hide(); ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/expand.png"))); ui->expandButton->setToolTip(tr("Expand")); + ui->expandButton->setChecked(false); } } else @@ -190,9 +192,10 @@ void BoardPostDisplayWidget::setup() ui->fromLabel->clear(); ui->siteLabel->clear(); - connect(ui->commentButton, SIGNAL( clicked()), this, SLOT(loadComments())); + connect(ui->expandButton, SIGNAL(toggled(bool)), this, SLOT(doExpand(bool))); + connect(ui->commentButton, SIGNAL(clicked()), this, SLOT(loadComments())); connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote())); - connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote())); + connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT(makeDownVote())); connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool))); QAction *CopyLinkAction = new QAction(QIcon(""),tr("Copy RetroShare Link"), this); @@ -339,6 +342,7 @@ void BoardPostDisplayWidget::setup() // FIX THIS UP LATER. ui->notes->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); + ui->pictureLabel_2->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); QTextDocument doc; doc.setHtml(ui->notes->text()); @@ -416,4 +420,9 @@ void BoardPostDisplayWidget::setup() #endif } +void BoardPostDisplayWidget::doExpand(bool e) +{ + std::cerr << "Expanding" << std::endl; + emit expand(mPost.mMeta.mMsgId,e); +} diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h index 434e486d1..e262a77f4 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h @@ -42,7 +42,7 @@ public: DISPLAY_MODE_COMPACT = 0x02 }; - BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode display_mode,QWidget *parent=nullptr); + BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode display_mode,bool expanded,QWidget *parent=nullptr); virtual ~BoardPostDisplayWidget(); static const char *DEFAULT_BOARD_IMAGE; @@ -55,7 +55,7 @@ protected slots: virtual void setup(); // to be overloaded by the different views - void doExpand(bool) {} + void doExpand(bool) ; void setComment(const RsGxsComment&) ; void setReadStatus(bool isNew, bool isUnread) ; @@ -67,6 +67,7 @@ protected slots: signals: void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down); + void expand(RsGxsMessageId,bool); protected: RsPostedPost mPost; diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui index 1c7f928db..abf5a5785 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.ui @@ -303,6 +303,9 @@ :/images/expand.png:/images/expand.png + + true + true @@ -433,6 +436,9 @@ true + + true + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp index 3dccf6e6f..5f64f2bab 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.cpp @@ -85,7 +85,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & painter->fillRect( option.rect, option.backgroundBrush); painter->restore(); - BoardPostDisplayWidget w(post,mDisplayMode); + BoardPostDisplayWidget w(post,mDisplayMode,isExpanded(post.mMeta.mMsgId)); w.adjustSize(); w.setFixedSize(option.rect.size()); @@ -120,32 +120,43 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & painter->restore(); } -QSize PostedPostDelegate::cellSize(const QSize& w) const -{ - return QSize(mCellWidthPix,mCellWidthPix * w.height()/(float)w.width()); -} - QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { // This is the only place where we actually set the size of cells RsPostedPost post = index.data(Qt::UserRole).value() ; - BoardPostDisplayWidget w(post,mDisplayMode); + BoardPostDisplayWidget w(post,mDisplayMode,isExpanded(post.mMeta.mMsgId)); w.adjustSize(); return w.size(); } +void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded) +{ + std::cerr << __PRETTY_FUNCTION__ << ": received expandItem signal. b=" << expanded << std::endl; + if(expanded) + mExpandedItems.insert(msgId); + else + mExpandedItems.erase(msgId); + + mPostListWidget->forceRedraw(); +} +bool PostedPostDelegate::isExpanded(const RsGxsMessageId &id) const +{ + return mExpandedItems.find(id) != mExpandedItems.end(); +} + QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { RsPostedPost post = index.data(Qt::UserRole).value() ; if(index.column() == RsPostedPostsModel::COLUMN_POSTS) { - QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent); + QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,isExpanded(post.mMeta.mMsgId),parent); QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool))); + QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(expandItem(RsGxsMessageId,bool))); w->adjustSize(); w->setFixedSize(option.rect.size()); @@ -184,9 +195,6 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts())); connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts())); - //connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnPostFiles(int,Qt::SortOrder))); - //connect(ui->channelFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumnFiles(int,Qt::SortOrder))); - 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())); @@ -243,13 +251,11 @@ void PostedListWidgetWithModel::switchDisplayMode() { whileBlocking(ui->cardViewButton)->setChecked(false); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT); - ui->postsTree->setUniformRowHeights(true); } else { whileBlocking(ui->classicViewButton)->setChecked(false); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); - ui->postsTree->setUniformRowHeights(false); } mPostedPostsModel->deepUpdate(); @@ -514,6 +520,11 @@ void PostedListWidgetWithModel::postPostLoad() whileBlocking(ui->filter_LE)->setText(QString()); } +void PostedListWidgetWithModel::forceRedraw() +{ + if(mPostedPostsModel) + mPostedPostsModel->deepUpdate(); +} void PostedListWidgetWithModel::updateDisplay(bool complete) { #ifdef DEBUG_CHANNEL @@ -534,6 +545,7 @@ void PostedListWidgetWithModel::updateDisplay(bool complete) #endif complete = true; } + if(complete) // need to update the group data, reload the messages etc. { updateGroupData(); diff --git a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h index 30cd9d40a..4e3f8171c 100644 --- a/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h +++ b/retroshare-gui/src/gui/Posted/PostedListWidgetWithModel.h @@ -42,28 +42,33 @@ class PostedListWidgetWithModel; class PostedPostDelegate: public QAbstractItemDelegate { - Q_OBJECT + Q_OBJECT - public: - PostedPostDelegate(PostedListWidgetWithModel *p,QObject *parent=0) : QAbstractItemDelegate(parent),mCellWidthPix(100),mPostListWidget(p),mDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT){} - virtual ~PostedPostDelegate(){} +public: + PostedPostDelegate(PostedListWidgetWithModel *p,QObject *parent=0) : QAbstractItemDelegate(parent),mCellWidthPix(100),mPostListWidget(p),mDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT){} + virtual ~PostedPostDelegate(){} - void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override; - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; - void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override; - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override; + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override; + void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - //int cellSize(const QFont& font) const; + void setCellWidth(int pix) { mCellWidthPix = pix; } + void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; } - void setCellWidth(int pix) { mCellWidthPix = pix; } - void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; } +public slots: + void expandItem(RsGxsMessageId msgId,bool expanded); - private: - QSize cellSize(const QSize& w) const; // Converts the supplied size to the cell size for the current container. - // The client should then scale its widget to fit the given size. - int mCellWidthPix; - PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on. - BoardPostDisplayWidget::DisplayMode mDisplayMode; +private: + // The class keeps a list of expanded items. Because items are constantly re-created, it is not possible + // to let the items themselves hold that information. + + bool isExpanded(const RsGxsMessageId& id) const; + + int mCellWidthPix; + PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on. + BoardPostDisplayWidget::DisplayMode mDisplayMode; + std::set mExpandedItems; }; class PostedListWidgetWithModel: public GxsMessageFrameWidget @@ -91,6 +96,7 @@ public: virtual bool navigate(const RsGxsMessageId&) override; void updateDisplay(bool complete) ; + void forceRedraw(); // does not re-load the data, but makes sure the underlying model triggers a full redraw, recomputes sizes, etc. #ifdef TODO /* FeedHolder */