fixed expanding of compact items in boards

This commit is contained in:
csoler 2020-08-12 14:06:43 +02:00
parent 20346fc30e
commit 2cce3963cb
5 changed files with 70 additions and 36 deletions

View file

@ -47,8 +47,8 @@ const char *BoardPostDisplayWidget::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2
//== Base class BoardPostDisplayWidget == //== Base class BoardPostDisplayWidget ==
//=================================================================================================================================== //===================================================================================================================================
BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,QWidget *parent) BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,bool expanded,QWidget *parent)
: QWidget(parent),mPost(post),dmode(mode),mExpanded(false),ui(new Ui::BoardPostDisplayWidget()) : QWidget(parent),mPost(post),dmode(mode),mExpanded(expanded),ui(new Ui::BoardPostDisplayWidget())
{ {
ui->setupUi(this); ui->setupUi(this);
setup(); setup();
@ -167,12 +167,14 @@ void BoardPostDisplayWidget::setup()
ui->frame_picture->show(); ui->frame_picture->show();
ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png"))); ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png")));
ui->expandButton->setToolTip(tr("Hide")); ui->expandButton->setToolTip(tr("Hide"));
ui->expandButton->setChecked(true);
} }
else else
{ {
ui->frame_picture->hide(); ui->frame_picture->hide();
ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/expand.png"))); ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/expand.png")));
ui->expandButton->setToolTip(tr("Expand")); ui->expandButton->setToolTip(tr("Expand"));
ui->expandButton->setChecked(false);
} }
} }
else else
@ -190,6 +192,7 @@ void BoardPostDisplayWidget::setup()
ui->fromLabel->clear(); ui->fromLabel->clear();
ui->siteLabel->clear(); ui->siteLabel->clear();
connect(ui->expandButton, SIGNAL(toggled(bool)), this, SLOT(doExpand(bool)));
connect(ui->commentButton, SIGNAL(clicked()), this, SLOT(loadComments())); connect(ui->commentButton, SIGNAL(clicked()), this, SLOT(loadComments()));
connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote())); connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT(makeDownVote())); connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT(makeDownVote()));
@ -339,6 +342,7 @@ void BoardPostDisplayWidget::setup()
// FIX THIS UP LATER. // 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->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; QTextDocument doc;
doc.setHtml(ui->notes->text()); doc.setHtml(ui->notes->text());
@ -416,4 +420,9 @@ void BoardPostDisplayWidget::setup()
#endif #endif
} }
void BoardPostDisplayWidget::doExpand(bool e)
{
std::cerr << "Expanding" << std::endl;
emit expand(mPost.mMeta.mMsgId,e);
}

View file

@ -42,7 +42,7 @@ public:
DISPLAY_MODE_COMPACT = 0x02 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(); virtual ~BoardPostDisplayWidget();
static const char *DEFAULT_BOARD_IMAGE; static const char *DEFAULT_BOARD_IMAGE;
@ -55,7 +55,7 @@ protected slots:
virtual void setup(); // to be overloaded by the different views virtual void setup(); // to be overloaded by the different views
void doExpand(bool) {} void doExpand(bool) ;
void setComment(const RsGxsComment&) ; void setComment(const RsGxsComment&) ;
void setReadStatus(bool isNew, bool isUnread) ; void setReadStatus(bool isNew, bool isUnread) ;
@ -67,6 +67,7 @@ protected slots:
signals: signals:
void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down); void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down);
void expand(RsGxsMessageId,bool);
protected: protected:
RsPostedPost mPost; RsPostedPost mPost;

View file

@ -303,6 +303,9 @@
<iconset resource="Posted_images.qrc"> <iconset resource="Posted_images.qrc">
<normaloff>:/images/expand.png</normaloff>:/images/expand.png</iconset> <normaloff>:/images/expand.png</normaloff>:/images/expand.png</iconset>
</property> </property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise"> <property name="autoRaise">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -433,6 +436,9 @@
<property name="scaledContents"> <property name="scaledContents">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property> </property>

View file

@ -85,7 +85,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
painter->fillRect( option.rect, option.backgroundBrush); painter->fillRect( option.rect, option.backgroundBrush);
painter->restore(); painter->restore();
BoardPostDisplayWidget w(post,mDisplayMode); BoardPostDisplayWidget w(post,mDisplayMode,isExpanded(post.mMeta.mMsgId));
w.adjustSize(); w.adjustSize();
w.setFixedSize(option.rect.size()); w.setFixedSize(option.rect.size());
@ -120,32 +120,43 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
painter->restore(); 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 QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
// This is the only place where we actually set the size of cells // This is the only place where we actually set the size of cells
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ; RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
BoardPostDisplayWidget w(post,mDisplayMode); BoardPostDisplayWidget w(post,mDisplayMode,isExpanded(post.mMeta.mMsgId));
w.adjustSize(); w.adjustSize();
return w.size(); 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 QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{ {
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ; RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
if(index.column() == RsPostedPostsModel::COLUMN_POSTS) 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(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool)));
QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(expandItem(RsGxsMessageId,bool)));
w->adjustSize(); w->adjustSize();
w->setFixedSize(option.rect.size()); w->setFixedSize(option.rect.size());
@ -184,9 +195,6 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts())); connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(next10Posts()));
connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prev10Posts())); 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->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&)));
connect(ui->cardViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode())); connect(ui->cardViewButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode()));
connect(ui->classicViewButton,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); whileBlocking(ui->cardViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT);
ui->postsTree->setUniformRowHeights(true);
} }
else else
{ {
whileBlocking(ui->classicViewButton)->setChecked(false); whileBlocking(ui->classicViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW);
ui->postsTree->setUniformRowHeights(false);
} }
mPostedPostsModel->deepUpdate(); mPostedPostsModel->deepUpdate();
@ -514,6 +520,11 @@ void PostedListWidgetWithModel::postPostLoad()
whileBlocking(ui->filter_LE)->setText(QString()); whileBlocking(ui->filter_LE)->setText(QString());
} }
void PostedListWidgetWithModel::forceRedraw()
{
if(mPostedPostsModel)
mPostedPostsModel->deepUpdate();
}
void PostedListWidgetWithModel::updateDisplay(bool complete) void PostedListWidgetWithModel::updateDisplay(bool complete)
{ {
#ifdef DEBUG_CHANNEL #ifdef DEBUG_CHANNEL
@ -534,6 +545,7 @@ void PostedListWidgetWithModel::updateDisplay(bool complete)
#endif #endif
complete = true; complete = true;
} }
if(complete) // need to update the group data, reload the messages etc. if(complete) // need to update the group data, reload the messages etc.
{ {
updateGroupData(); updateGroupData();

View file

@ -53,17 +53,22 @@ class PostedPostDelegate: public QAbstractItemDelegate
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) 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; 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 setCellWidth(int pix) { mCellWidthPix = pix; }
void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; } void setDisplayMode(BoardPostDisplayWidget::DisplayMode dm) { mDisplayMode = dm; }
public slots:
void expandItem(RsGxsMessageId msgId,bool expanded);
private: private:
QSize cellSize(const QSize& w) const; // Converts the supplied size to the cell size for the current container. // The class keeps a list of expanded items. Because items are constantly re-created, it is not possible
// The client should then scale its widget to fit the given size. // to let the items themselves hold that information.
bool isExpanded(const RsGxsMessageId& id) const;
int mCellWidthPix; int mCellWidthPix;
PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on. PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on.
BoardPostDisplayWidget::DisplayMode mDisplayMode; BoardPostDisplayWidget::DisplayMode mDisplayMode;
std::set<RsGxsMessageId> mExpandedItems;
}; };
class PostedListWidgetWithModel: public GxsMessageFrameWidget class PostedListWidgetWithModel: public GxsMessageFrameWidget
@ -91,6 +96,7 @@ public:
virtual bool navigate(const RsGxsMessageId&) override; virtual bool navigate(const RsGxsMessageId&) override;
void updateDisplay(bool complete) ; 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 #ifdef TODO
/* FeedHolder */ /* FeedHolder */