16
16
#include < QMimeData>
17
17
#include < QMouseEvent>
18
18
#include < QPixmap>
19
+ #include < QMenu>
19
20
#if QT_VERSION < 0x050000
20
21
#include < QUrl>
21
22
#endif
29
30
#endif
30
31
31
32
QRImageWidget::QRImageWidget (QWidget *parent):
32
- QLabel(parent)
33
+ QLabel(parent), contextMenu( 0 )
33
34
{
34
- setContextMenuPolicy (Qt::ActionsContextMenu);
35
-
35
+ contextMenu = new QMenu ();
36
36
QAction *saveImageAction = new QAction (tr (" &Save Image..." ), this );
37
37
connect (saveImageAction, SIGNAL (triggered ()), this , SLOT (saveImage ()));
38
- addAction (saveImageAction);
38
+ contextMenu-> addAction (saveImageAction);
39
39
QAction *copyImageAction = new QAction (tr (" &Copy Image" ), this );
40
40
connect (copyImageAction, SIGNAL (triggered ()), this , SLOT (copyImage ()));
41
- addAction (copyImageAction);
41
+ contextMenu-> addAction (copyImageAction);
42
42
}
43
43
44
44
QImage QRImageWidget::exportImage ()
45
45
{
46
+ if (!pixmap ())
47
+ return QImage ();
46
48
return pixmap ()->toImage ().scaled (EXPORT_IMAGE_SIZE, EXPORT_IMAGE_SIZE);
47
49
}
48
50
49
51
void QRImageWidget::mousePressEvent (QMouseEvent *event)
50
52
{
51
- if (event->button () == Qt::LeftButton)
53
+ if (event->button () == Qt::LeftButton && pixmap () )
52
54
{
53
55
event->accept ();
54
56
QMimeData *mimeData = new QMimeData;
@@ -64,6 +66,8 @@ void QRImageWidget::mousePressEvent(QMouseEvent *event)
64
66
65
67
void QRImageWidget::saveImage ()
66
68
{
69
+ if (!pixmap ())
70
+ return ;
67
71
QString fn = GUIUtil::getSaveFileName (this , tr (" Save QR Code" ), QString (), tr (" PNG Image (*.png)" ), NULL );
68
72
if (!fn.isEmpty ())
69
73
{
@@ -73,9 +77,18 @@ void QRImageWidget::saveImage()
73
77
74
78
void QRImageWidget::copyImage ()
75
79
{
80
+ if (!pixmap ())
81
+ return ;
76
82
QApplication::clipboard ()->setImage (exportImage ());
77
83
}
78
84
85
+ void QRImageWidget::contextMenuEvent (QContextMenuEvent *event)
86
+ {
87
+ if (!pixmap ())
88
+ return ;
89
+ contextMenu->exec (event->globalPos ());
90
+ }
91
+
79
92
ReceiveRequestDialog::ReceiveRequestDialog (QWidget *parent) :
80
93
QDialog(parent),
81
94
ui(new Ui::ReceiveRequestDialog),
0 commit comments