qrimagewidget.h raw

   1  // Copyright (c) 2011-2020 The Limenka 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 LIMENKA_QT_QRIMAGEWIDGET_H
   6  #define LIMENKA_QT_QRIMAGEWIDGET_H
   7  
   8  #include <qt/optionsmodel.h>
   9  
  10  #include <QImage>
  11  #include <QLabel>
  12  
  13  /* Maximum allowed URI length */
  14  static const int MAX_URI_LENGTH = 255;
  15  
  16  /* Size of exported QR Code image */
  17  static constexpr int QR_IMAGE_SIZE = 252;
  18  static constexpr int QR_IMAGE_TEXT_MARGIN = 8;
  19  static constexpr int QR_IMAGE_MARGIN = 24;
  20  
  21  QT_BEGIN_NAMESPACE
  22  class QMenu;
  23  QT_END_NAMESPACE
  24  
  25  /* Label widget for QR code. This image can be dragged, dropped, copied and saved
  26   * to disk.
  27   */
  28  class QRImageWidget : public QLabel
  29  {
  30      Q_OBJECT
  31  
  32  public:
  33      explicit QRImageWidget(QWidget *parent = nullptr);
  34      bool setQR(const QString& data);
  35      bool setQR(const QString& data, const QString& text, const OptionsModel::FontChoice& fontchoice);
  36      QImage exportImage();
  37  
  38  public Q_SLOTS:
  39      void saveImage();
  40      void copyImage();
  41  
  42  protected:
  43      virtual void mousePressEvent(QMouseEvent *event) override;
  44      virtual void contextMenuEvent(QContextMenuEvent *event) override;
  45  
  46  private:
  47      QMenu* contextMenu{nullptr};
  48  };
  49  
  50  #endif // LIMENKA_QT_QRIMAGEWIDGET_H
  51