fixed right-click menu on board posts

This commit is contained in:
csoler 2023-04-19 20:43:12 +02:00
parent 44bb2c0f05
commit 4a69380848
4 changed files with 57 additions and 113 deletions

View file

@ -219,7 +219,7 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
else
w = new BoardPostDisplayWidget_card(post,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(commentsRequested(RsGxsMessageId,bool)),mPostListWidget,SLOT(openComments(RsGxsMessageId)));
QObject::connect(w,SIGNAL(changeReadStatusRequested(RsGxsMessageId,bool)),mPostListWidget,SLOT(changeReadStatus(RsGxsMessageId,bool)));
@ -230,7 +230,6 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
QObject::connect(w,SIGNAL(expand(RsGxsMessageId,bool)),this,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(commentsRequested(RsGxsMessageId,bool)),mPostListWidget,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(shareButtonClicked()),mPostListWidget,SLOT(markCurrentPostAsRead()));
QObject::connect(w,SIGNAL(copylinkClicked()),mPostListWidget,SLOT(copyMessageLink()));
w->setGeometry(option.rect);
w->adjustSize();
@ -277,7 +276,6 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
connect(ui->nextButton,SIGNAL(clicked()),this,SLOT(nextPosts()));
connect(ui->prevButton,SIGNAL(clicked()),this,SLOT(prevPosts()));
connect(ui->postsTree,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(postContextMenu(QPoint)));
connect(ui->viewModeButton,SIGNAL(clicked()),this,SLOT(switchDisplayMode()));
connect(mPostedPostsModel,SIGNAL(boardPostsLoaded()),this,SLOT(postPostLoad()));
@ -296,7 +294,11 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize)));
/* load settings */
ui->postsTree->setContextMenuPolicy(Qt::CustomContextMenu);
//QObject::connect(this,SIGNAL(copylinkClicked()),this,SLOT(copyMessageLink()));
connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&)));
/* load settings */
processSettings(true);
/* Initialize subscribe button */
@ -325,6 +327,32 @@ PostedListWidgetWithModel::PostedListWidgetWithModel(const RsGxsGroupId& postedI
}, mEventHandlerId, RsEventType::GXS_POSTED );
}
void PostedListWidgetWithModel::postContextMenu(const QPoint& point)
{
QMenu menu(this);
// 1 - check that we are clicking on a post
QModelIndex index = ui->postsTree->indexAt(point);
if(!index.isValid())
return;
// 2 - generate the menu for that post.
menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink()))->setData(index);
menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_AUTHOR), tr("Show author in People tab"), this, SLOT(showAuthorInPeople()))->setData(index);
#ifdef TODO
// This feature is not implemented yet in libretroshare.
if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags))
menu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/edit_16.png"), tr("Edit"), this, SLOT(editPost()));
#endif
menu.exec(QCursor::pos());
}
void PostedListWidgetWithModel::switchDisplayMode()
{
if(mPostedPostsDelegate->getDisplayMode() == BoardPostDisplayWidget_compact::DISPLAY_MODE_CARD)
@ -403,7 +431,7 @@ void PostedListWidgetWithModel::prevPosts()
void PostedListWidgetWithModel::showAuthorInPeople()
{
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
QModelIndex index = qobject_cast<QAction*>(QObject::sender())->data().toModelIndex();
if(!index.isValid())
throw std::runtime_error("No post under mouse!");
@ -428,23 +456,6 @@ void PostedListWidgetWithModel::showAuthorInPeople()
MainWindow::showWindow(MainWindow::People);
idDialog->navigate(RsGxsId(post.mMeta.mAuthorId));
}
void PostedListWidgetWithModel::postContextMenu(const QPoint&)
{
QMenu menu(this);
menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink()));
menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_AUTHOR), tr("Show author in People tab"), this, SLOT(showAuthorInPeople()));
#ifdef TODO
// This feature is not implemented yet in libretroshare.
if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags))
menu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/edit_16.png"), tr("Edit"), this, SLOT(editPost()));
#endif
menu.exec(QCursor::pos());
}
void PostedListWidgetWithModel::copyMessageLink()
{
try
@ -452,7 +463,7 @@ void PostedListWidgetWithModel::copyMessageLink()
if (groupId().isNull())
throw std::runtime_error("No channel currently selected!");
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
QModelIndex index = qobject_cast<QAction*>(QObject::sender())->data().toModelIndex();
if(!index.isValid())
throw std::runtime_error("No post under mouse!");
@ -528,87 +539,6 @@ void PostedListWidgetWithModel::handleEvent_main_thread(std::shared_ptr<const Rs
}
}
#ifdef TO_REMOVE
void PostedListWidgetWithModel::showPostDetails()
{
QModelIndex index = ui->postsTree->selectionModel()->currentIndex();
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
QTextDocument doc;
doc.setHtml(post.mMsg.c_str());
if(post.mMeta.mPublishTs == 0)
{
ui->postDetails_TE->clear();
ui->postLogo_LB->hide();
ui->postName_LB->hide();
ui->postTime_LB->hide();
mChannelPostFilesModel->clear();
return;
}
ui->postLogo_LB->show();
ui->postName_LB->show();
ui->postTime_LB->show();
if(index.row()==0 && index.column()==0)
std::cerr << "here" << std::endl;
std::cerr << "showPostDetails: setting mLastSelectedPosts[groupId()] to current post Id " << post.mMeta.mMsgId << ". Previous value: " << mLastSelectedPosts[groupId()] << std::endl;
mLastSelectedPosts[groupId()] = post.mMeta.mMsgId;
std::list<ChannelPostFileInfo> files;
for(auto& file:post.mFiles)
files.push_back(ChannelPostFileInfo(file,post.mMeta.mPublishTs));
mChannelPostFilesModel->setFiles(files);
auto all_msgs_versions(post.mOlderVersions);
all_msgs_versions.insert(post.mMeta.mMsgId);
ui->commentsDialog->commentLoad(post.mMeta.mGroupId, all_msgs_versions, post.mMeta.mMsgId);
std::cerr << "Showing details about selected index : "<< index.row() << "," << index.column() << std::endl;
ui->postDetails_TE->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), /* RSHTML_FORMATTEXT_EMBED_SMILEYS |*/ RSHTML_FORMATTEXT_EMBED_LINKS));
QPixmap postImage;
if (post.mThumbnail.mData != NULL)
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, postImage,GxsIdDetails::ORIGINAL);
else
postImage = FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE);
int W = QFontMetricsF(font()).height() * 8;
// Using fixed width so that the post will not displace the text when we browse.
ui->postLogo_LB->setPixmap(postImage);
ui->postLogo_LB->setFixedSize(W,postImage.height()/(float)postImage.width()*W);
ui->postName_LB->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str()));
ui->postName_LB->setFixedWidth(W);
ui->postTime_LB->setText(QDateTime::fromMSecsSinceEpoch(post.mMeta.mPublishTs*1000).toString("MM/dd/yyyy, hh:mm"));
ui->postTime_LB->setFixedWidth(W);
//ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_FILE);
//ui->channelPostFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE);
ui->channelPostFiles_TV->setAutoSelect(true);
// Now also set the post as read
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus))
{
RsGxsGrpMsgIdPair postId;
postId.second = post.mMeta.mMsgId;
postId.first = post.mMeta.mGroupId;
RsThread::async([postId]() { rsGxsChannels->markRead(postId, true) ; } );
}
}
#endif
void PostedListWidgetWithModel::updateGroupData()
{
if(groupId().isNull())