qrimagewidget.h raw
1 // Copyright (c) 2011-present The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_QT_QRIMAGEWIDGET_H
6 #define BITCOIN_QT_QRIMAGEWIDGET_H
7
8 #include <QImage>
9 #include <QLabel>
10
11 /* Maximum allowed URI length */
12 static const int MAX_URI_LENGTH = 255;
13
14 /* Size of exported QR Code image */
15 static constexpr int QR_IMAGE_SIZE = 300;
16 static constexpr int QR_IMAGE_TEXT_MARGIN = 10;
17 static constexpr int QR_IMAGE_MARGIN = 2 * QR_IMAGE_TEXT_MARGIN;
18
19 QT_BEGIN_NAMESPACE
20 class QMenu;
21 QT_END_NAMESPACE
22
23 /* Label widget for QR code. This image can be dragged, dropped, copied and saved
24 * to disk.
25 */
26 class QRImageWidget : public QLabel
27 {
28 Q_OBJECT
29
30 public:
31 explicit QRImageWidget(QWidget *parent = nullptr);
32 bool setQR(const QString& data, const QString& text = "");
33 QImage exportImage();
34
35 public Q_SLOTS:
36 void saveImage();
37 void copyImage();
38
39 protected:
40 virtual void mousePressEvent(QMouseEvent *event) override;
41 virtual void contextMenuEvent(QContextMenuEvent *event) override;
42
43 private:
44 QMenu* contextMenu{nullptr};
45 };
46
47 #endif // BITCOIN_QT_QRIMAGEWIDGET_H
48