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.
This commit is contained in:
parent
786b066f03
commit
33a2febf5d
4 changed files with 86 additions and 221 deletions
|
@ -17,7 +17,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRImageWidget" name="lblQRCode">
|
<widget class="QRImageWidget" name="lblQRCode">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -40,40 +40,9 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="QTextEdit" name="outUri">
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="btnSaveAs">
|
|
||||||
<property name="text">
|
|
||||||
<string>&Save Image...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Bitcoin URI:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPlainTextEdit" name="outUri">
|
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
|
@ -93,130 +62,38 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="text">
|
|
||||||
<string>Payment information:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<spacer name="horizontalSpacer">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<property name="orientation">
|
||||||
<item>
|
<enum>Qt::Horizontal</enum>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
|
||||||
<property name="fieldGrowthPolicy">
|
|
||||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
|
||||||
</property>
|
</property>
|
||||||
<item row="2" column="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<widget class="QLabel" name="lblLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Label:</string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::PlainText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>lnLabel</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QLineEdit" name="lnLabel">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="lblMessage">
|
|
||||||
<property name="text">
|
|
||||||
<string>Message:</string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::PlainText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>lnMessage</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLineEdit" name="lnMessage">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="readOnly">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="lblAmount">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Amount:</string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::PlainText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>lnReqAmount</cstring>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="BitcoinAmountField" name="lnReqAmount" native="true">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
<size>
|
||||||
<width>80</width>
|
<width>40</width>
|
||||||
<height>0</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="readOnly" stdset="0">
|
</spacer>
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QPushButton" name="btnCopyURI">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Address:</string>
|
<string>Copy &URI</string>
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::PlainText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>reqAddress</cstring>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item>
|
||||||
<widget class="QLineEdit" name="lnAddress">
|
<widget class="QPushButton" name="btnCopyImage">
|
||||||
<property name="readOnly">
|
<property name="text">
|
||||||
<bool>true</bool>
|
<string>&Copy Image</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSaveAs">
|
||||||
|
<property name="text">
|
||||||
|
<string>&Save Image...</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -224,15 +101,7 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
|
||||||
<class>BitcoinAmountField</class>
|
|
||||||
<extends>QWidget</extends>
|
|
||||||
<header>bitcoinamountfield.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>QRImageWidget</class>
|
<class>QRImageWidget</class>
|
||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
|
|
|
@ -98,8 +98,9 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
|
||||||
}
|
}
|
||||||
SendCoinsRecipient info(address, label,
|
SendCoinsRecipient info(address, label,
|
||||||
ui->reqAmount->value(), ui->reqMessage->text());
|
ui->reqAmount->value(), ui->reqMessage->text());
|
||||||
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(info, this);
|
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
|
||||||
dialog->setModel(model->getOptionsModel());
|
dialog->setModel(model->getOptionsModel());
|
||||||
|
dialog->setInfo(info);
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
dialog->show();
|
dialog->show();
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QMimeData>
|
||||||
#if QT_VERSION < 0x050000
|
#if QT_VERSION < 0x050000
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,34 +67,21 @@ void QRImageWidget::copyImage()
|
||||||
QApplication::clipboard()->setImage(exportImage());
|
QApplication::clipboard()->setImage(exportImage());
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiveRequestDialog::ReceiveRequestDialog(const SendCoinsRecipient &info, QWidget *parent) :
|
ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ReceiveRequestDialog),
|
ui(new Ui::ReceiveRequestDialog),
|
||||||
model(0),
|
model(0)
|
||||||
info(info)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
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
|
#ifndef USE_QRCODE
|
||||||
ui->btnSaveAs->setVisible(false);
|
ui->btnSaveAs->setVisible(false);
|
||||||
|
ui->btnCopyImage->setVisible(false);
|
||||||
ui->lblQRCode->setVisible(false);
|
ui->lblQRCode->setVisible(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(ui->btnSaveAs, SIGNAL(clicked()), ui->lblQRCode, SLOT(saveImage()));
|
connect(ui->btnSaveAs, SIGNAL(clicked()), ui->lblQRCode, SLOT(saveImage()));
|
||||||
|
connect(ui->btnCopyImage, SIGNAL(clicked()), ui->lblQRCode, SLOT(copyImage()));
|
||||||
genCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiveRequestDialog::~ReceiveRequestDialog()
|
ReceiveRequestDialog::~ReceiveRequestDialog()
|
||||||
|
@ -104,17 +94,42 @@ void ReceiveRequestDialog::setModel(OptionsModel *model)
|
||||||
this->model = model;
|
this->model = model;
|
||||||
|
|
||||||
if (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")
|
// update the display unit if necessary
|
||||||
updateDisplayUnit();
|
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);
|
QString uri = GUIUtil::formatBitcoinURI(info);
|
||||||
ui->btnSaveAs->setEnabled(false);
|
ui->btnSaveAs->setEnabled(false);
|
||||||
ui->outUri->setPlainText(uri);
|
QString html;
|
||||||
|
html += "<html><font face='verdana, arial, helvetica, sans-serif'>";
|
||||||
|
html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><br>";
|
||||||
|
html += "<br>";
|
||||||
|
html += "<b>"+tr("Payment information")+"</b><br>";
|
||||||
|
html += "<b>"+tr("Address")+"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>";
|
||||||
|
if(info.amount)
|
||||||
|
html += "<b>"+tr("Amount")+"</b>: " + BitcoinUnits::formatWithUnit(model->getDisplayUnit(), info.amount) + "<br>";
|
||||||
|
if(!info.label.isEmpty())
|
||||||
|
html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
|
||||||
|
if(!info.message.isEmpty())
|
||||||
|
html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
|
||||||
|
ui->outUri->setText(html);
|
||||||
|
|
||||||
#ifdef USE_QRCODE
|
#ifdef USE_QRCODE
|
||||||
ui->lblQRCode->setText("");
|
ui->lblQRCode->setText("");
|
||||||
|
@ -151,26 +166,10 @@ void ReceiveRequestDialog::genCode()
|
||||||
#endif
|
#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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,25 +36,21 @@ class ReceiveRequestDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ReceiveRequestDialog(const SendCoinsRecipient &info, QWidget *parent = 0);
|
explicit ReceiveRequestDialog(QWidget *parent = 0);
|
||||||
~ReceiveRequestDialog();
|
~ReceiveRequestDialog();
|
||||||
|
|
||||||
void setModel(OptionsModel *model);
|
void setModel(OptionsModel *model);
|
||||||
|
void setInfo(const SendCoinsRecipient &info);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_lnReqAmount_textChanged();
|
void on_btnCopyURI_clicked();
|
||||||
void on_lnLabel_textChanged();
|
|
||||||
void on_lnMessage_textChanged();
|
|
||||||
|
|
||||||
void updateDisplayUnit();
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ReceiveRequestDialog *ui;
|
Ui::ReceiveRequestDialog *ui;
|
||||||
OptionsModel *model;
|
OptionsModel *model;
|
||||||
SendCoinsRecipient info;
|
SendCoinsRecipient info;
|
||||||
|
|
||||||
void genCode();
|
|
||||||
QString getURI();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QRCODEDIALOG_H
|
#endif // QRCODEDIALOG_H
|
||||||
|
|
Loading…
Reference in a new issue