From a8eac7efeb7cfbb25eb38a62af14e1dd05f182ea Mon Sep 17 00:00:00 2001 From: tobtoht Date: Wed, 3 Jan 2024 17:22:26 +0100 Subject: [PATCH] TxConfAdv: allow copy context menus --- src/dialog/TxConfAdvDialog.cpp | 42 +++++++++++++++++++++++++++++++++- src/dialog/TxConfAdvDialog.h | 3 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/dialog/TxConfAdvDialog.cpp b/src/dialog/TxConfAdvDialog.cpp index f13f915..4b8a13a 100644 --- a/src/dialog/TxConfAdvDialog.cpp +++ b/src/dialog/TxConfAdvDialog.cpp @@ -48,7 +48,16 @@ TxConfAdvDialog::TxConfAdvDialog(Wallet *wallet, const QString &description, QWi ui->txid->hide(); ui->label_txid->hide(); } - + + ui->treeInputs->setContextMenuPolicy(Qt::CustomContextMenu); + ui->treeOutputs->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->treeInputs, &QTreeView::customContextMenuRequested, [this](const QPoint &point){ + this->setupContextMenu(point, ui->treeInputs); + }); + connect(ui->treeOutputs, &QTreeView::customContextMenuRequested, [this](const QPoint &point){ + this->setupContextMenu(point, ui->treeOutputs); + }); + this->adjustSize(); } @@ -217,4 +226,35 @@ void TxConfAdvDialog::closeDialog() { QDialog::reject(); } +void TxConfAdvDialog::setupContextMenu(const QPoint &point, QTreeWidget *tree) { + if (!tree) { + return; + } + + QTreeWidgetItem *header = tree->headerItem(); + if (!header) { + return; + } + + auto* menu = new QMenu(this); + for (int column = 0; column < tree->columnCount(); column++) + { + menu->addAction(QString("Copy %1").arg(header->text(column)), this, [this, column, point, tree]{ + this->copyFromTree(point, column, tree); + }); + } + + menu->popup(tree->viewport()->mapToGlobal(point)); +} + +void TxConfAdvDialog::copyFromTree(const QPoint &point, int column, QTreeWidget *tree) { + QModelIndex index = tree->indexAt(point); + if (!index.isValid()) { + return; + } + + QModelIndex dataIndex = index.sibling(index.row(), column); + Utils::copyToClipboard(dataIndex.data().toString()); +} + TxConfAdvDialog::~TxConfAdvDialog() = default; \ No newline at end of file diff --git a/src/dialog/TxConfAdvDialog.h b/src/dialog/TxConfAdvDialog.h index 5ea28e1..e0faba5 100644 --- a/src/dialog/TxConfAdvDialog.h +++ b/src/dialog/TxConfAdvDialog.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "components.h" #include "libwalletqt/PendingTransaction.h" @@ -34,6 +35,8 @@ private: void broadcastTransaction(); void closeDialog(); void setAmounts(quint64 amount, quint64 fee); + void setupContextMenu(const QPoint &point, QTreeWidget *tree); + void copyFromTree(const QPoint &point, int column, QTreeWidget *tree); void signedCopy(); void signedSaveFile();