From 33a2febf5de0c7bd73c0ea409584487bd9995643 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 18 Oct 2013 14:25:35 +0200 Subject: [PATCH] qt: show payment information in one text area Simplifies the dialog (makes it look less crowded) as well as the code and makes it possible to copy multiple fields at once. Also format bitcoin URI as URI, add copy button for URI. --- src/qt/forms/receiverequestdialog.ui | 209 +++++---------------------- src/qt/receivecoinsdialog.cpp | 3 +- src/qt/receiverequestdialog.cpp | 83 ++++++----- src/qt/receiverequestdialog.h | 12 +- 4 files changed, 86 insertions(+), 221 deletions(-) diff --git a/src/qt/forms/receiverequestdialog.ui b/src/qt/forms/receiverequestdialog.ui index 4f53dc19b..fc0d10b4e 100644 --- a/src/qt/forms/receiverequestdialog.ui +++ b/src/qt/forms/receiverequestdialog.ui @@ -17,7 +17,7 @@ - + 0 0 @@ -40,40 +40,9 @@ - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Save Image... - - - - - - - - - Bitcoin URI: - - - - - + - + 0 0 @@ -93,146 +62,46 @@ - - - Payment information: - - - - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Label: - - - Qt::PlainText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - lnLabel - - - - - - - true - - - true - - - - - - - Message: - - - Qt::PlainText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - lnMessage - - - - - - - true - - - true - - - - - - - - 0 - 0 - - - - Amount: - - - Qt::PlainText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - lnReqAmount - - - - - - - true - - - - 80 - 0 - - - - true - - - - - - - Address: - - - Qt::PlainText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - reqAddress - - - - - - - true - - - - - - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Copy &URI + + + + + + + &Copy Image + + + + + + + &Save Image... + + + + - - BitcoinAmountField - QWidget -
bitcoinamountfield.h
-
QRImageWidget QLabel diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index fff678d0c..f3ab343fe 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -98,8 +98,9 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() } SendCoinsRecipient info(address, label, ui->reqAmount->value(), ui->reqMessage->text()); - ReceiveRequestDialog *dialog = new ReceiveRequestDialog(info, this); + ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); dialog->setModel(model->getOptionsModel()); + dialog->setInfo(info); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); clear(); diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index efbc6ebd7..f6031e2b4 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #if QT_VERSION < 0x050000 #include #endif @@ -64,34 +67,21 @@ void QRImageWidget::copyImage() QApplication::clipboard()->setImage(exportImage()); } -ReceiveRequestDialog::ReceiveRequestDialog(const SendCoinsRecipient &info, QWidget *parent) : +ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ReceiveRequestDialog), - model(0), - info(info) + model(0) { ui->setupUi(this); - QString target = info.label; - if(target.isEmpty()) - target = info.address; - setWindowTitle(tr("Request payment to %1").arg(target)); - - ui->lnAddress->setText(info.address); - if(info.amount) - ui->lnReqAmount->setValue(info.amount); - ui->lnReqAmount->setReadOnly(true); - ui->lnLabel->setText(info.label); - ui->lnMessage->setText(info.message); - #ifndef USE_QRCODE ui->btnSaveAs->setVisible(false); + ui->btnCopyImage->setVisible(false); ui->lblQRCode->setVisible(false); #endif connect(ui->btnSaveAs, SIGNAL(clicked()), ui->lblQRCode, SLOT(saveImage())); - - genCode(); + connect(ui->btnCopyImage, SIGNAL(clicked()), ui->lblQRCode, SLOT(copyImage())); } ReceiveRequestDialog::~ReceiveRequestDialog() @@ -104,17 +94,42 @@ void ReceiveRequestDialog::setModel(OptionsModel *model) this->model = model; if (model) - connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); + connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(update())); - // update the display unit, to not use the default ("BTC") - updateDisplayUnit(); + // update the display unit if necessary + update(); } -void ReceiveRequestDialog::genCode() +void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &info) { + this->info = info; + update(); +} + +void ReceiveRequestDialog::update() +{ + if(!model) + return; + QString target = info.label; + if(target.isEmpty()) + target = info.address; + setWindowTitle(tr("Request payment to %1").arg(target)); + QString uri = GUIUtil::formatBitcoinURI(info); ui->btnSaveAs->setEnabled(false); - ui->outUri->setPlainText(uri); + QString html; + html += ""; + html += "" + GUIUtil::HtmlEscape(uri) + "
"; + html += "
"; + html += ""+tr("Payment information")+"
"; + html += ""+tr("Address")+": " + GUIUtil::HtmlEscape(info.address) + "
"; + if(info.amount) + html += ""+tr("Amount")+": " + BitcoinUnits::formatWithUnit(model->getDisplayUnit(), info.amount) + "
"; + if(!info.label.isEmpty()) + html += ""+tr("Label")+": " + GUIUtil::HtmlEscape(info.label) + "
"; + if(!info.message.isEmpty()) + html += ""+tr("Message")+": " + GUIUtil::HtmlEscape(info.message) + "
"; + ui->outUri->setText(html); #ifdef USE_QRCODE ui->lblQRCode->setText(""); @@ -151,26 +166,10 @@ void ReceiveRequestDialog::genCode() #endif } -void ReceiveRequestDialog::on_lnReqAmount_textChanged() +void ReceiveRequestDialog::on_btnCopyURI_clicked() { - genCode(); + QString uri = GUIUtil::formatBitcoinURI(info); + QApplication::clipboard()->setText(uri, QClipboard::Clipboard); + QApplication::clipboard()->setText(uri, QClipboard::Selection); } -void ReceiveRequestDialog::on_lnLabel_textChanged() -{ - genCode(); -} - -void ReceiveRequestDialog::on_lnMessage_textChanged() -{ - genCode(); -} - -void ReceiveRequestDialog::updateDisplayUnit() -{ - if (model) - { - // Update lnReqAmount with the current unit - ui->lnReqAmount->setDisplayUnit(model->getDisplayUnit()); - } -} diff --git a/src/qt/receiverequestdialog.h b/src/qt/receiverequestdialog.h index bfe50bde7..8db1ad83a 100644 --- a/src/qt/receiverequestdialog.h +++ b/src/qt/receiverequestdialog.h @@ -36,25 +36,21 @@ class ReceiveRequestDialog : public QDialog Q_OBJECT public: - explicit ReceiveRequestDialog(const SendCoinsRecipient &info, QWidget *parent = 0); + explicit ReceiveRequestDialog(QWidget *parent = 0); ~ReceiveRequestDialog(); void setModel(OptionsModel *model); + void setInfo(const SendCoinsRecipient &info); private slots: - void on_lnReqAmount_textChanged(); - void on_lnLabel_textChanged(); - void on_lnMessage_textChanged(); + void on_btnCopyURI_clicked(); - void updateDisplayUnit(); + void update(); private: Ui::ReceiveRequestDialog *ui; OptionsModel *model; SendCoinsRecipient info; - - void genCode(); - QString getURI(); }; #endif // QRCODEDIALOG_H