File indexing completed on 2024-05-12 05:38:57
0001 /* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com> 0002 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 */ 0004 0005 #ifndef PAINTEDSYMBOLITEM_H 0006 #define PAINTEDSYMBOLITEM_H 0007 0008 #include <QtQuick> 0009 0010 #include <climits> 0011 0012 class PaintedSymbolItemPrivate; 0013 0014 /** 0015 * This class is mainly intended for drawing symbols that are difficult to make 0016 * with QQuickRectangle or that don't look right with QQuickRectangle. 0017 * 0018 * This should be used instead of the Qt Quick Shapes API because 0019 * Qt Quick Shapes can't use good antialiasing. You can use MSAA (expensive) on 0020 * Qt Quick Shapes via the `layer.samples` property, but it's very prone to 0021 * distortion when you change the dimentions of the symbol and distortion issues 0022 * can be difficult to reliably reproduce. 0023 */ 0024 class PaintedSymbolItem : public QQuickPaintedItem 0025 { 0026 Q_OBJECT 0027 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) 0028 // Should be used when setting the size of this element 0029 Q_PROPERTY(qreal penWidth READ penWidth NOTIFY penWidthChanged) 0030 Q_PROPERTY(SymbolType symbolType READ symbolType WRITE setSymbolType NOTIFY symbolTypeChanged) 0031 QML_NAMED_ELEMENT(PaintedSymbol) 0032 0033 public: 0034 enum SymbolType { 0035 Checkmark, 0036 LeftArrow, 0037 RightArrow, 0038 UpArrow, 0039 DownArrow, 0040 NSymbolTypes, // Only used to access the total number of symbol types 0041 None = USHRT_MAX, 0042 }; 0043 Q_ENUM(SymbolType) 0044 0045 explicit PaintedSymbolItem(QQuickItem *parent = nullptr); 0046 ~PaintedSymbolItem(); 0047 0048 void paint(QPainter *painter) override; 0049 0050 QColor color() const; 0051 void setColor(const QColor &color); 0052 0053 qreal penWidth() const; 0054 void setPenWidth(const qreal penWidth); 0055 0056 SymbolType symbolType() const; 0057 void setSymbolType(const SymbolType symbolType); 0058 0059 Q_SIGNALS: 0060 void colorChanged(); 0061 void penWidthChanged(); 0062 void symbolTypeChanged(); 0063 0064 private: 0065 const QScopedPointer<PaintedSymbolItemPrivate> d_ptr; 0066 Q_DECLARE_PRIVATE(PaintedSymbolItem) 0067 Q_DISABLE_COPY(PaintedSymbolItem) 0068 }; 0069 0070 #endif