Changeset View
Changeset View
Standalone View
Standalone View
src/qt/receiverequestdialog.cpp
Show All 33 Lines | QRImageWidget::QRImageWidget(QWidget *parent) : QLabel(parent), contextMenu(0) { | ||||
connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage())); | connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage())); | ||||
contextMenu->addAction(saveImageAction); | contextMenu->addAction(saveImageAction); | ||||
QAction *copyImageAction = new QAction(tr("&Copy Image"), this); | QAction *copyImageAction = new QAction(tr("&Copy Image"), this); | ||||
connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage())); | connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage())); | ||||
contextMenu->addAction(copyImageAction); | contextMenu->addAction(copyImageAction); | ||||
} | } | ||||
QImage QRImageWidget::exportImage() { | QImage QRImageWidget::exportImage() { | ||||
if (!pixmap()) return QImage(); | if (!pixmap()) { | ||||
return QImage(); | |||||
} | |||||
return pixmap()->toImage(); | return pixmap()->toImage(); | ||||
} | } | ||||
void QRImageWidget::mousePressEvent(QMouseEvent *event) { | void QRImageWidget::mousePressEvent(QMouseEvent *event) { | ||||
if (event->button() == Qt::LeftButton && pixmap()) { | if (event->button() == Qt::LeftButton && pixmap()) { | ||||
event->accept(); | event->accept(); | ||||
QMimeData *mimeData = new QMimeData; | QMimeData *mimeData = new QMimeData; | ||||
mimeData->setImageData(exportImage()); | mimeData->setImageData(exportImage()); | ||||
QDrag *drag = new QDrag(this); | QDrag *drag = new QDrag(this); | ||||
drag->setMimeData(mimeData); | drag->setMimeData(mimeData); | ||||
drag->exec(); | drag->exec(); | ||||
} else { | } else { | ||||
QLabel::mousePressEvent(event); | QLabel::mousePressEvent(event); | ||||
} | } | ||||
} | } | ||||
void QRImageWidget::saveImage() { | void QRImageWidget::saveImage() { | ||||
if (!pixmap()) return; | if (!pixmap()) { | ||||
return; | |||||
} | |||||
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), | QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), | ||||
tr("PNG Image (*.png)"), nullptr); | tr("PNG Image (*.png)"), nullptr); | ||||
if (!fn.isEmpty()) { | if (!fn.isEmpty()) { | ||||
exportImage().save(fn); | exportImage().save(fn); | ||||
} | } | ||||
} | } | ||||
void QRImageWidget::copyImage() { | void QRImageWidget::copyImage() { | ||||
if (!pixmap()) return; | if (!pixmap()) { | ||||
return; | |||||
} | |||||
QApplication::clipboard()->setImage(exportImage()); | QApplication::clipboard()->setImage(exportImage()); | ||||
} | } | ||||
void QRImageWidget::contextMenuEvent(QContextMenuEvent *event) { | void QRImageWidget::contextMenuEvent(QContextMenuEvent *event) { | ||||
if (!pixmap()) return; | if (!pixmap()) { | ||||
return; | |||||
} | |||||
contextMenu->exec(event->globalPos()); | contextMenu->exec(event->globalPos()); | ||||
} | } | ||||
ReceiveRequestDialog::ReceiveRequestDialog(const Config *configIn, | ReceiveRequestDialog::ReceiveRequestDialog(const Config *configIn, | ||||
QWidget *parent) | QWidget *parent) | ||||
: QDialog(parent), ui(new Ui::ReceiveRequestDialog), model(0), | : QDialog(parent), ui(new Ui::ReceiveRequestDialog), model(0), | ||||
config(configIn) { | config(configIn) { | ||||
ui->setupUi(this); | ui->setupUi(this); | ||||
#ifndef USE_QRCODE | #ifndef USE_QRCODE | ||||
ui->btnSaveAs->setVisible(false); | ui->btnSaveAs->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())); | ||||
} | } | ||||
ReceiveRequestDialog::~ReceiveRequestDialog() { | ReceiveRequestDialog::~ReceiveRequestDialog() { | ||||
delete ui; | delete ui; | ||||
} | } | ||||
void ReceiveRequestDialog::setModel(WalletModel *_model) { | void ReceiveRequestDialog::setModel(WalletModel *_model) { | ||||
this->model = _model; | this->model = _model; | ||||
if (_model) | if (_model) { | ||||
connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), | connect(_model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), | ||||
this, SLOT(update())); | this, SLOT(update())); | ||||
} | |||||
// update the display unit if necessary | // update the display unit if necessary | ||||
update(); | update(); | ||||
} | } | ||||
void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &_info) { | void ReceiveRequestDialog::setInfo(const SendCoinsRecipient &_info) { | ||||
this->info = _info; | this->info = _info; | ||||
// Display addresses with currently configured encoding. | // Display addresses with currently configured encoding. | ||||
this->info.address = | this->info.address = | ||||
GUIUtil::convertToConfiguredAddressFormat(*config, this->info.address); | GUIUtil::convertToConfiguredAddressFormat(*config, this->info.address); | ||||
update(); | update(); | ||||
} | } | ||||
void ReceiveRequestDialog::update() { | void ReceiveRequestDialog::update() { | ||||
if (!model) return; | if (!model) { | ||||
return; | |||||
} | |||||
QString target = info.label; | QString target = info.label; | ||||
if (target.isEmpty()) target = info.address; | if (target.isEmpty()) { | ||||
target = info.address; | |||||
} | |||||
setWindowTitle(tr("Request payment to %1").arg(target)); | setWindowTitle(tr("Request payment to %1").arg(target)); | ||||
QString uri = GUIUtil::formatBitcoinURI(*config, info); | QString uri = GUIUtil::formatBitcoinURI(*config, info); | ||||
ui->btnSaveAs->setEnabled(false); | ui->btnSaveAs->setEnabled(false); | ||||
QString html; | QString html; | ||||
html += "<html><font face='verdana, arial, helvetica, sans-serif'>"; | html += "<html><font face='verdana, arial, helvetica, sans-serif'>"; | ||||
html += "<b>" + tr("Payment information") + "</b><br>"; | html += "<b>" + tr("Payment information") + "</b><br>"; | ||||
html += "<b>" + tr("URI") + "</b>: "; | html += "<b>" + tr("URI") + "</b>: "; | ||||
html += "<a href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a><br>"; | html += "<a href=\"" + uri + "\">" + GUIUtil::HtmlEscape(uri) + "</a><br>"; | ||||
html += "<b>" + tr("Address") + | html += "<b>" + tr("Address") + | ||||
"</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>"; | "</b>: " + GUIUtil::HtmlEscape(info.address) + "<br>"; | ||||
if (info.amount != Amount::zero()) | if (info.amount != Amount::zero()) { | ||||
html += "<b>" + tr("Amount") + "</b>: " + | html += "<b>" + tr("Amount") + "</b>: " + | ||||
BitcoinUnits::formatHtmlWithUnit( | BitcoinUnits::formatHtmlWithUnit( | ||||
model->getOptionsModel()->getDisplayUnit(), info.amount) + | model->getOptionsModel()->getDisplayUnit(), info.amount) + | ||||
"<br>"; | "<br>"; | ||||
if (!info.label.isEmpty()) | } | ||||
if (!info.label.isEmpty()) { | |||||
html += "<b>" + tr("Label") + | html += "<b>" + tr("Label") + | ||||
"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>"; | "</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>"; | ||||
if (!info.message.isEmpty()) | } | ||||
if (!info.message.isEmpty()) { | |||||
html += "<b>" + tr("Message") + | html += "<b>" + tr("Message") + | ||||
"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>"; | "</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>"; | ||||
} | |||||
if (model->isMultiwallet()) { | if (model->isMultiwallet()) { | ||||
html += "<b>" + tr("Wallet") + | html += "<b>" + tr("Wallet") + | ||||
"</b>: " + GUIUtil::HtmlEscape(model->getWalletName()) + "<br>"; | "</b>: " + GUIUtil::HtmlEscape(model->getWalletName()) + "<br>"; | ||||
} | } | ||||
ui->outUri->setText(html); | ui->outUri->setText(html); | ||||
#ifdef USE_QRCODE | #ifdef USE_QRCODE | ||||
int fontSize = config->UseCashAddrEncoding() ? 10 : 12; | int fontSize = config->UseCashAddrEncoding() ? 10 : 12; | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |