make interactions on BoardPostWidget to mark the post as read

This commit is contained in:
csoler 2020-10-01 20:25:10 +02:00
parent 4fd7f455a1
commit c30c7a4dfe
5 changed files with 35 additions and 12 deletions

View File

@ -191,18 +191,14 @@ void BoardPostDisplayWidgetBase::setup()
readButton()->setChecked(false); readButton()->setChecked(false);
// voteUpButton()->setIconSize(QSize(S*1.5,S*1.5));
// voteDownButton()->setIconSize(QSize(S*1.5,S*1.5));
// commentButton()->setIconSize(QSize(S*1.5,S*1.5));
// readButton()->setIconSize(QSize(S*1.5,S*1.5));
// shareButton()->setIconSize(QSize(S*1.5,S*1.5));
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
menu->addAction(CopyLinkAction); menu->addAction(CopyLinkAction);
menu->addSeparator(); menu->addSeparator();
menu->addAction(showInPeopleAct); menu->addAction(showInPeopleAct);
shareButton()->setMenu(menu); shareButton()->setMenu(menu);
connect(shareButton(),SIGNAL(pressed()),this,SLOT(handleShareButtonClicked()));
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId); RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE); bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
@ -307,6 +303,10 @@ void BoardPostDisplayWidgetBase::setup()
emit sizeChanged(this); emit sizeChanged(this);
#endif #endif
} }
void BoardPostDisplayWidgetBase::handleShareButtonClicked()
{
emit shareButtonClicked();
}
//=================================================================================================================================== //===================================================================================================================================
//== class BoardPostDisplayWidget == //== class BoardPostDisplayWidget ==
//=================================================================================================================================== //===================================================================================================================================
@ -423,7 +423,7 @@ void BoardPostDisplayWidget_compact::viewPicture()
PView->show(); PView->show();
/* window will destroy itself! */ emit thumbnailOpenned();
} }
QToolButton *BoardPostDisplayWidget_compact::voteUpButton() { return ui->voteUpButton; } QToolButton *BoardPostDisplayWidget_compact::voteUpButton() { return ui->voteUpButton; }

View File

@ -87,12 +87,15 @@ protected slots:
void makeUpVote() ; void makeUpVote() ;
void makeDownVote() ; void makeDownVote() ;
void setCommentsSize(int comNb) ; void setCommentsSize(int comNb) ;
void handleShareButtonClicked() ;
signals: signals:
void changeReadStatusRequested(const RsGxsMessageId&,bool); void changeReadStatusRequested(const RsGxsMessageId&,bool);
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(const RsGxsMessageId&,bool); void commentsRequested(const RsGxsMessageId&,bool);
void thumbnailOpenned();
void shareButtonClicked();
protected: protected:
RsPostedPost mPost; RsPostedPost mPost;

View File

@ -199,6 +199,13 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(openComments(const RsGxsMessageId&))); QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(openComments(const RsGxsMessageId&)));
QObject::connect(w,SIGNAL(changeReadStatusRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(changeReadStatus(const RsGxsMessageId&,bool))); QObject::connect(w,SIGNAL(changeReadStatusRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(changeReadStatus(const RsGxsMessageId&,bool)));
// All other interactions with the widget should cause the msg to be set as read.
QObject::connect(w,SIGNAL(thumbnailOpenned()),mPostListWidget,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(vote(RsGxsGrpMsgIdPair,bool)),mPostListWidget,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(commentsRequested(const RsGxsMessageId&,bool)),mPostListWidget,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(shareButtonClicked()),mPostListWidget,SLOT(markCurrentPostAsRead()));
w->setFixedSize(option.rect.size()); w->setFixedSize(option.rect.size());
w->adjustSize(); w->adjustSize();
w->updateGeometry(); w->updateGeometry();
@ -692,6 +699,16 @@ void PostedListWidgetWithModel::openComments(const RsGxsMessageId& msgId)
ui->tabWidget->addTab(commentDialog,title); ui->tabWidget->addTab(commentDialog,title);
} }
void PostedListWidgetWithModel::markCurrentPostAsRead()
{
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
if(!index.isValid())
throw std::runtime_error("No post under mouse!");
mPostedPostsModel->setMsgReadStatus(index,true);
}
void PostedListWidgetWithModel::changeReadStatus(const RsGxsMessageId& msgId,bool b) void PostedListWidgetWithModel::changeReadStatus(const RsGxsMessageId& msgId,bool b)
{ {
QModelIndex index=mPostedPostsModel->getIndexOfMessage(msgId); QModelIndex index=mPostedPostsModel->getIndexOfMessage(msgId);

View File

@ -149,6 +149,7 @@ private slots:
public slots: public slots:
void handlePostsTreeSizeChange(QSize size); void handlePostsTreeSizeChange(QSize size);
void voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down); void voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down);
void markCurrentPostAsRead();
private: private:
void processSettings(bool load); void processSettings(bool load);

View File

@ -748,13 +748,15 @@ void RsPostedPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
RsGxsGroupId grpId = mPosts[entry].mMeta.mGroupId; RsGxsGroupId grpId = mPosts[entry].mMeta.mGroupId;
RsGxsMessageId msgId = mPosts[entry].mMeta.mMsgId; RsGxsMessageId msgId = mPosts[entry].mMeta.mMsgId;
bool current_read_status = !(IS_MSG_UNREAD(mPosts[entry].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[entry].mMeta.mMsgStatus));
if(current_read_status != read_status)
RsThread::async([msgId,grpId,read_status]() RsThread::async([msgId,grpId,read_status]()
{ {
// Call blocking API // Call blocking API
rsPosted->setPostReadStatus(RsGxsGrpMsgIdPair(grpId,msgId),read_status); rsPosted->setPostReadStatus(RsGxsGrpMsgIdPair(grpId,msgId),read_status);
} ); } );
} }
QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const