| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QQUICKRECTANGLE_P_H |
| 41 | #define QQUICKRECTANGLE_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include "qquickitem.h" |
| 55 | |
| 56 | #include <QtGui/qbrush.h> |
| 57 | |
| 58 | #include <private/qtquickglobal_p.h> |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | class Q_QUICK_PRIVATE_EXPORT QQuickPen : public QObject |
| 63 | { |
| 64 | Q_OBJECT |
| 65 | |
| 66 | Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY penChanged) |
| 67 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged) |
| 68 | Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY penChanged) |
| 69 | QML_ANONYMOUS |
| 70 | public: |
| 71 | QQuickPen(QObject *parent=nullptr); |
| 72 | |
| 73 | qreal width() const; |
| 74 | void setWidth(qreal w); |
| 75 | |
| 76 | QColor color() const; |
| 77 | void setColor(const QColor &c); |
| 78 | |
| 79 | bool pixelAligned() const; |
| 80 | void setPixelAligned(bool aligned); |
| 81 | |
| 82 | bool isValid() const; |
| 83 | |
| 84 | Q_SIGNALS: |
| 85 | void penChanged(); |
| 86 | |
| 87 | private: |
| 88 | qreal m_width; |
| 89 | QColor m_color; |
| 90 | bool m_aligned : 1; |
| 91 | bool m_valid : 1; |
| 92 | }; |
| 93 | |
| 94 | class Q_QUICK_PRIVATE_EXPORT QQuickGradientStop : public QObject |
| 95 | { |
| 96 | Q_OBJECT |
| 97 | |
| 98 | Q_PROPERTY(qreal position READ position WRITE setPosition) |
| 99 | Q_PROPERTY(QColor color READ color WRITE setColor) |
| 100 | QML_NAMED_ELEMENT(GradientStop) |
| 101 | |
| 102 | public: |
| 103 | QQuickGradientStop(QObject *parent=nullptr); |
| 104 | |
| 105 | qreal position() const; |
| 106 | void setPosition(qreal position); |
| 107 | |
| 108 | QColor color() const; |
| 109 | void setColor(const QColor &color); |
| 110 | |
| 111 | private: |
| 112 | void updateGradient(); |
| 113 | |
| 114 | private: |
| 115 | qreal m_position; |
| 116 | QColor m_color; |
| 117 | }; |
| 118 | |
| 119 | class Q_QUICK_PRIVATE_EXPORT QQuickGradient : public QObject |
| 120 | { |
| 121 | Q_OBJECT |
| 122 | |
| 123 | Q_PROPERTY(QQmlListProperty<QQuickGradientStop> stops READ stops) |
| 124 | Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged REVISION 12) |
| 125 | Q_CLASSINFO("DefaultProperty" , "stops" ) |
| 126 | QML_NAMED_ELEMENT(Gradient) |
| 127 | |
| 128 | Q_ENUMS(QGradient::Preset) |
| 129 | public: |
| 130 | QQuickGradient(QObject *parent=nullptr); |
| 131 | ~QQuickGradient() override; |
| 132 | |
| 133 | enum Orientation { Vertical = Qt::Vertical, |
| 134 | Horizontal = Qt::Horizontal }; |
| 135 | Q_ENUM(Orientation) |
| 136 | |
| 137 | QQmlListProperty<QQuickGradientStop> stops(); |
| 138 | |
| 139 | Orientation orientation() const { return m_orientation; } |
| 140 | void setOrientation(Orientation orientation); |
| 141 | |
| 142 | QGradientStops gradientStops() const; |
| 143 | |
| 144 | Q_SIGNALS: |
| 145 | void updated(); |
| 146 | void orientationChanged(); |
| 147 | |
| 148 | private: |
| 149 | void doUpdate(); |
| 150 | |
| 151 | private: |
| 152 | QList<QQuickGradientStop *> m_stops; |
| 153 | Orientation m_orientation = Vertical; |
| 154 | friend class QQuickRectangle; |
| 155 | friend class QQuickGradientStop; |
| 156 | }; |
| 157 | |
| 158 | class QQuickRectanglePrivate; |
| 159 | class Q_QUICK_PRIVATE_EXPORT QQuickRectangle : public QQuickItem |
| 160 | { |
| 161 | Q_OBJECT |
| 162 | |
| 163 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
| 164 | Q_PROPERTY(QJSValue gradient READ gradient WRITE setGradient RESET resetGradient) |
| 165 | Q_PROPERTY(QQuickPen * border READ border CONSTANT) |
| 166 | Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) |
| 167 | QML_NAMED_ELEMENT(Rectangle) |
| 168 | public: |
| 169 | QQuickRectangle(QQuickItem *parent=nullptr); |
| 170 | |
| 171 | QColor color() const; |
| 172 | void setColor(const QColor &); |
| 173 | |
| 174 | QQuickPen *border(); |
| 175 | |
| 176 | QJSValue gradient() const; |
| 177 | void setGradient(const QJSValue &gradient); |
| 178 | void resetGradient(); |
| 179 | |
| 180 | qreal radius() const; |
| 181 | void setRadius(qreal radius); |
| 182 | |
| 183 | Q_SIGNALS: |
| 184 | void colorChanged(); |
| 185 | void radiusChanged(); |
| 186 | |
| 187 | protected: |
| 188 | QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; |
| 189 | |
| 190 | private Q_SLOTS: |
| 191 | void doUpdate(); |
| 192 | |
| 193 | private: |
| 194 | Q_DISABLE_COPY(QQuickRectangle) |
| 195 | Q_DECLARE_PRIVATE(QQuickRectangle) |
| 196 | }; |
| 197 | |
| 198 | QT_END_NAMESPACE |
| 199 | |
| 200 | QML_DECLARE_TYPE(QQuickPen) |
| 201 | QML_DECLARE_TYPE(QQuickGradientStop) |
| 202 | QML_DECLARE_TYPE(QQuickGradient) |
| 203 | QML_DECLARE_TYPE(QQuickRectangle) |
| 204 | |
| 205 | #endif // QQUICKRECTANGLE_P_H |
| 206 | |