File indexing completed on 2024-05-12 04:01:32
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef PRISON_BARCODEQUICKITEM_H 0008 #define PRISON_BARCODEQUICKITEM_H 0009 0010 #include <Prison/Barcode> 0011 0012 #include <QColor> 0013 #include <QQuickPaintedItem> 0014 0015 #include <qqmlregistration.h> 0016 0017 namespace Prison 0018 { 0019 0020 class BarcodeQuickItem : public QQuickPaintedItem 0021 { 0022 Q_OBJECT 0023 QML_ELEMENT 0024 QML_NAMED_ELEMENT(Barcode) 0025 Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged) 0026 Q_PROPERTY(QJSValue barcodeType READ barcodeType WRITE setBarcodeType NOTIFY barcodeTypeChanged) 0027 Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor NOTIFY foregroundColorChanged) 0028 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) 0029 Q_PROPERTY(Dimensions dimensions READ dimensions NOTIFY dimensionsChanged) 0030 /** 0031 * @see Prison::Barcode::minimumSize() 0032 * @since 5.69 0033 */ 0034 Q_PROPERTY(qreal minimumHeight READ minimumHeight NOTIFY implicitHeightChanged) 0035 /** 0036 * @see Prison::Barcode::minimumSize() 0037 * @since 5.69 0038 */ 0039 Q_PROPERTY(qreal minimumWidth READ minimumWidth NOTIFY implicitWidthChanged) 0040 0041 public: 0042 enum BarcodeType { 0043 QRCode = Prison::QRCode, 0044 DataMatrix = Prison::DataMatrix, 0045 Aztec = Prison::Aztec, 0046 Code39 = Prison::Code39, 0047 Code93 = Prison::Code93, 0048 Code128 = Prison::Code128, 0049 PDF417 = Prison::PDF417, 0050 EAN13 = Prison::EAN13, 0051 }; 0052 Q_ENUM(BarcodeType) 0053 explicit BarcodeQuickItem(QQuickItem *parent = nullptr); 0054 ~BarcodeQuickItem() override; 0055 0056 QVariant content() const; 0057 void setContent(const QVariant &data); 0058 0059 QJSValue barcodeType() const; 0060 void setBarcodeType(const QJSValue &type); 0061 0062 QColor foregroundColor() const; 0063 void setForegroundColor(const QColor &color); 0064 QColor backgroundColor() const; 0065 void setBackgroundColor(const QColor &color); 0066 0067 enum Dimensions { 0068 NoDimensions, 0069 OneDimension, 0070 TwoDimensions, 0071 }; 0072 Q_ENUM(Dimensions) 0073 Dimensions dimensions() const; 0074 0075 void paint(QPainter *painter) override; 0076 void componentComplete() override; 0077 0078 qreal minimumHeight() const; 0079 qreal minimumWidth() const; 0080 0081 Q_SIGNALS: 0082 void contentChanged(); 0083 void barcodeTypeChanged(); 0084 void foregroundColorChanged(); 0085 void backgroundColorChanged(); 0086 void dimensionsChanged(); 0087 0088 private: 0089 bool isEmpty() const; 0090 void updateBarcode(); 0091 0092 QVariant m_content; 0093 std::optional<Barcode> m_barcode; 0094 QColor m_fgColor = Qt::black; 0095 QColor m_bgColor = Qt::white; 0096 std::optional<Prison::BarcodeType> m_type; 0097 }; 0098 0099 } 0100 0101 #endif // PRISON_BARCODEQUICKITEM_H