aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-08 10:31:32 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-08 10:32:14 +0200
commit69e264b6f80013595f6e7669947856b5432bdf6e (patch)
treedcefd06d4b116b013e0785b4935f9887814e3b4f
parent4629f95b22df9206198b61ef9670a9122c6a6e76 (diff)
parent9d558e1c18a29bbccec802829f9b8b65fb4101a1 (diff)
Merge pull request #4141
9d558e1 ui: Check for !pixmap() before trying to export QR code (Wladimir J. van der Laan)
-rw-r--r--src/qt/receiverequestdialog.cpp25
-rw-r--r--src/qt/receiverequestdialog.h7
2 files changed, 26 insertions, 6 deletions
diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp
index b5e45341d9..062638f2bc 100644
--- a/src/qt/receiverequestdialog.cpp
+++ b/src/qt/receiverequestdialog.cpp
@@ -16,6 +16,7 @@
#include <QMimeData>
#include <QMouseEvent>
#include <QPixmap>
+#include <QMenu>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif
@@ -29,26 +30,27 @@
#endif
QRImageWidget::QRImageWidget(QWidget *parent):
- QLabel(parent)
+ QLabel(parent), contextMenu(0)
{
- setContextMenuPolicy(Qt::ActionsContextMenu);
-
+ contextMenu = new QMenu();
QAction *saveImageAction = new QAction(tr("&Save Image..."), this);
connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage()));
- addAction(saveImageAction);
+ contextMenu->addAction(saveImageAction);
QAction *copyImageAction = new QAction(tr("&Copy Image"), this);
connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage()));
- addAction(copyImageAction);
+ contextMenu->addAction(copyImageAction);
}
QImage QRImageWidget::exportImage()
{
+ if(!pixmap())
+ return QImage();
return pixmap()->toImage().scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE);
}
void QRImageWidget::mousePressEvent(QMouseEvent *event)
{
- if(event->button() == Qt::LeftButton)
+ if(event->button() == Qt::LeftButton && pixmap())
{
event->accept();
QMimeData *mimeData = new QMimeData;
@@ -64,6 +66,8 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event)
void QRImageWidget::saveImage()
{
+ if(!pixmap())
+ return;
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), NULL);
if (!fn.isEmpty())
{
@@ -73,9 +77,18 @@ void QRImageWidget::saveImage()
void QRImageWidget::copyImage()
{
+ if(!pixmap())
+ return;
QApplication::clipboard()->setImage(exportImage());
}
+void QRImageWidget::contextMenuEvent(QContextMenuEvent *event)
+{
+ if(!pixmap())
+ return;
+ contextMenu->exec(event->globalPos());
+}
+
ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ReceiveRequestDialog),
diff --git a/src/qt/receiverequestdialog.h b/src/qt/receiverequestdialog.h
index 295a73031d..5614ac635a 100644
--- a/src/qt/receiverequestdialog.h
+++ b/src/qt/receiverequestdialog.h
@@ -15,6 +15,9 @@ namespace Ui {
class ReceiveRequestDialog;
}
class OptionsModel;
+QT_BEGIN_NAMESPACE
+class QMenu;
+QT_END_NAMESPACE
/* Label widget for QR code. This image can be dragged, dropped, copied and saved
* to disk.
@@ -33,6 +36,10 @@ public slots:
protected:
virtual void mousePressEvent(QMouseEvent *event);
+ virtual void contextMenuEvent(QContextMenuEvent *event);
+
+private:
+ QMenu *contextMenu;
};
class ReceiveRequestDialog : public QDialog