mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 07:29:33 -05:00
added hide/unhide comments inside QTreeView
This commit is contained in:
parent
da200f1e1d
commit
2bdb389200
@ -47,8 +47,8 @@ const char *BoardPostDisplayWidget::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2
|
||||
//== Base class BoardPostDisplayWidget ==
|
||||
//===================================================================================================================================
|
||||
|
||||
BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,bool expanded,QWidget *parent)
|
||||
: QWidget(parent),mPost(post),dmode(mode),mExpanded(expanded),ui(new Ui::BoardPostDisplayWidget())
|
||||
BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post, DisplayMode mode, uint8_t display_flags, QWidget *parent)
|
||||
: QWidget(parent),mPost(post),dmode(mode),mDisplayFlags(display_flags),ui(new Ui::BoardPostDisplayWidget())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setup();
|
||||
@ -161,8 +161,15 @@ void BoardPostDisplayWidget::setup()
|
||||
ui->pictureLabel->hide();
|
||||
ui->notes->hide();
|
||||
ui->siteLabel->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->frame_picture->hide();
|
||||
ui->pictureLabel_compact->hide();
|
||||
ui->expandButton->hide();
|
||||
}
|
||||
|
||||
if(mExpanded)
|
||||
if(mDisplayFlags & SHOW_NOTES)
|
||||
{
|
||||
ui->frame_picture->show();
|
||||
ui->expandButton->setIcon(FilesDefs::getIconFromQtResourcePath(QString(":/images/decrease.png")));
|
||||
@ -176,13 +183,14 @@ void BoardPostDisplayWidget::setup()
|
||||
ui->expandButton->setToolTip(tr("Expand"));
|
||||
ui->expandButton->setChecked(false);
|
||||
}
|
||||
|
||||
if(!(mDisplayFlags & SHOW_COMMENTS))
|
||||
{
|
||||
ui->commentsWidget->hide();
|
||||
ui->commentButton->setChecked(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->frame_picture->hide();
|
||||
ui->pictureLabel_compact->hide();
|
||||
ui->expandButton->hide();
|
||||
}
|
||||
ui->commentButton->setChecked(true);
|
||||
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
@ -193,7 +201,7 @@ void BoardPostDisplayWidget::setup()
|
||||
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(toggled(bool)), this, SLOT(loadComments(bool)));
|
||||
connect(ui->voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
||||
connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT(makeDownVote()));
|
||||
connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool)));
|
||||
@ -350,10 +358,6 @@ void BoardPostDisplayWidget::setup()
|
||||
if(doc.toPlainText().trimmed().isEmpty())
|
||||
ui->notes->hide();
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
// differences between Feed or Top of Comment.
|
||||
if (mFeedHolder)
|
||||
{
|
||||
// feed.
|
||||
//frame_comment->show();
|
||||
ui->commentButton->show();
|
||||
@ -366,22 +370,9 @@ void BoardPostDisplayWidget::setup()
|
||||
ui->commentButton->setText(commentText);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->commentButton->setText(tr("Comment"));
|
||||
}
|
||||
|
||||
setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// no feed.
|
||||
//frame_comment->hide();
|
||||
ui->commentButton->hide();
|
||||
|
||||
ui->readButton->hide();
|
||||
ui->newLabel->hide();
|
||||
}
|
||||
|
||||
// disable voting buttons - if they have already voted.
|
||||
if (mPost.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
||||
@ -426,3 +417,7 @@ void BoardPostDisplayWidget::doExpand(bool e)
|
||||
emit expand(mPost.mMeta.mMsgId,e);
|
||||
}
|
||||
|
||||
void BoardPostDisplayWidget::loadComments(bool e)
|
||||
{
|
||||
emit commentsRequested(mPost.mMeta.mMsgId,e);
|
||||
}
|
||||
|
@ -42,7 +42,13 @@ public:
|
||||
DISPLAY_MODE_COMPACT = 0x02
|
||||
};
|
||||
|
||||
BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode display_mode,bool expanded,QWidget *parent=nullptr);
|
||||
enum DisplayFlags: uint8_t {
|
||||
SHOW_NONE = 0x00,
|
||||
SHOW_COMMENTS = 0x01,
|
||||
SHOW_NOTES = 0x02,
|
||||
};
|
||||
|
||||
BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode display_mode,uint8_t display_flags,QWidget *parent=nullptr);
|
||||
virtual ~BoardPostDisplayWidget();
|
||||
|
||||
static const char *DEFAULT_BOARD_IMAGE;
|
||||
@ -61,6 +67,7 @@ protected slots:
|
||||
|
||||
void toggle() {}
|
||||
void setCommentsSize(int comNb) ;
|
||||
void loadComments(bool e);
|
||||
void makeUpVote() ;
|
||||
void makeDownVote() ;
|
||||
void toggleNotes() ;
|
||||
@ -68,12 +75,13 @@ protected slots:
|
||||
signals:
|
||||
void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down);
|
||||
void expand(RsGxsMessageId,bool);
|
||||
void commentsRequested(RsGxsMessageId,bool);
|
||||
|
||||
protected:
|
||||
RsPostedPost mPost;
|
||||
|
||||
DisplayMode dmode;
|
||||
bool mExpanded;
|
||||
uint8_t mDisplayFlags;
|
||||
|
||||
private:
|
||||
/** Qt Designer generated object */
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>758</width>
|
||||
<height>190</height>
|
||||
<height>205</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -52,7 +52,7 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
@ -269,6 +269,9 @@
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/comments.png</normaloff>:/images/comments.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||
</property>
|
||||
@ -440,6 +443,9 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsCommentDialog" name="commentsWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@ -463,6 +469,12 @@
|
||||
<extends>QLabel</extends>
|
||||
<header>util/ClickableLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>GxsCommentDialog</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/gxs/GxsCommentDialog.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../images.qrc"/>
|
||||
|
@ -85,7 +85,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
||||
painter->fillRect( option.rect, option.backgroundBrush);
|
||||
painter->restore();
|
||||
|
||||
BoardPostDisplayWidget w(post,mDisplayMode,isExpanded(post.mMeta.mMsgId));
|
||||
BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(post.mMeta.mMsgId));
|
||||
|
||||
w.adjustSize();
|
||||
w.setFixedSize(option.rect.size());
|
||||
@ -125,13 +125,12 @@ QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo
|
||||
// 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,isExpanded(post.mMeta.mMsgId));
|
||||
BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(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;
|
||||
@ -142,9 +141,27 @@ void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded)
|
||||
|
||||
mPostListWidget->forceRedraw();
|
||||
}
|
||||
bool PostedPostDelegate::isExpanded(const RsGxsMessageId &id) const
|
||||
void PostedPostDelegate::commentItem(RsGxsMessageId msgId,bool comment)
|
||||
{
|
||||
return mExpandedItems.find(id) != mExpandedItems.end();
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": received commentItem signal. b=" << comment << std::endl;
|
||||
if(comment)
|
||||
mShowCommentItems.insert(msgId);
|
||||
else
|
||||
mShowCommentItems.erase(msgId);
|
||||
|
||||
mPostListWidget->forceRedraw();
|
||||
}
|
||||
uint8_t PostedPostDelegate::displayFlags(const RsGxsMessageId &id) const
|
||||
{
|
||||
uint8_t flags=0;
|
||||
|
||||
if(mExpandedItems.find(id) != mExpandedItems.end())
|
||||
flags |= BoardPostDisplayWidget::SHOW_NOTES;
|
||||
|
||||
if(mShowCommentItems.find(id) != mShowCommentItems.end())
|
||||
flags |= BoardPostDisplayWidget::SHOW_COMMENTS;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
@ -153,10 +170,11 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
|
||||
|
||||
if(index.column() == RsPostedPostsModel::COLUMN_POSTS)
|
||||
{
|
||||
QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,isExpanded(post.mMeta.mMsgId),parent);
|
||||
QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,displayFlags(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)));
|
||||
QObject::connect(w,SIGNAL(commentsRequested(RsGxsMessageId,bool)),this,SLOT(commentItem(RsGxsMessageId,bool)));
|
||||
|
||||
w->adjustSize();
|
||||
w->setFixedSize(option.rect.size());
|
||||
|
@ -58,17 +58,19 @@ public:
|
||||
|
||||
public slots:
|
||||
void expandItem(RsGxsMessageId msgId,bool expanded);
|
||||
void commentItem(RsGxsMessageId msgId,bool comment);
|
||||
|
||||
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;
|
||||
uint8_t displayFlags(const RsGxsMessageId& id) const;
|
||||
|
||||
int mCellWidthPix;
|
||||
PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on.
|
||||
BoardPostDisplayWidget::DisplayMode mDisplayMode;
|
||||
std::set<RsGxsMessageId> mExpandedItems;
|
||||
std::set<RsGxsMessageId> mShowCommentItems;
|
||||
};
|
||||
|
||||
class PostedListWidgetWithModel: public GxsMessageFrameWidget
|
||||
|
Loading…
Reference in New Issue
Block a user