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 ==
|
//== Base class BoardPostDisplayWidget ==
|
||||||
//===================================================================================================================================
|
//===================================================================================================================================
|
||||||
|
|
||||||
BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayMode mode,bool expanded,QWidget *parent)
|
BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post, DisplayMode mode, uint8_t display_flags, QWidget *parent)
|
||||||
: QWidget(parent),mPost(post),dmode(mode),mExpanded(expanded),ui(new Ui::BoardPostDisplayWidget())
|
: QWidget(parent),mPost(post),dmode(mode),mDisplayFlags(display_flags),ui(new Ui::BoardPostDisplayWidget())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setup();
|
setup();
|
||||||
@ -161,21 +161,6 @@ void BoardPostDisplayWidget::setup()
|
|||||||
ui->pictureLabel->hide();
|
ui->pictureLabel->hide();
|
||||||
ui->notes->hide();
|
ui->notes->hide();
|
||||||
ui->siteLabel->hide();
|
ui->siteLabel->hide();
|
||||||
|
|
||||||
if(mExpanded)
|
|
||||||
{
|
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
@ -184,6 +169,29 @@ void BoardPostDisplayWidget::setup()
|
|||||||
ui->expandButton->hide();
|
ui->expandButton->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mDisplayFlags & SHOW_NOTES)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(mDisplayFlags & SHOW_COMMENTS))
|
||||||
|
{
|
||||||
|
ui->commentsWidget->hide();
|
||||||
|
ui->commentButton->setChecked(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ui->commentButton->setChecked(true);
|
||||||
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
|
||||||
/* clear ui */
|
/* clear ui */
|
||||||
@ -193,7 +201,7 @@ void BoardPostDisplayWidget::setup()
|
|||||||
ui->siteLabel->clear();
|
ui->siteLabel->clear();
|
||||||
|
|
||||||
connect(ui->expandButton, SIGNAL(toggled(bool)), this, SLOT(doExpand(bool)));
|
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->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)));
|
connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool)));
|
||||||
@ -350,38 +358,21 @@ void BoardPostDisplayWidget::setup()
|
|||||||
if(doc.toPlainText().trimmed().isEmpty())
|
if(doc.toPlainText().trimmed().isEmpty())
|
||||||
ui->notes->hide();
|
ui->notes->hide();
|
||||||
|
|
||||||
#ifdef TO_REMOVE
|
// feed.
|
||||||
// differences between Feed or Top of Comment.
|
//frame_comment->show();
|
||||||
if (mFeedHolder)
|
ui->commentButton->show();
|
||||||
|
|
||||||
|
if (mPost.mComments)
|
||||||
{
|
{
|
||||||
// feed.
|
QString commentText = QString::number(mPost.mComments);
|
||||||
//frame_comment->show();
|
commentText += " ";
|
||||||
ui->commentButton->show();
|
commentText += tr("Comments");
|
||||||
|
ui->commentButton->setText(commentText);
|
||||||
if (mPost.mComments)
|
|
||||||
{
|
|
||||||
QString commentText = QString::number(mPost.mComments);
|
|
||||||
commentText += " ";
|
|
||||||
commentText += tr("Comments");
|
|
||||||
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
|
else
|
||||||
#endif
|
ui->commentButton->setText(tr("Comment"));
|
||||||
{
|
|
||||||
// no feed.
|
|
||||||
//frame_comment->hide();
|
|
||||||
ui->commentButton->hide();
|
|
||||||
|
|
||||||
ui->readButton->hide();
|
setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus));
|
||||||
ui->newLabel->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable voting buttons - if they have already voted.
|
// disable voting buttons - if they have already voted.
|
||||||
if (mPost.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
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);
|
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
|
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();
|
virtual ~BoardPostDisplayWidget();
|
||||||
|
|
||||||
static const char *DEFAULT_BOARD_IMAGE;
|
static const char *DEFAULT_BOARD_IMAGE;
|
||||||
@ -61,6 +67,7 @@ protected slots:
|
|||||||
|
|
||||||
void toggle() {}
|
void toggle() {}
|
||||||
void setCommentsSize(int comNb) ;
|
void setCommentsSize(int comNb) ;
|
||||||
|
void loadComments(bool e);
|
||||||
void makeUpVote() ;
|
void makeUpVote() ;
|
||||||
void makeDownVote() ;
|
void makeDownVote() ;
|
||||||
void toggleNotes() ;
|
void toggleNotes() ;
|
||||||
@ -68,12 +75,13 @@ 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);
|
void expand(RsGxsMessageId,bool);
|
||||||
|
void commentsRequested(RsGxsMessageId,bool);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RsPostedPost mPost;
|
RsPostedPost mPost;
|
||||||
|
|
||||||
DisplayMode dmode;
|
DisplayMode dmode;
|
||||||
bool mExpanded;
|
uint8_t mDisplayFlags;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>758</width>
|
<width>758</width>
|
||||||
<height>190</height>
|
<height>205</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -52,7 +52,7 @@
|
|||||||
<property name="frameShadow">
|
<property name="frameShadow">
|
||||||
<enum>QFrame::Raised</enum>
|
<enum>QFrame::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
@ -269,6 +269,9 @@
|
|||||||
<iconset resource="Posted_images.qrc">
|
<iconset resource="Posted_images.qrc">
|
||||||
<normaloff>:/images/comments.png</normaloff>:/images/comments.png</iconset>
|
<normaloff>:/images/comments.png</normaloff>:/images/comments.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="toolButtonStyle">
|
<property name="toolButtonStyle">
|
||||||
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
<enum>Qt::ToolButtonTextBesideIcon</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -440,6 +443,9 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="GxsCommentDialog" name="commentsWidget" native="true"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -463,6 +469,12 @@
|
|||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>util/ClickableLabel.h</header>
|
<header>util/ClickableLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>GxsCommentDialog</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>gui/gxs/GxsCommentDialog.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../images.qrc"/>
|
<include location="../images.qrc"/>
|
||||||
|
@ -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,isExpanded(post.mMeta.mMsgId));
|
BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(post.mMeta.mMsgId));
|
||||||
|
|
||||||
w.adjustSize();
|
w.adjustSize();
|
||||||
w.setFixedSize(option.rect.size());
|
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
|
// 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,isExpanded(post.mMeta.mMsgId));
|
BoardPostDisplayWidget w(post,mDisplayMode,displayFlags(post.mMeta.mMsgId));
|
||||||
|
|
||||||
w.adjustSize();
|
w.adjustSize();
|
||||||
|
|
||||||
return w.size();
|
return w.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded)
|
void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded)
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": received expandItem signal. b=" << expanded << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << ": received expandItem signal. b=" << expanded << std::endl;
|
||||||
@ -142,9 +141,27 @@ void PostedPostDelegate::expandItem(RsGxsMessageId msgId,bool expanded)
|
|||||||
|
|
||||||
mPostListWidget->forceRedraw();
|
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
|
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)
|
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(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(voteMsg(RsGxsGrpMsgIdPair,bool)));
|
||||||
QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(expandItem(RsGxsMessageId,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->adjustSize();
|
||||||
w->setFixedSize(option.rect.size());
|
w->setFixedSize(option.rect.size());
|
||||||
|
@ -58,17 +58,19 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void expandItem(RsGxsMessageId msgId,bool expanded);
|
void expandItem(RsGxsMessageId msgId,bool expanded);
|
||||||
|
void commentItem(RsGxsMessageId msgId,bool comment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The class keeps a list of expanded items. Because items are constantly re-created, it is not possible
|
// 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.
|
// to let the items themselves hold that information.
|
||||||
|
|
||||||
bool isExpanded(const RsGxsMessageId& id) const;
|
uint8_t displayFlags(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;
|
std::set<RsGxsMessageId> mExpandedItems;
|
||||||
|
std::set<RsGxsMessageId> mShowCommentItems;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostedListWidgetWithModel: public GxsMessageFrameWidget
|
class PostedListWidgetWithModel: public GxsMessageFrameWidget
|
||||||
|
Loading…
Reference in New Issue
Block a user