From a4d160dd3d0b430a09fac5c1efdb2e29cdd9af69 Mon Sep 17 00:00:00 2001 From: mandlebro Date: Wed, 25 Jul 2018 23:15:21 +0100 Subject: [PATCH] Added context menu to register refs --- src/widgets/RegisterRefsWidget.cpp | 32 ++++++++++++++++++++++++++++++ src/widgets/RegisterRefsWidget.h | 5 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/widgets/RegisterRefsWidget.cpp b/src/widgets/RegisterRefsWidget.cpp index 11440e31..e10ab703 100644 --- a/src/widgets/RegisterRefsWidget.cpp +++ b/src/widgets/RegisterRefsWidget.cpp @@ -3,6 +3,7 @@ #include "MainWindow.h" #include "utils/Helpers.h" #include +#include RegisterRefModel::RegisterRefModel(QList *registerRefs, QObject *parent) : QAbstractListModel(parent), @@ -121,6 +122,9 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) : ui->registerRefTreeView->setModel(registerRefProxyModel); ui->registerRefTreeView->sortByColumn(RegisterRefModel::RegColumn, Qt::AscendingOrder); + actionCopyValue = new QAction(tr("Copy register value")); + actionCopyRef = new QAction(tr("Copy register reference")); + // Ctrl-F to show/hide the filter entry QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this); connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter); @@ -132,6 +136,15 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) : setScrollMode(); connect(Core(), &CutterCore::refreshAll, this, &RegisterRefsWidget::refreshRegisterRef); connect(Core(), &CutterCore::registersChanged, this, &RegisterRefsWidget::refreshRegisterRef); + connect(actionCopyValue, &QAction::triggered, [=] () { + copyClip(RegisterRefModel::ValueColumn); + }); + connect(actionCopyRef, &QAction::triggered, [=] () { + copyClip(RegisterRefModel::RefColumn); + }); + ui->registerRefTreeView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->registerRefTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(showRegRefContextMenu(const QPoint &))); } RegisterRefsWidget::~RegisterRefsWidget() {} @@ -158,3 +171,22 @@ void RegisterRefsWidget::on_registerRefTreeView_doubleClicked(const QModelIndex RegisterRefModel::RegisterRefDescriptionRole).value(); Core()->seek(item.value); } + +void RegisterRefsWidget::showRegRefContextMenu(const QPoint &pt) +{ + QMenu *menu = new QMenu(ui->registerRefTreeView); + menu->clear(); + menu->addAction(actionCopyValue); + menu->addAction(actionCopyRef); + + menu->exec(ui->registerRefTreeView->viewport()->mapToGlobal(pt)); + delete menu; +} + +void RegisterRefsWidget::copyClip(int column) +{ + int row = ui->registerRefTreeView->selectionModel()->currentIndex().row(); + QString value = ui->registerRefTreeView->selectionModel()->currentIndex().sibling(row, column).data().toString(); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(value); +} \ No newline at end of file diff --git a/src/widgets/RegisterRefsWidget.h b/src/widgets/RegisterRefsWidget.h index 09fd3d7a..f7cef0c5 100644 --- a/src/widgets/RegisterRefsWidget.h +++ b/src/widgets/RegisterRefsWidget.h @@ -69,6 +69,8 @@ public: private slots: void on_registerRefTreeView_doubleClicked(const QModelIndex &index); void refreshRegisterRef(); + void copyClip(int column); + void showRegRefContextMenu(const QPoint &pt); private: std::unique_ptr ui; @@ -76,6 +78,7 @@ private: RegisterRefModel *registerRefModel; RegisterRefProxyModel *registerRefProxyModel; QList registerRefs; - + QAction *actionCopyValue; + QAction *actionCopyRef; void setScrollMode(); };