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 ==
//===================================================================================================================================
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);
}

View File

@ -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;

View File

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

View File

@ -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<RsPostedPost>() ;
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<RsPostedPost>() ;
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();

View File

@ -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<RsGxsMessageId> 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 */