From 219f27d75cbfb6c48a8da45e56f1192605dab0aa Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Mon, 18 Mar 2024 12:17:36 +0530 Subject: [PATCH] exp approach 2 --- src/dialogs/VersionInfoDialog.cpp | 65 ++++++++++++++++++++++--------- src/dialogs/VersionInfoDialog.h | 8 +++- src/dialogs/VersionInfoDialog.ui | 6 +++ 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 730398d41..c4ff8b6fa 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -13,12 +13,55 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core()) -{ +{ ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); // Get version information fillVersionInfo(); + + // Setup context menu and actions + copyActionLeftTreewidget = new QAction(tr("Copy"), this); + copyActionLeftTreewidget->setIcon(QIcon(":/img/icons/copy.svg")); + copyActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::Copy); + copyActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + copyActionRightTreewidget = new QAction(tr("Copy"), this); + copyActionRightTreewidget->setIcon(QIcon(":/img/icons/copy.svg")); + copyActionRightTreewidget->setShortcut(QKeySequence::StandardKey::Copy); + copyActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + selAllActionLeftTreewidget = new QAction(tr("Select All"), this); + selAllActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll); + selAllActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + selAllActionRightTreewidget = new QAction(tr("Select All"), this); + selAllActionRightTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll); + selAllActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + connect(copyActionLeftTreewidget, &QAction::triggered, this, [this](){ + CopyTreeWidgetSelection(ui->leftTreeWidget); + }); + + connect(copyActionRightTreewidget, &QAction::triggered, this, [this](){ + CopyTreeWidgetSelection(ui->rightTreeWidget); + }); + + connect(selAllActionLeftTreewidget, &QAction::triggered, this, [this](){ + ui->leftTreeWidget->selectAll(); + }); + + connect(selAllActionRightTreewidget, &QAction::triggered, this, [this](){ + ui->rightTreeWidget->selectAll(); + }); + + ui->leftTreeWidget->addAction(copyActionLeftTreewidget); + ui->leftTreeWidget->addAction(selAllActionLeftTreewidget); + + ui->rightTreeWidget->addAction(copyActionRightTreewidget); + ui->rightTreeWidget->addAction(selAllActionRightTreewidget); + + contextMenu = new QMenu(this); } VersionInfoDialog::~VersionInfoDialog() {} @@ -38,24 +81,8 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) } void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event){ - QAction *copyAction = new QAction(tr("Copy"), this); - copyAction->setShortcutContext(Qt::WidgetWithChildrenShortcut); - copyAction->setShortcut(QKeySequence::Copy); - - connect(copyAction, &QAction::triggered, this, [this](){ - if(ui->rightTreeWidget->hasFocus()){ - CopyTreeWidgetSelection(ui->rightTreeWidget); - } - else if(ui->leftTreeWidget->hasFocus()){ - CopyTreeWidgetSelection(ui->leftTreeWidget); - } - }); - - QMenu menu(this); - menu.addAction(copyAction); - menu.exec(event->globalPos()); - - addAction(copyAction); + contextMenu->exec(event->globalPos()); + event->accept(); } void VersionInfoDialog::fillVersionInfo() diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index ea6d7adcb..29d1be864 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -15,13 +15,19 @@ class VersionInfoDialog : public QDialog Q_OBJECT public: - explicit VersionInfoDialog(QWidget *parent = nullptr); + explicit VersionInfoDialog(QWidget *parent = nullptr); ~VersionInfoDialog(); private slots: void CopyTreeWidgetSelection(QTreeWidget *t); protected: + QMenu *contextMenu = nullptr; + QAction *copyActionLeftTreewidget = nullptr; + QAction *copyActionRightTreewidget = nullptr; + QAction *selAllActionLeftTreewidget = nullptr; + QAction *selAllActionRightTreewidget = nullptr; + void contextMenuEvent(QContextMenuEvent *event) override; private: diff --git a/src/dialogs/VersionInfoDialog.ui b/src/dialogs/VersionInfoDialog.ui index 85dbac55e..9ab0da67d 100644 --- a/src/dialogs/VersionInfoDialog.ui +++ b/src/dialogs/VersionInfoDialog.ui @@ -71,6 +71,9 @@ + + Qt::ActionsContextMenu + QAbstractItemView::ExtendedSelection @@ -106,6 +109,9 @@ + + Qt::ActionsContextMenu + QAbstractItemView::ExtendedSelection