Skip to content

Commit 69e264b

Browse files
committed
Merge pull request #4141
9d558e1 ui: Check for !pixmap() before trying to export QR code (Wladimir J. van der Laan)
2 parents 4629f95 + 9d558e1 commit 69e264b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/qt/receiverequestdialog.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <QMimeData>
1717
#include <QMouseEvent>
1818
#include <QPixmap>
19+
#include <QMenu>
1920
#if QT_VERSION < 0x050000
2021
#include <QUrl>
2122
#endif
@@ -29,26 +30,27 @@
2930
#endif
3031

3132
QRImageWidget::QRImageWidget(QWidget *parent):
32-
QLabel(parent)
33+
QLabel(parent), contextMenu(0)
3334
{
34-
setContextMenuPolicy(Qt::ActionsContextMenu);
35-
35+
contextMenu = new QMenu();
3636
QAction *saveImageAction = new QAction(tr("&Save Image..."), this);
3737
connect(saveImageAction, SIGNAL(triggered()), this, SLOT(saveImage()));
38-
addAction(saveImageAction);
38+
contextMenu->addAction(saveImageAction);
3939
QAction *copyImageAction = new QAction(tr("&Copy Image"), this);
4040
connect(copyImageAction, SIGNAL(triggered()), this, SLOT(copyImage()));
41-
addAction(copyImageAction);
41+
contextMenu->addAction(copyImageAction);
4242
}
4343

4444
QImage QRImageWidget::exportImage()
4545
{
46+
if(!pixmap())
47+
return QImage();
4648
return pixmap()->toImage().scaled(EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE);
4749
}
4850

4951
void QRImageWidget::mousePressEvent(QMouseEvent *event)
5052
{
51-
if(event->button() == Qt::LeftButton)
53+
if(event->button() == Qt::LeftButton && pixmap())
5254
{
5355
event->accept();
5456
QMimeData *mimeData = new QMimeData;
@@ -64,6 +66,8 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event)
6466

6567
void QRImageWidget::saveImage()
6668
{
69+
if(!pixmap())
70+
return;
6771
QString fn = GUIUtil::getSaveFileName(this, tr("Save QR Code"), QString(), tr("PNG Image (*.png)"), NULL);
6872
if (!fn.isEmpty())
6973
{
@@ -73,9 +77,18 @@ void QRImageWidget::saveImage()
7377

7478
void QRImageWidget::copyImage()
7579
{
80+
if(!pixmap())
81+
return;
7682
QApplication::clipboard()->setImage(exportImage());
7783
}
7884

85+
void QRImageWidget::contextMenuEvent(QContextMenuEvent *event)
86+
{
87+
if(!pixmap())
88+
return;
89+
contextMenu->exec(event->globalPos());
90+
}
91+
7992
ReceiveRequestDialog::ReceiveRequestDialog(QWidget *parent) :
8093
QDialog(parent),
8194
ui(new Ui::ReceiveRequestDialog),

src/qt/receiverequestdialog.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace Ui {
1515
class ReceiveRequestDialog;
1616
}
1717
class OptionsModel;
18+
QT_BEGIN_NAMESPACE
19+
class QMenu;
20+
QT_END_NAMESPACE
1821

1922
/* Label widget for QR code. This image can be dragged, dropped, copied and saved
2023
* to disk.
@@ -33,6 +36,10 @@ public slots:
3336

3437
protected:
3538
virtual void mousePressEvent(QMouseEvent *event);
39+
virtual void contextMenuEvent(QContextMenuEvent *event);
40+
41+
private:
42+
QMenu *contextMenu;
3643
};
3744

3845
class ReceiveRequestDialog : public QDialog

0 commit comments

Comments
 (0)