Wladimir J. van der Laan
11 years ago
29 changed files with 876 additions and 667 deletions
@ -1,212 +0,0 @@
@@ -1,212 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>QRCodeDialog</class> |
||||
<widget class="QDialog" name="QRCodeDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>340</width> |
||||
<height>530</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>QR Code Dialog</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout_3"> |
||||
<item> |
||||
<widget class="QLabel" name="lblQRCode"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>300</width> |
||||
<height>300</height> |
||||
</size> |
||||
</property> |
||||
<property name="textFormat"> |
||||
<enum>Qt::PlainText</enum> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
<property name="wordWrap"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPlainTextEdit" name="outUri"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>0</width> |
||||
<height>50</height> |
||||
</size> |
||||
</property> |
||||
<property name="tabChangesFocus"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="textInteractionFlags"> |
||||
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QWidget" name="widget" native="true"> |
||||
<layout class="QVBoxLayout" name="verticalLayout_2"> |
||||
<item> |
||||
<widget class="QCheckBox" name="chkReqPayment"> |
||||
<property name="enabled"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Request Payment</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QFormLayout" name="formLayout"> |
||||
<property name="fieldGrowthPolicy"> |
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> |
||||
</property> |
||||
<item row="1" column="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="1" column="1"> |
||||
<widget class="QLineEdit" name="lnLabel"/> |
||||
</item> |
||||
<item row="2" 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="2" column="1"> |
||||
<widget class="QLineEdit" name="lnMessage"/> |
||||
</item> |
||||
<item row="0" 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="0" column="1"> |
||||
<widget class="BitcoinAmountField" name="lnReqAmount"> |
||||
<property name="enabled"> |
||||
<bool>false</bool> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>80</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<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 As...</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<customwidgets> |
||||
<customwidget> |
||||
<class>BitcoinAmountField</class> |
||||
<extends>QLineEdit</extends> |
||||
<header>bitcoinamountfield.h</header> |
||||
</customwidget> |
||||
</customwidgets> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>chkReqPayment</sender> |
||||
<signal>clicked(bool)</signal> |
||||
<receiver>lnReqAmount</receiver> |
||||
<slot>setEnabled(bool)</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>92</x> |
||||
<y>285</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>98</x> |
||||
<y>311</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -0,0 +1,178 @@
@@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>ReceiveCoinsDialog</class> |
||||
<widget class="QWidget" name="ReceiveCoinsDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>776</width> |
||||
<height>343</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Form</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout"> |
||||
<item> |
||||
<layout class="QFormLayout" name="formLayout"> |
||||
<property name="fieldGrowthPolicy"> |
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> |
||||
</property> |
||||
<item row="3" column="0"> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>&Amount:</string> |
||||
</property> |
||||
<property name="buddy"> |
||||
<cstring>reqAmount</cstring> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="1"> |
||||
<widget class="BitcoinAmountField" name="reqAmount"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>80</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>The amount to request</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="4" column="0"> |
||||
<widget class="QLabel" name="label_2"> |
||||
<property name="text"> |
||||
<string>&Label:</string> |
||||
</property> |
||||
<property name="buddy"> |
||||
<cstring>reqLabel</cstring> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="4" column="1"> |
||||
<widget class="QLineEdit" name="reqLabel"> |
||||
<property name="toolTip"> |
||||
<string>The label to associate with the receiving address</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="5" column="0"> |
||||
<widget class="QLabel" name="label_3"> |
||||
<property name="text"> |
||||
<string>&Message:</string> |
||||
</property> |
||||
<property name="buddy"> |
||||
<cstring>reqMessage</cstring> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="5" column="1"> |
||||
<widget class="QLineEdit" name="reqMessage"> |
||||
<property name="toolTip"> |
||||
<string>The message to attach to payment request</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="0"> |
||||
<widget class="QLabel" name="label_4"> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="1"> |
||||
<widget class="QCheckBox" name="reuseAddress"> |
||||
<property name="toolTip"> |
||||
<string>Reuse one of the previously used receiving addresses. Reusing addresses has security and privacy issues. Do not use this unless re-generating a payment request made before.</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>R&euse an existing receiving address (not recommended)</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="1"> |
||||
<widget class="QLabel" name="label_5"> |
||||
<property name="text"> |
||||
<string>Use this form to request payments. All fields are optional.</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QPushButton" name="clearButton"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>Remove all transaction fields</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Clear</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../bitcoin.qrc"> |
||||
<normaloff>:/icons/remove</normaloff>:/icons/remove</iconset> |
||||
</property> |
||||
<property name="autoRepeatDelay"> |
||||
<number>300</number> |
||||
</property> |
||||
<property name="autoDefault"> |
||||
<bool>false</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<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="receiveButton"> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>150</width> |
||||
<height>0</height> |
||||
</size> |
||||
</property> |
||||
<property name="text"> |
||||
<string>&Request payment</string> |
||||
</property> |
||||
<property name="icon"> |
||||
<iconset resource="../bitcoin.qrc"> |
||||
<normaloff>:/icons/receiving_addresses</normaloff>:/icons/receiving_addresses</iconset> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<customwidgets> |
||||
<customwidget> |
||||
<class>BitcoinAmountField</class> |
||||
<extends>QLineEdit</extends> |
||||
<header>bitcoinamountfield.h</header> |
||||
</customwidget> |
||||
</customwidgets> |
||||
<resources> |
||||
<include location="../bitcoin.qrc"/> |
||||
</resources> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,169 @@
@@ -0,0 +1,169 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>ReceiveRequestDialog</class> |
||||
<widget class="QDialog" name="ReceiveRequestDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>487</width> |
||||
<height>597</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Request coins</string> |
||||
</property> |
||||
<layout class="QVBoxLayout" name="verticalLayout_3"> |
||||
<item> |
||||
<widget class="QRImageWidget" name="lblQRCode"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>300</width> |
||||
<height>300</height> |
||||
</size> |
||||
</property> |
||||
<property name="toolTip"> |
||||
<string>QR Code</string> |
||||
</property> |
||||
<property name="textFormat"> |
||||
<enum>Qt::PlainText</enum> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
<property name="wordWrap"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QTextEdit" name="outUri"> |
||||
<property name="sizePolicy"> |
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
||||
<horstretch>0</horstretch> |
||||
<verstretch>0</verstretch> |
||||
</sizepolicy> |
||||
</property> |
||||
<property name="minimumSize"> |
||||
<size> |
||||
<width>0</width> |
||||
<height>50</height> |
||||
</size> |
||||
</property> |
||||
<property name="frameShape"> |
||||
<enum>QFrame::NoFrame</enum> |
||||
</property> |
||||
<property name="frameShadow"> |
||||
<enum>QFrame::Plain</enum> |
||||
</property> |
||||
<property name="tabChangesFocus"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="textInteractionFlags"> |
||||
<set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<item> |
||||
<widget class="QPushButton" name="btnCopyURI"> |
||||
<property name="text"> |
||||
<string>Copy &URI</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="btnCopyAddress"> |
||||
<property name="text"> |
||||
<string>Copy &Address</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="btnCopyImage"> |
||||
<property name="text"> |
||||
<string>&Copy Image</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<widget class="QPushButton" name="btnSaveAs"> |
||||
<property name="text"> |
||||
<string>&Save Image...</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item> |
||||
<spacer name="horizontalSpacer_2"> |
||||
<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="QDialogButtonBox" name="buttonBox"> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Close</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<customwidgets> |
||||
<customwidget> |
||||
<class>QRImageWidget</class> |
||||
<extends>QLabel</extends> |
||||
<header>receiverequestdialog.h</header> |
||||
</customwidget> |
||||
</customwidgets> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>ReceiveRequestDialog</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>452</x> |
||||
<y>573</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>243</x> |
||||
<y>298</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>ReceiveRequestDialog</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>452</x> |
||||
<y>573</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>243</x> |
||||
<y>298</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
@ -1,173 +0,0 @@
@@ -1,173 +0,0 @@
|
||||
#include "qrcodedialog.h" |
||||
#include "ui_qrcodedialog.h" |
||||
|
||||
#include "bitcoinunits.h" |
||||
#include "guiconstants.h" |
||||
#include "guiutil.h" |
||||
#include "optionsmodel.h" |
||||
|
||||
#include <QPixmap> |
||||
#if QT_VERSION < 0x050000 |
||||
#include <QUrl> |
||||
#endif |
||||
|
||||
#include <qrencode.h> |
||||
|
||||
QRCodeDialog::QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::QRCodeDialog), |
||||
model(0), |
||||
address(addr) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
setWindowTitle(QString("%1").arg(address)); |
||||
|
||||
ui->chkReqPayment->setVisible(enableReq); |
||||
ui->lblAmount->setVisible(enableReq); |
||||
ui->lnReqAmount->setVisible(enableReq); |
||||
|
||||
ui->lnLabel->setText(label); |
||||
|
||||
ui->btnSaveAs->setEnabled(false); |
||||
|
||||
genCode(); |
||||
} |
||||
|
||||
QRCodeDialog::~QRCodeDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void QRCodeDialog::setModel(OptionsModel *model) |
||||
{ |
||||
this->model = model; |
||||
|
||||
if (model) |
||||
connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); |
||||
|
||||
// update the display unit, to not use the default ("BTC")
|
||||
updateDisplayUnit(); |
||||
} |
||||
|
||||
void QRCodeDialog::genCode() |
||||
{ |
||||
QString uri = getURI(); |
||||
|
||||
if (uri != "") |
||||
{ |
||||
ui->lblQRCode->setText(""); |
||||
|
||||
QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1); |
||||
if (!code) |
||||
{ |
||||
ui->lblQRCode->setText(tr("Error encoding URI into QR Code.")); |
||||
return; |
||||
} |
||||
myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32); |
||||
myImage.fill(0xffffff); |
||||
unsigned char *p = code->data; |
||||
for (int y = 0; y < code->width; y++) |
||||
{ |
||||
for (int x = 0; x < code->width; x++) |
||||
{ |
||||
myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff)); |
||||
p++; |
||||
} |
||||
} |
||||
QRcode_free(code); |
||||
|
||||
ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300)); |
||||
|
||||
ui->outUri->setPlainText(uri); |
||||
} |
||||
} |
||||
|
||||
QString QRCodeDialog::getURI() |
||||
{ |
||||
QString ret = QString("bitcoin:%1").arg(address); |
||||
int paramCount = 0; |
||||
|
||||
ui->outUri->clear(); |
||||
|
||||
if (ui->chkReqPayment->isChecked()) |
||||
{ |
||||
if (ui->lnReqAmount->validate()) |
||||
{ |
||||
// even if we allow a non BTC unit input in lnReqAmount, we generate the URI with BTC as unit (as defined in BIP21)
|
||||
ret += QString("?amount=%1").arg(BitcoinUnits::format(BitcoinUnits::BTC, ui->lnReqAmount->value())); |
||||
paramCount++; |
||||
} |
||||
else |
||||
{ |
||||
ui->btnSaveAs->setEnabled(false); |
||||
ui->lblQRCode->setText(tr("The entered amount is invalid, please check.")); |
||||
return QString(""); |
||||
} |
||||
} |
||||
|
||||
if (!ui->lnLabel->text().isEmpty()) |
||||
{ |
||||
QString lbl(QUrl::toPercentEncoding(ui->lnLabel->text())); |
||||
ret += QString("%1label=%2").arg(paramCount == 0 ? "?" : "&").arg(lbl); |
||||
paramCount++; |
||||
} |
||||
|
||||
if (!ui->lnMessage->text().isEmpty()) |
||||
{ |
||||
QString msg(QUrl::toPercentEncoding(ui->lnMessage->text())); |
||||
ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg); |
||||
paramCount++; |
||||
} |
||||
|
||||
// limit URI length to prevent a DoS against the QR-Code dialog
|
||||
if (ret.length() > MAX_URI_LENGTH) |
||||
{ |
||||
ui->btnSaveAs->setEnabled(false); |
||||
ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message.")); |
||||
return QString(""); |
||||
} |
||||
|
||||
ui->btnSaveAs->setEnabled(true); |
||||
return ret; |
||||
} |
||||
|
||||
void QRCodeDialog::on_lnReqAmount_textChanged() |
||||
{ |
||||
genCode(); |
||||
} |
||||
|
||||
void QRCodeDialog::on_lnLabel_textChanged() |
||||
{ |
||||
genCode(); |
||||
} |
||||
|
||||
void QRCodeDialog::on_lnMessage_textChanged() |
||||
{ |
||||
genCode(); |
||||
} |
||||
|
||||
void QRCodeDialog::on_btnSaveAs_clicked() |
||||
{ |
||||
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Images (*.png)")); |
||||
if (!fn.isEmpty()) |
||||
myImage.scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE).save(fn); |
||||
} |
||||
|
||||
void QRCodeDialog::on_chkReqPayment_toggled(bool fChecked) |
||||
{ |
||||
if (!fChecked) |
||||
// if chkReqPayment is not active, don't display lnReqAmount as invalid
|
||||
ui->lnReqAmount->setValid(true); |
||||
|
||||
genCode(); |
||||
} |
||||
|
||||
void QRCodeDialog::updateDisplayUnit() |
||||
{ |
||||
if (model) |
||||
{ |
||||
// Update lnReqAmount with the current unit
|
||||
ui->lnReqAmount->setDisplayUnit(model->getDisplayUnit()); |
||||
} |
||||
} |
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
#ifndef QRCODEDIALOG_H |
||||
#define QRCODEDIALOG_H |
||||
|
||||
#include <QDialog> |
||||
#include <QImage> |
||||
|
||||
namespace Ui { |
||||
class QRCodeDialog; |
||||
} |
||||
class OptionsModel; |
||||
|
||||
class QRCodeDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit QRCodeDialog(const QString &addr, const QString &label, bool enableReq, QWidget *parent = 0); |
||||
~QRCodeDialog(); |
||||
|
||||
void setModel(OptionsModel *model); |
||||
|
||||
private slots: |
||||
void on_lnReqAmount_textChanged(); |
||||
void on_lnLabel_textChanged(); |
||||
void on_lnMessage_textChanged(); |
||||
void on_btnSaveAs_clicked(); |
||||
void on_chkReqPayment_toggled(bool fChecked); |
||||
|
||||
void updateDisplayUnit(); |
||||
|
||||
private: |
||||
Ui::QRCodeDialog *ui; |
||||
OptionsModel *model; |
||||
QString address; |
||||
QImage myImage; |
||||
|
||||
void genCode(); |
||||
QString getURI(); |
||||
}; |
||||
|
||||
#endif // QRCODEDIALOG_H
|
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
#include "receivecoinsdialog.h" |
||||
#include "ui_receivecoinsdialog.h" |
||||
|
||||
#include "walletmodel.h" |
||||
#include "bitcoinunits.h" |
||||
#include "addressbookpage.h" |
||||
#include "optionsmodel.h" |
||||
#include "guiutil.h" |
||||
#include "receiverequestdialog.h" |
||||
#include "addresstablemodel.h" |
||||
|
||||
#include <QMessageBox> |
||||
#include <QTextDocument> |
||||
#include <QScrollBar> |
||||
|
||||
ReceiveCoinsDialog::ReceiveCoinsDialog(QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::ReceiveCoinsDialog), |
||||
model(0) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
#ifdef Q_OS_MAC // Icons on push buttons are very uncommon on Mac
|
||||
ui->clearButton->setIcon(QIcon()); |
||||
ui->receiveButton->setIcon(QIcon()); |
||||
#endif |
||||
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear())); |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::setModel(WalletModel *model) |
||||
{ |
||||
this->model = model; |
||||
|
||||
if(model && model->getOptionsModel()) |
||||
{ |
||||
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); |
||||
updateDisplayUnit(); |
||||
} |
||||
} |
||||
|
||||
ReceiveCoinsDialog::~ReceiveCoinsDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::clear() |
||||
{ |
||||
ui->reqAmount->clear(); |
||||
ui->reqLabel->setText(""); |
||||
ui->reqMessage->setText(""); |
||||
ui->reuseAddress->setChecked(false); |
||||
updateDisplayUnit(); |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::reject() |
||||
{ |
||||
clear(); |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::accept() |
||||
{ |
||||
clear(); |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::updateDisplayUnit() |
||||
{ |
||||
if(model && model->getOptionsModel()) |
||||
{ |
||||
ui->reqAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit()); |
||||
} |
||||
} |
||||
|
||||
void ReceiveCoinsDialog::on_receiveButton_clicked() |
||||
{ |
||||
if(!model || !model->getOptionsModel() || !model->getAddressTableModel()) |
||||
return; |
||||
|
||||
QString address; |
||||
QString label = ui->reqLabel->text(); |
||||
if(ui->reuseAddress->isChecked()) |
||||
{ |
||||
/* Choose existing receiving address */ |
||||
AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::ReceivingTab, this); |
||||
dlg.setModel(model->getAddressTableModel()); |
||||
if(dlg.exec()) |
||||
{ |
||||
address = dlg.getReturnValue(); |
||||
if(label.isEmpty()) /* If no label provided, use the previously used label */ |
||||
{ |
||||
label = model->getAddressTableModel()->labelForAddress(address); |
||||
} |
||||
} else { |
||||
return; |
||||
} |
||||
} else { |
||||
/* Generate new receiving address */ |
||||
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, ""); |
||||
} |
||||
SendCoinsRecipient info(address, label, |
||||
ui->reqAmount->value(), ui->reqMessage->text()); |
||||
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); |
||||
dialog->setModel(model->getOptionsModel()); |
||||
dialog->setInfo(info); |
||||
dialog->setAttribute(Qt::WA_DeleteOnClose); |
||||
dialog->show(); |
||||
clear(); |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
#ifndef RECEIVECOINSDIALOG_H |
||||
#define RECEIVECOINSDIALOG_H |
||||
|
||||
#include <QDialog> |
||||
#include <QVariant> |
||||
|
||||
namespace Ui { |
||||
class ReceiveCoinsDialog; |
||||
} |
||||
class WalletModel; |
||||
class OptionsModel; |
||||
|
||||
/** Dialog for requesting payment of bitcoins */ |
||||
class ReceiveCoinsDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit ReceiveCoinsDialog(QWidget *parent = 0); |
||||
~ReceiveCoinsDialog(); |
||||
|
||||
void setModel(WalletModel *model); |
||||
|
||||
public slots: |
||||
void clear(); |
||||
void reject(); |
||||
void accept(); |
||||
|
||||
private: |
||||
Ui::ReceiveCoinsDialog *ui; |
||||
WalletModel *model; |
||||
|
||||
private slots: |
||||
void on_receiveButton_clicked(); |
||||
void updateDisplayUnit(); |
||||
}; |
||||
|
||||
#endif // RECEIVECOINSDIALOG_H
|
@ -0,0 +1,183 @@
@@ -0,0 +1,183 @@
|
||||
#include "receiverequestdialog.h" |
||||
#include "ui_receiverequestdialog.h" |
||||
|
||||
#include "bitcoinunits.h" |
||||
#include "guiconstants.h" |
||||
#include "guiutil.h" |
||||
#include "optionsmodel.h" |
||||
#include "walletmodel.h" |
||||
|
||||
#include <QPixmap> |
||||
#include <QClipboard> |
||||
#include <QMouseEvent> |
||||
#include <QDrag> |
||||
#include <QMimeData> |
||||
#if QT_VERSION < 0x050000 |
||||
#include <QUrl> |
||||
#endif |
||||
|
||||
#include "bitcoin-config.h" /* for USE_QRCODE */ |
||||
|
||||
#ifdef USE_QRCODE |
||||
#include <qrencode.h> |
||||
#endif |
||||
|
||||
QRImageWidget::QRImageWidget(QWidget *parent): |
||||
QLabel(parent) |
||||
{ |
||||
setContextMenuPolicy(Qt::ActionsContextMenu); |
||||
|
||||
QAction *saveImageAction = new QAction(tr("&Save Image..."), this); |
||||
connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage())); |
||||
addAction(saveImageAction); |
||||
QAction *copyImageAction = new QAction(tr("&Copy Image"), this); |
||||
connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage())); |
||||
addAction(copyImageAction); |
||||
} |
||||
|
||||
QImage QRImageWidget::exportImage() |
||||
{ |
||||
return pixmap()->toImage().scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE); |
||||
} |
||||
|
||||
void QRImageWidget::mousePressEvent(QMouseEvent *event) |
||||
{ |
||||
if(event->button() == Qt::LeftButton) |
||||
{ |
||||
event->accept(); |
||||
QMimeData *mimeData = new QMimeData; |
||||
mimeData->setImageData(exportImage()); |
||||
|
||||
QDrag *drag = new QDrag(this); |
||||
drag->setMimeData(mimeData); |
||||
drag->exec(); |
||||
} else { |
||||
QLabel::mousePressEvent(event); |
||||
} |
||||
} |
||||
|
||||
void QRImageWidget::saveImage() |
||||
{ |
||||
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Images (*.png)")); |
||||
if (!fn.isEmpty()) |
||||
{ |
||||
exportImage().save(fn); |
||||
} |
||||
} |
||||
|
||||
void QRImageWidget::copyImage() |
||||
{ |
||||
QApplication::clipboard()->setImage(exportImage()); |
||||
} |
||||
|
||||
ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::ReceiveRequestDialog), |
||||
model(0) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
#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())); |
||||
connect(ui->btnCopyImage, SIGNAL(clicked()), ui->lblQRCode, SLOT(copyImage())); |
||||
} |
||||
|
||||
ReceiveRequestDialog::~ReceiveRequestDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void ReceiveRequestDialog::setModel(OptionsModel *model) |
||||
{ |
||||
this->model = model; |
||||
|
||||
if (model) |
||||
connect(model, SIGNAL(displayUnitChanged(int)), this, SLOT(update())); |
||||
|
||||
// update the display unit if necessary
|
||||
update(); |
||||
} |
||||
|
||||
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); |
||||
QString html; |
||||
html += "<html><font face='verdana, arial, helvetica, sans-serif'>"; |
||||
html += "<b>"+tr("Payment information")+"</b><br>"; |
||||
html += "<b>"+tr("URI")+"</b>: "; |
||||
html += "<a href=\""+uri+"\">" + GUIUtil::HtmlEscape(uri) + "</a><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 |
||||
ui->lblQRCode->setText(""); |
||||
if(!uri.isEmpty()) |
||||
{ |
||||
// limit URI length
|
||||
if (uri.length() > MAX_URI_LENGTH) |
||||
{ |
||||
ui->lblQRCode->setText(tr("Resulting URI too long, try to reduce the text for label / message.")); |
||||
} else { |
||||
QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1); |
||||
if (!code) |
||||
{ |
||||
ui->lblQRCode->setText(tr("Error encoding URI into QR Code.")); |
||||
return; |
||||
} |
||||
QImage myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32); |
||||
myImage.fill(0xffffff); |
||||
unsigned char *p = code->data; |
||||
for (int y = 0; y < code->width; y++) |
||||
{ |
||||
for (int x = 0; x < code->width; x++) |
||||
{ |
||||
myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff)); |
||||
p++; |
||||
} |
||||
} |
||||
QRcode_free(code); |
||||
|
||||
ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300)); |
||||
ui->btnSaveAs->setEnabled(true); |
||||
} |
||||
} |
||||
#endif |
||||
} |
||||
|
||||
void ReceiveRequestDialog::on_btnCopyURI_clicked() |
||||
{ |
||||
QString uri = GUIUtil::formatBitcoinURI(info); |
||||
QApplication::clipboard()->setText(uri, QClipboard::Clipboard); |
||||
QApplication::clipboard()->setText(uri, QClipboard::Selection); |
||||
} |
||||
|
||||
void ReceiveRequestDialog::on_btnCopyAddress_clicked() |
||||
{ |
||||
QApplication::clipboard()->setText(info.address, QClipboard::Clipboard); |
||||
QApplication::clipboard()->setText(info.address, QClipboard::Selection); |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
#ifndef QRCODEDIALOG_H |
||||
#define QRCODEDIALOG_H |
||||
|
||||
#include "walletmodel.h" |
||||
|
||||
#include <QDialog> |
||||
#include <QImage> |
||||
#include <QLabel> |
||||
|
||||
namespace Ui { |
||||
class ReceiveRequestDialog; |
||||
} |
||||
class OptionsModel; |
||||
|
||||
/* Label widget for QR code. This image can be dragged, dropped, copied and saved
|
||||
* to disk. |
||||
*/ |
||||
class QRImageWidget : public QLabel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit QRImageWidget(QWidget *parent = 0); |
||||
QImage exportImage(); |
||||
|
||||
public slots: |
||||
void saveImage(); |
||||
void copyImage(); |
||||
|
||||
protected: |
||||
virtual void mousePressEvent(QMouseEvent *event); |
||||
}; |
||||
|
||||
class ReceiveRequestDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit ReceiveRequestDialog(QWidget *parent = 0); |
||||
~ReceiveRequestDialog(); |
||||
|
||||
void setModel(OptionsModel *model); |
||||
void setInfo(const SendCoinsRecipient &info); |
||||
|
||||
private slots: |
||||
void on_btnCopyURI_clicked(); |
||||
void on_btnCopyAddress_clicked(); |
||||
|
||||
void update(); |
||||
|
||||
private: |
||||
Ui::ReceiveRequestDialog *ui; |
||||
OptionsModel *model; |
||||
SendCoinsRecipient info; |
||||
}; |
||||
|
||||
#endif // QRCODEDIALOG_H
|
Loading…
Reference in new issue