aboutsummaryrefslogtreecommitdiff
path: root/src/qt/receiverequestdialog.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2013-10-18 13:08:30 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2013-10-23 09:15:25 +0200
commit82095923bb71a670aa67ad15987bb6d4d7726abe (patch)
tree1bd9b4747659277bb365d8d56008fbed9ead0945 /src/qt/receiverequestdialog.cpp
parent864a6f790ee80a4acc56189cdc1897c9a3ed6998 (diff)
qt: allow dragging, copying and saving QR code
Add context menu and drag handling to QR code widget.
Diffstat (limited to 'src/qt/receiverequestdialog.cpp')
-rw-r--r--src/qt/receiverequestdialog.cpp59
1 files changed, 49 insertions, 10 deletions
diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp
index b40cda9b32..dd4f5f16f4 100644
--- a/src/qt/receiverequestdialog.cpp
+++ b/src/qt/receiverequestdialog.cpp
@@ -7,6 +7,7 @@
#include "optionsmodel.h"
#include <QPixmap>
+#include <QClipboard>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif
@@ -17,6 +18,51 @@
#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)
+ {
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setImageData(exportImage());
+
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->exec();
+ }
+}
+
+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(const QString &addr, const QString &label, quint64 amount, const QString &message, QWidget *parent) :
QDialog(parent),
ui(new Ui::ReceiveRequestDialog),
@@ -42,6 +88,8 @@ ReceiveRequestDialog::ReceiveRequestDialog(const QString &addr, const QString &l
ui->lblQRCode->setVisible(false);
#endif
+ connect(ui->btnSaveAs, SIGNAL(clicked()), ui->lblQRCode, SLOT(saveImage()));
+
genCode();
}
@@ -77,7 +125,7 @@ void ReceiveRequestDialog::genCode()
ui->lblQRCode->setText(tr("Error encoding URI into QR Code."));
return;
}
- myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
+ 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++)
@@ -147,15 +195,6 @@ void ReceiveRequestDialog::on_lnMessage_textChanged()
genCode();
}
-void ReceiveRequestDialog::on_btnSaveAs_clicked()
-{
-#ifdef USE_QRCODE
- 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);
-#endif
-}
-
void ReceiveRequestDialog::updateDisplayUnit()
{
if (model)