| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKRECTANGLE_P_H |
| 5 | #define QQUICKRECTANGLE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qquickitem.h" |
| 19 | |
| 20 | #include <QtGui/qbrush.h> |
| 21 | |
| 22 | #include <private/qtquickglobal_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class Q_QUICK_EXPORT QQuickPen : public QObject |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | |
| 30 | Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL) |
| 31 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged FINAL) |
| 32 | Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged FINAL) |
| 33 | QML_ANONYMOUS |
| 34 | QML_ADDED_IN_VERSION(2, 0) |
| 35 | public: |
| 36 | QQuickPen(QObject *parent=nullptr); |
| 37 | |
| 38 | qreal width() const; |
| 39 | void setWidth(qreal w); |
| 40 | |
| 41 | QColor color() const; |
| 42 | void setColor(const QColor &c); |
| 43 | |
| 44 | bool pixelAligned() const; |
| 45 | void setPixelAligned(bool aligned); |
| 46 | |
| 47 | bool isValid() const; |
| 48 | |
| 49 | Q_SIGNALS: |
| 50 | void widthChanged(); |
| 51 | void colorChanged(); |
| 52 | void pixelAlignedChanged(); |
| 53 | |
| 54 | private: |
| 55 | qreal m_width; |
| 56 | QColor m_color; |
| 57 | bool m_aligned : 1; |
| 58 | bool m_valid : 1; |
| 59 | }; |
| 60 | |
| 61 | class Q_QUICK_EXPORT QQuickGradientStop : public QObject |
| 62 | { |
| 63 | Q_OBJECT |
| 64 | |
| 65 | Q_PROPERTY(qreal position READ position WRITE setPosition) |
| 66 | Q_PROPERTY(QColor color READ color WRITE setColor) |
| 67 | QML_NAMED_ELEMENT(GradientStop) |
| 68 | QML_ADDED_IN_VERSION(2, 0) |
| 69 | |
| 70 | public: |
| 71 | QQuickGradientStop(QObject *parent=nullptr); |
| 72 | |
| 73 | qreal position() const; |
| 74 | void setPosition(qreal position); |
| 75 | |
| 76 | QColor color() const; |
| 77 | void setColor(const QColor &color); |
| 78 | |
| 79 | private: |
| 80 | void updateGradient(); |
| 81 | |
| 82 | private: |
| 83 | qreal m_position; |
| 84 | QColor m_color; |
| 85 | }; |
| 86 | |
| 87 | class Q_QUICK_EXPORT QQuickGradient : public QObject |
| 88 | { |
| 89 | Q_OBJECT |
| 90 | |
| 91 | Q_PROPERTY(QQmlListProperty<QQuickGradientStop> stops READ stops) |
| 92 | Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged REVISION(2, 12)) |
| 93 | Q_CLASSINFO("DefaultProperty" , "stops" ) |
| 94 | QML_NAMED_ELEMENT(Gradient) |
| 95 | QML_ADDED_IN_VERSION(2, 0) |
| 96 | QML_EXTENDED_NAMESPACE(QGradient) |
| 97 | |
| 98 | public: |
| 99 | QQuickGradient(QObject *parent=nullptr); |
| 100 | ~QQuickGradient() override; |
| 101 | |
| 102 | enum Orientation { Vertical = Qt::Vertical, |
| 103 | Horizontal = Qt::Horizontal }; |
| 104 | Q_ENUM(Orientation) |
| 105 | |
| 106 | QQmlListProperty<QQuickGradientStop> stops(); |
| 107 | |
| 108 | Orientation orientation() const { return m_orientation; } |
| 109 | void setOrientation(Orientation orientation); |
| 110 | |
| 111 | QGradientStops gradientStops() const; |
| 112 | |
| 113 | Q_SIGNALS: |
| 114 | void updated(); |
| 115 | void orientationChanged(); |
| 116 | |
| 117 | private: |
| 118 | void doUpdate(); |
| 119 | |
| 120 | private: |
| 121 | QList<QQuickGradientStop *> m_stops; |
| 122 | Orientation m_orientation = Vertical; |
| 123 | friend class QQuickRectangle; |
| 124 | friend class QQuickGradientStop; |
| 125 | }; |
| 126 | |
| 127 | class QQuickRectanglePrivate; |
| 128 | class Q_QUICK_EXPORT QQuickRectangle : public QQuickItem |
| 129 | { |
| 130 | Q_OBJECT |
| 131 | |
| 132 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
| 133 | Q_PROPERTY(QJSValue gradient READ gradient WRITE setGradient RESET resetGradient) |
| 134 | Q_PROPERTY(QQuickPen * border READ border CONSTANT) |
| 135 | Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) |
| 136 | Q_PROPERTY(qreal topLeftRadius READ topLeftRadius WRITE setTopLeftRadius NOTIFY topLeftRadiusChanged RESET resetTopLeftRadius REVISION(6, 7) FINAL) |
| 137 | Q_PROPERTY(qreal topRightRadius READ topRightRadius WRITE setTopRightRadius NOTIFY topRightRadiusChanged RESET resetTopRightRadius REVISION(6, 7) FINAL) |
| 138 | Q_PROPERTY(qreal bottomLeftRadius READ bottomLeftRadius WRITE setBottomLeftRadius NOTIFY bottomLeftRadiusChanged RESET resetBottomLeftRadius REVISION(6, 7) FINAL) |
| 139 | Q_PROPERTY(qreal bottomRightRadius READ bottomRightRadius WRITE setBottomRightRadius NOTIFY bottomRightRadiusChanged RESET resetBottomRightRadius REVISION(6, 7) FINAL) |
| 140 | QML_NAMED_ELEMENT(Rectangle) |
| 141 | QML_ADDED_IN_VERSION(2, 0) |
| 142 | public: |
| 143 | QQuickRectangle(QQuickItem *parent=nullptr); |
| 144 | |
| 145 | QColor color() const; |
| 146 | void setColor(const QColor &); |
| 147 | |
| 148 | QQuickPen *border(); |
| 149 | |
| 150 | QJSValue gradient() const; |
| 151 | void setGradient(const QJSValue &gradient); |
| 152 | void resetGradient(); |
| 153 | |
| 154 | qreal radius() const; |
| 155 | void setRadius(qreal radius); |
| 156 | |
| 157 | qreal topLeftRadius() const; |
| 158 | void setTopLeftRadius(qreal radius); |
| 159 | void resetTopLeftRadius(); |
| 160 | qreal topRightRadius() const; |
| 161 | void setTopRightRadius(qreal radius); |
| 162 | void resetTopRightRadius(); |
| 163 | qreal bottomLeftRadius() const; |
| 164 | void setBottomLeftRadius(qreal radius); |
| 165 | void resetBottomLeftRadius(); |
| 166 | qreal bottomRightRadius() const; |
| 167 | void setBottomRightRadius(qreal radius); |
| 168 | void resetBottomRightRadius(); |
| 169 | |
| 170 | Q_SIGNALS: |
| 171 | void colorChanged(); |
| 172 | void radiusChanged(); |
| 173 | Q_REVISION(6, 7) void topLeftRadiusChanged(); |
| 174 | Q_REVISION(6, 7) void topRightRadiusChanged(); |
| 175 | Q_REVISION(6, 7) void bottomLeftRadiusChanged(); |
| 176 | Q_REVISION(6, 7) void bottomRightRadiusChanged(); |
| 177 | |
| 178 | protected: |
| 179 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 180 | |
| 181 | private Q_SLOTS: |
| 182 | void doUpdate(); |
| 183 | |
| 184 | private: |
| 185 | Q_DISABLE_COPY(QQuickRectangle) |
| 186 | Q_DECLARE_PRIVATE(QQuickRectangle) |
| 187 | }; |
| 188 | |
| 189 | QT_END_NAMESPACE |
| 190 | |
| 191 | #endif // QQUICKRECTANGLE_P_H |
| 192 | |