From f63aa81c23c442a23c7b65d3284b88ae78156051 Mon Sep 17 00:00:00 2001 From: cristian64 Date: Mon, 27 May 2024 21:06:27 +0100 Subject: [PATCH] Add context menu to results list in scanner pane. The context menu currently includes two actions: - **Add Watch** (same as double-clicking), added for discoverability. - **Copy Address**, as users may occasionally want to copy the address without first having to create the watch entry. --- Source/GUI/MemScanner/MemScanWidget.cpp | 27 +++++++++++++++++++++++++ Source/GUI/MemScanner/MemScanWidget.h | 1 + 2 files changed, 28 insertions(+) diff --git a/Source/GUI/MemScanner/MemScanWidget.cpp b/Source/GUI/MemScanner/MemScanWidget.cpp index 7986d01..505b616 100644 --- a/Source/GUI/MemScanner/MemScanWidget.cpp +++ b/Source/GUI/MemScanner/MemScanWidget.cpp @@ -1,8 +1,11 @@ #include "MemScanWidget.h" +#include +#include #include #include #include +#include #include #include #include @@ -52,6 +55,9 @@ void MemScanWidget::initialiseWidgets() m_tblResulstList->setMinimumWidth(385); connect(m_tblResulstList, &QAbstractItemView::doubleClicked, this, &MemScanWidget::onResultListDoubleClicked); + m_tblResulstList->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_tblResulstList, &QWidget::customContextMenuRequested, this, + &MemScanWidget::onResultsListContextMenuRequested); m_btnAddAll = new QPushButton(tr("Add all")); connect(m_btnAddAll, &QPushButton::clicked, this, &MemScanWidget::onAddAll); @@ -597,3 +603,24 @@ void MemScanWidget::onResultListDoubleClicked(const QModelIndex& index) m_memScanner->getIsUnsigned(), m_memScanner->getBase()); } } + +void MemScanWidget::onResultsListContextMenuRequested(const QPoint& pos) +{ + const QModelIndex index{m_tblResulstList->indexAt(pos)}; + if (!index.isValid()) + return; + + QMenu menu(this); + + QAction* const addAction{menu.addAction(tr("&Add Watch"))}; + connect(addAction, &QAction::triggered, this, + [this, index] { onResultListDoubleClicked(index); }); + + QAction* const copyAction{menu.addAction(tr("&Copy Address"))}; + connect(copyAction, &QAction::triggered, [index] { + const QModelIndex addressIndex{index.siblingAtColumn(ResultsListModel::RESULT_COL_ADDRESS)}; + QApplication::clipboard()->setText(addressIndex.data(Qt::DisplayRole).toString()); + }); + + menu.exec(m_tblResulstList->viewport()->mapToGlobal(pos)); +} diff --git a/Source/GUI/MemScanner/MemScanWidget.h b/Source/GUI/MemScanner/MemScanWidget.h index 1b5fd50..f735c15 100644 --- a/Source/GUI/MemScanner/MemScanWidget.h +++ b/Source/GUI/MemScanner/MemScanWidget.h @@ -37,6 +37,7 @@ class MemScanWidget : public QWidget void onScanMemTypeChanged(); void onCurrentValuesUpdateTimer(); void onResultListDoubleClicked(const QModelIndex& index); + void onResultsListContextMenuRequested(const QPoint& pos); void handleScannerErrors(Common::MemOperationReturnCode errorCode); void onFirstScan(); void onNextScan();