diff options
author | Cozz Lovan <cozzlovan@yahoo.com> | 2014-01-26 06:37:17 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-01-29 14:20:15 +0100 |
commit | 79fb0557cf3b72cac6c7db2b5389a48ac8ab4e22 (patch) | |
tree | d80c45f4c4daaeed5330ad3458cede6534f49d44 /src/qt/receivecoinsdialog.cpp | |
parent | 624154114f30b73662a01dbc8de734dc423a3d51 (diff) |
[Qt] minor receive tab improvements
Diffstat (limited to 'src/qt/receivecoinsdialog.cpp')
-rw-r--r-- | src/qt/receivecoinsdialog.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 38dc88f63b..8ef80d32ea 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -14,6 +14,8 @@ #include "addresstablemodel.h" #include "recentrequeststablemodel.h" +#include <QAction> +#include <QCursor> #include <QMessageBox> #include <QTextDocument> #include <QScrollBar> @@ -31,6 +33,24 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(QWidget *parent) : ui->showRequestButton->setIcon(QIcon()); ui->removeRequestButton->setIcon(QIcon()); #endif + + // context menu actions + QAction *copyLabelAction = new QAction(tr("Copy label"), this); + QAction *copyMessageAction = new QAction(tr("Copy message"), this); + QAction *copyAmountAction = new QAction(tr("Copy amount"), this); + + // context menu + contextMenu = new QMenu(); + contextMenu->addAction(copyLabelAction); + contextMenu->addAction(copyMessageAction); + contextMenu->addAction(copyAmountAction); + + // context menu signals + connect(ui->recentRequestsView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showMenu(QPoint))); + connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel())); + connect(copyMessageAction, SIGNAL(triggered()), this, SLOT(copyMessage())); + connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount())); + connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); } @@ -164,3 +184,61 @@ void ReceiveCoinsDialog::on_removeRequestButton_clicked() QModelIndex firstIndex = selection.at(0); model->getRecentRequestsTableModel()->removeRows(firstIndex.row(), selection.length(), firstIndex.parent()); } + +void ReceiveCoinsDialog::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Return) + { + // press return -> submit form + if (ui->reqLabel->hasFocus() || ui->reqAmount->hasFocus() || ui->reqMessage->hasFocus()) + { + event->ignore(); + on_receiveButton_clicked(); + return; + } + } + + this->QDialog::keyPressEvent(event); +} + +// copy column of selected row to clipboard +void ReceiveCoinsDialog::copyColumnToClipboard(int column) +{ + if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel()) + return; + QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows(); + if(selection.empty()) + return; + // correct for selection mode ContiguousSelection + QModelIndex firstIndex = selection.at(0); + GUIUtil::setClipboard(model->getRecentRequestsTableModel()->data(firstIndex.child(firstIndex.row(), column), Qt::EditRole).toString()); +} + +// context menu +void ReceiveCoinsDialog::showMenu(const QPoint &point) +{ + if(!model || !model->getRecentRequestsTableModel() || !ui->recentRequestsView->selectionModel()) + return; + QModelIndexList selection = ui->recentRequestsView->selectionModel()->selectedRows(); + if(selection.empty()) + return; + contextMenu->exec(QCursor::pos()); +} + +// context menu action: copy label +void ReceiveCoinsDialog::copyLabel() +{ + copyColumnToClipboard(RecentRequestsTableModel::Label); +} + +// context menu action: copy message +void ReceiveCoinsDialog::copyMessage() +{ + copyColumnToClipboard(RecentRequestsTableModel::Message); +} + +// context menu action: copy amount +void ReceiveCoinsDialog::copyAmount() +{ + copyColumnToClipboard(RecentRequestsTableModel::Amount); +} |