From cbfcb2c7fb3c3252da5e25c9e0f4eb8f8a3b335e Mon Sep 17 00:00:00 2001 From: chelovechishko Date: Wed, 1 Jul 2020 16:42:35 +0900 Subject: [PATCH] gxsforums: resurrect the header context menu --- .../gui/gxsforums/GxsForumThreadWidget.cpp | 49 +++++++++++++++++++ .../src/gui/gxsforums/GxsForumThreadWidget.h | 2 + 2 files changed, 51 insertions(+) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 2d0a79825..8ea70849b 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -316,6 +316,9 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ttheader->hideSection (RsGxsForumModel::COLUMN_THREAD_MSGID); ttheader->hideSection (RsGxsForumModel::COLUMN_THREAD_DATA); + ttheader->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ttheader, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(headerContextMenuRequested(QPoint))); + ui->progressBar->hide(); ui->progressText->hide(); @@ -736,6 +739,52 @@ void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point) delete(contextMnu); } +void GxsForumThreadWidget::headerContextMenuRequested(const QPoint &pos) +{ + QMenu* header_context_menu = new QMenu(tr("Show column"), this); + + QAction* title = header_context_menu->addAction(QIcon(), tr("Title")); + title->setCheckable(true); + title->setChecked(!ui->threadTreeWidget->isColumnHidden(RsGxsForumModel::COLUMN_THREAD_TITLE)); + title->setData(RsGxsForumModel::COLUMN_THREAD_TITLE); + connect(title, SIGNAL(toggled(bool)), this, SLOT(changeHeaderColumnVisibility(bool))); + + QAction* read = header_context_menu->addAction(QIcon(), tr("Read")); + read->setCheckable(true); + read->setChecked(!ui->threadTreeWidget->isColumnHidden(RsGxsForumModel::COLUMN_THREAD_READ)); + read->setData(RsGxsForumModel::COLUMN_THREAD_READ); + connect(read, SIGNAL(toggled(bool)), this, SLOT(changeHeaderColumnVisibility(bool))); + + QAction* date = header_context_menu->addAction(QIcon(), tr("Date")); + date->setCheckable(true); + date->setChecked(!ui->threadTreeWidget->isColumnHidden(RsGxsForumModel::COLUMN_THREAD_DATE)); + date->setData(RsGxsForumModel::COLUMN_THREAD_DATE); + connect(date, SIGNAL(toggled(bool)), this, SLOT(changeHeaderColumnVisibility(bool))); + + QAction* distribution = header_context_menu->addAction(QIcon(), tr("Distribution")); + distribution->setCheckable(true); + distribution->setChecked(!ui->threadTreeWidget->isColumnHidden(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION)); + distribution->setData(RsGxsForumModel::COLUMN_THREAD_DISTRIBUTION); + connect(distribution, SIGNAL(toggled(bool)), this, SLOT(changeHeaderColumnVisibility(bool))); + + // QAction* author = header_context_menu->addAction(QIcon(), tr("Author")); + // author->setCheckable(true); + // author->setChecked(!ui->threadTreeWidget->isColumnHidden(RsGxsForumModel::COLUMN_THREAD_AUTHOR)); + // author->setData(RsGxsForumModel::COLUMN_THREAD_AUTHOR); + // connect(author, SIGNAL(toggled(bool)), this, SLOT(changeHeaderColumnVisibility(bool))); + + header_context_menu->exec(mapToGlobal(pos)); + delete(header_context_menu); +} + +void GxsForumThreadWidget::changeHeaderColumnVisibility(bool visibility) { + QAction* the_action = qobject_cast(sender()); + if ( !the_action ) { + return; + } + ui->threadTreeWidget->setColumnHidden(the_action->data().toInt(), !visibility); +} + #ifdef TODO bool GxsForumThreadWidget::eventFilter(QObject *obj, QEvent *event) { diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 0a87a683a..579cc15fd 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -97,6 +97,7 @@ private slots: /** Create the context popup menu and it's submenus */ void threadListCustomPopupMenu(QPoint point); void contextMenuTextBrowser(QPoint point); + void headerContextMenuRequested(const QPoint& pos); void changedSelection(const QModelIndex &, const QModelIndex &); void changedThread(QModelIndex index); @@ -148,6 +149,7 @@ private slots: #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) void expandSubtree(); #endif + void changeHeaderColumnVisibility(bool visibility); private: void insertMessageData(const RsGxsForumMsg &msg); bool getCurrentPost(ForumModelPostEntry& fmpe) const ;