From 50647c01333fdea56c2d248a3385afbd91bf0dda Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 29 May 2020 10:02:16 +0200 Subject: [PATCH] Merge #17597: qt: Fix height of QR-less ReceiveRequestDialog 73529f0859c060087dd41e9e176fd4198d0f385f qt: Rename slot to updateDisplayUnit() (Hennadii Stepanov) 68288ef0c15522799d4bf6239d2ae1e8086b5abf qt: Overhaul ReceiveRequestDialog (Hennadii Stepanov) Pull request description: If master (89a1f7a250ef70ff2d65701564f1e24bb9280d90) is compiled without QR support, the "Request payment to..." dialog looks ugly: ![Screenshot from 2019-11-25 19-58-59](https://user-images.githubusercontent.com/32963518/69566647-3d9c1c80-0fc0-11ea-8ff6-183cea9372c5.png) With this PR: ![Screenshot from 2019-12-26 00-42-46](https://user-images.githubusercontent.com/32963518/71451226-221c6100-277a-11ea-94ae-c19a5c6256f7.png) ![Screenshot from 2019-12-26 00-44-34](https://user-images.githubusercontent.com/32963518/71451228-29436f00-277a-11ea-8ac5-1bafe6d73b5c.png) ![Screenshot from 2019-12-26 00-48-51](https://user-images.githubusercontent.com/32963518/71451230-2e082300-277a-11ea-8c4c-726ca7b776e7.png) Other minor changes: - "URI" abbreviation is not translated now - wallet name is shown if available ACKs for top commit: jonasschnelli: Tested ACK 73529f0859c060087dd41e9e176fd4198d0f385f Tree-SHA512: 45f9a41d3c72978d78eb2e8ca98e274b8be5abf5352fd3e1f4f49514ce744994545fb3012e80600ded936ae41c6be4d4825a0c5f7bcb3db671d69e0299f0f65b --- src/qt/forms/receiverequestdialog.ui | 288 +++++++++++++++++++++------ src/qt/receiverequestdialog.cpp | 89 +++++---- src/qt/receiverequestdialog.h | 3 +- src/qt/test/wallettests.cpp | 26 ++- 4 files changed, 290 insertions(+), 116 deletions(-) diff --git a/src/qt/forms/receiverequestdialog.ui b/src/qt/forms/receiverequestdialog.ui index 9f896ee3b199bc..f6d47234655e5c 100644 --- a/src/qt/forms/receiverequestdialog.ui +++ b/src/qt/forms/receiverequestdialog.ui @@ -6,68 +6,233 @@ 0 0 - 487 - 597 + 413 + 229 - - - - - - 0 - 0 - - - - - 300 - 320 - - - - QR Code + + Request payment to ... + + + + QLayout::SetFixedSize + + + + + QR image + + + Qt::NoTextInteraction + + + + + + + + 75 + true + + + + Payment information + + + Qt::NoTextInteraction + + + + + + + + 75 + true + + + + URI: Qt::PlainText - - Qt::AlignCenter + + Qt::NoTextInteraction + + + + + + + bitcoin:BC1... + + + Qt::RichText true + + Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Address: + + + Qt::NoTextInteraction + - - - - - 0 - 0 - - - - - 0 - 50 - - - - QFrame::NoFrame - - - QFrame::Plain - - + + + + bc1... + + + Qt::PlainText + + + Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Amount: + + + Qt::NoTextInteraction + + + + + + + 0.00000000 BTC + + + Qt::PlainText + + + Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Label: + + + Qt::NoTextInteraction + + + + + + + label content + + + Qt::PlainText + + + true + + + Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Message: + + + Qt::NoTextInteraction + + + + + + + message content + + + Qt::PlainText + + + true + + + Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + Wallet: + + + Qt::NoTextInteraction + + + + + + + wallet name + + + Qt::PlainText + + true - Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + Qt::TextSelectableByMouse - + @@ -114,8 +279,11 @@ + + Qt::StrongFocus + - QDialogButtonBox::Close + QDialogButtonBox::Ok @@ -130,24 +298,14 @@
qt/qrimagewidget.h
+ + buttonBox + btnCopyURI + btnCopyAddress + btnSaveAs + - - buttonBox - rejected() - ReceiveRequestDialog - reject() - - - 452 - 573 - - - 243 - 298 - - - buttonBox accepted() @@ -155,12 +313,12 @@ accept() - 452 - 573 + 135 + 230 - 243 - 298 + 135 + 126 diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index be2aeb06e1e086..028a58092b3ddd 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -11,8 +11,8 @@ #include #include -#include -#include +#include +#include #if defined(HAVE_CONFIG_H) #include /* for USE_QRCODE */ @@ -27,13 +27,6 @@ ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) : GUIUtil::updateFonts(); -#ifndef USE_QRCODE - ui->btnSaveAs->setVisible(false); - ui->lblQRCode->setVisible(false); -#endif - - connect(ui->btnSaveAs, &QPushButton::clicked, ui->lblQRCode, &QRImageWidget::saveImage); - GUIUtil::handleCloseWindowShortcut(this); } @@ -47,7 +40,7 @@ void ReceiveRequestDialog::setModel(WalletModel *_model) this->model = _model; if (_model) - connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &ReceiveRequestDialog::update); + connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &ReceiveRequestDialog::updateDisplayUnit); // update the display unit if necessary update(); @@ -56,41 +49,57 @@ void ReceiveRequestDialog::setModel(WalletModel *_model) void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &_info) { this->info = _info; - update(); -} + setWindowTitle(tr("Request payment to %1").arg(info.label.isEmpty() ? info.address : info.label)); + QString uri = GUIUtil::formatBitcoinURI(info); -void ReceiveRequestDialog::update() -{ - if(!model) - return; - QString target = info.label; - if(target.isEmpty()) - target = info.address; - setWindowTitle(tr("Request payment to %1").arg(target)); +#ifdef USE_QRCODE + if (ui->qr_code->setQR(uri, info.address)) { + connect(ui->btnSaveAs, &QPushButton::clicked, ui->qr_code, &QRImageWidget::saveImage); + } else { + ui->btnSaveAs->setEnabled(false); + } +#else + ui->btnSaveAs->hide(); + ui->qr_code->hide(); +#endif - QString uri = GUIUtil::formatBitcoinURI(info); - ui->btnSaveAs->setEnabled(false); - QString html; - html += ""; - html += "" + tr("Payment information") + "

"; - html += ""+tr("URI")+": "; - html += QString("" + GUIUtil::HtmlEscape(uri) + "
"; - html += ""+tr("Address")+": " + GUIUtil::HtmlEscape(info.address) + "
"; - if(info.amount) - html += ""+tr("Amount")+": " + BitcoinUnits::formatHtmlWithUnit(model->getOptionsModel()->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) + "
"; - if(model->isMultiwallet()) { - html += ""+tr("Wallet")+": " + GUIUtil::HtmlEscape(model->getWalletName()) + "
"; + QString uri_style = GUIUtil::getThemedStyleQString(GUIUtil::ThemedStyle::TS_COMMAND); + ui->uri_content->setText(QString("%3").arg(uri_style).arg(uri).arg(GUIUtil::HtmlEscape(uri))); + ui->address_content->setText(info.address); + + if (!info.amount) { + ui->amount_tag->hide(); + ui->amount_content->hide(); + } // Amount is set in updateDisplayUnit() slot. + updateDisplayUnit(); + + if (!info.label.isEmpty()) { + ui->label_content->setText(info.label); + } else { + ui->label_tag->hide(); + ui->label_content->hide(); } - ui->outUri->setText(html); - if (ui->lblQRCode->setQR(uri, info.address)) { - ui->btnSaveAs->setEnabled(true); + if (!info.message.isEmpty()) { + ui->message_content->setText(info.message); + } else { + ui->message_tag->hide(); + ui->message_content->hide(); } + + if (!model->getWalletName().isEmpty()) { + ui->wallet_content->setText(model->getWalletName()); + } else { + ui->wallet_tag->hide(); + ui->wallet_content->hide(); + } +} + +void ReceiveRequestDialog::updateDisplayUnit() +{ + if(!model) + return; + ui->amount_content->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), info.amount)); } void ReceiveRequestDialog::on_btnCopyURI_clicked() diff --git a/src/qt/receiverequestdialog.h b/src/qt/receiverequestdialog.h index 40e3d5ffa8ac8f..846478643d819d 100644 --- a/src/qt/receiverequestdialog.h +++ b/src/qt/receiverequestdialog.h @@ -29,8 +29,7 @@ class ReceiveRequestDialog : public QDialog private Q_SLOTS: void on_btnCopyURI_clicked(); void on_btnCopyAddress_clicked(); - - void update(); + void updateDisplayUnit(); private: Ui::ReceiveRequestDialog *ui; diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index efbb33c39b1a2f..deb3b76aa3e15c 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -192,15 +192,23 @@ void TestGUI(interfaces::Node& node) for (QWidget* widget : QApplication::topLevelWidgets()) { if (widget->inherits("ReceiveRequestDialog")) { ReceiveRequestDialog* receiveRequestDialog = qobject_cast(widget); - QTextEdit* rlist = receiveRequestDialog->QObject::findChild("outUri"); - QString paymentText = rlist->toPlainText(); - QStringList paymentTextList = paymentText.split('\n'); - QCOMPARE(paymentTextList.at(0), QString("Payment information")); - QVERIFY(paymentTextList.at(2).indexOf(QString("URI: dash:")) != -1); - QVERIFY(paymentTextList.at(3).indexOf(QString("Address:")) != -1); - QCOMPARE(paymentTextList.at(4), QString("Amount: 0.00000001 ") + BitcoinUnits::name(unit)); - QCOMPARE(paymentTextList.at(5), QString("Label: TEST_LABEL_1")); - QCOMPARE(paymentTextList.at(6), QString("Message: TEST_MESSAGE_1")); + QCOMPARE(receiveRequestDialog->QObject::findChild("payment_header")->text(), QString("Payment information")); + QCOMPARE(receiveRequestDialog->QObject::findChild("uri_tag")->text(), QString("URI:")); + QString uri = receiveRequestDialog->QObject::findChild("uri_content")->text(); + QCOMPARE(uri.count("dash:"), 2); + QCOMPARE(receiveRequestDialog->QObject::findChild("address_tag")->text(), QString("Address:")); + + QCOMPARE(uri.count("amount=0.00000001"), 2); + QCOMPARE(receiveRequestDialog->QObject::findChild("amount_tag")->text(), QString("Amount:")); + QCOMPARE(receiveRequestDialog->QObject::findChild("amount_content")->text(), QString("0.00000001 ") + BitcoinUnits::name(unit)); + + QCOMPARE(uri.count("label=TEST_LABEL_1"), 2); + QCOMPARE(receiveRequestDialog->QObject::findChild("label_tag")->text(), QString("Label:")); + QCOMPARE(receiveRequestDialog->QObject::findChild("label_content")->text(), QString("TEST_LABEL_1")); + + QCOMPARE(uri.count("message=TEST_MESSAGE_1"), 2); + QCOMPARE(receiveRequestDialog->QObject::findChild("message_tag")->text(), QString("Message:")); + QCOMPARE(receiveRequestDialog->QObject::findChild("message_content")->text(), QString("TEST_MESSAGE_1")); } }