From 79fb0557cf3b72cac6c7db2b5389a48ac8ab4e22 Mon Sep 17 00:00:00 2001 From: Cozz Lovan Date: Sun, 26 Jan 2014 06:37:17 +0100 Subject: [PATCH] [Qt] minor receive tab improvements --- src/qt/forms/receivecoinsdialog.ui | 77 +++++++++++++++++++------- src/qt/forms/sendcoinsdialog.ui | 84 ++++++++++++++--------------- src/qt/receivecoinsdialog.cpp | 78 +++++++++++++++++++++++++++ src/qt/receivecoinsdialog.h | 12 +++++ src/qt/recentrequeststablemodel.cpp | 5 +- 5 files changed, 193 insertions(+), 63 deletions(-) diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui index e93636ea5f8..e5a8812711d 100644 --- a/src/qt/forms/receivecoinsdialog.ui +++ b/src/qt/forms/receivecoinsdialog.ui @@ -10,8 +10,23 @@ 364 - + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Sunken + + + @@ -32,6 +47,9 @@ + + An optional message to attach to the payment request, which will be displayed when the request is opened. Note: The message will not be sent with the payment over the Bitcoin network. + &Message: @@ -46,7 +64,7 @@ - An optional label to associate with the new receiving address + An optional label to associate with the new receiving address. @@ -66,6 +84,9 @@ + + An optional label to associate with the new receiving address. + &Label: @@ -79,6 +100,9 @@ + + An optional amount to request. Leave this empty or zero to not request a specific amount. + &Amount: @@ -103,10 +127,25 @@ - - - + + + + + + 150 + 0 + + + + &Request payment + + + + :/icons/receiving_addresses:/icons/receiving_addresses + + + @@ -146,25 +185,20 @@ - - - - - 150 - 0 - - + + + + - &Request payment - - - - :/icons/receiving_addresses:/icons/receiving_addresses + + + + @@ -173,7 +207,7 @@ 20 - 40 + 10 @@ -202,12 +236,15 @@ - Requested payments + Requested payments history + + Qt::CustomContextMenu + true diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index db8271b0169..95f3294adbe 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -657,19 +657,25 @@ - + + + + 150 + 0 + + - Send to multiple recipients at once + Confirm the send action - Add &Recipient + S&end - :/icons/add:/icons/add + :/icons/send:/icons/send - - false + + true @@ -699,6 +705,36 @@ + + + + Send to multiple recipients at once + + + Add &Recipient + + + + :/icons/add:/icons/add + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -726,42 +762,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 150 - 0 - - - - Confirm the send action - - - S&end - - - - :/icons/send:/icons/send - - - true - - - diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 38dc88f63bf..8ef80d32ea6 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -14,6 +14,8 @@ #include "addresstablemodel.h" #include "recentrequeststablemodel.h" +#include +#include #include #include #include @@ -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); +} diff --git a/src/qt/receivecoinsdialog.h b/src/qt/receivecoinsdialog.h index ed4b04d3612..2c6de0cbca2 100644 --- a/src/qt/receivecoinsdialog.h +++ b/src/qt/receivecoinsdialog.h @@ -6,6 +6,9 @@ #define RECEIVECOINSDIALOG_H #include +#include +#include +#include #include namespace Ui { @@ -34,9 +37,14 @@ public slots: void reject(); void accept(); +protected: + virtual void keyPressEvent(QKeyEvent *event); + private: Ui::ReceiveCoinsDialog *ui; WalletModel *model; + QMenu *contextMenu; + void copyColumnToClipboard(int column); private slots: void on_receiveButton_clicked(); @@ -44,6 +52,10 @@ private slots: void on_removeRequestButton_clicked(); void on_recentRequestsView_doubleClicked(const QModelIndex &index); void updateDisplayUnit(); + void showMenu(const QPoint &); + void copyLabel(); + void copyMessage(); + void copyAmount(); }; #endif // RECEIVECOINSDIALOG_H diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp index 74b43f1d24b..64f140bc862 100644 --- a/src/qt/recentrequeststablemodel.cpp +++ b/src/qt/recentrequeststablemodel.cpp @@ -75,7 +75,10 @@ QVariant RecentRequestsTableModel::data(const QModelIndex &index, int role) cons return rec->recipient.message; } case Amount: - return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount); + if (rec->recipient.amount == 0 && role == Qt::DisplayRole) + return tr("(no amount)"); + else + return BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), rec->recipient.amount); } } return QVariant();