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
60QT_BEGIN_NAMESPACE
61
62class 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)
69public:
70 QQuickPen(QObject *parent=nullptr);
71
72 qreal width() const;
73 void setWidth(qreal w);
74
75 QColor color() const;
76 void setColor(const QColor &c);
77
78 bool pixelAligned() const;
79 void setPixelAligned(bool aligned);
80
81 bool isValid() const;
82
83Q_SIGNALS:
84 void penChanged();
85
86private:
87 qreal m_width;
88 QColor m_color;
89 bool m_aligned : 1;
90 bool m_valid : 1;
91};
92
93class Q_QUICK_PRIVATE_EXPORT QQuickGradientStop : public QObject
94{
95 Q_OBJECT
96
97 Q_PROPERTY(qreal position READ position WRITE setPosition)
98 Q_PROPERTY(QColor color READ color WRITE setColor)
99
100public:
101 QQuickGradientStop(QObject *parent=nullptr);
102
103 qreal position() const;
104 void setPosition(qreal position);
105
106 QColor color() const;
107 void setColor(const QColor &color);
108
109private:
110 void updateGradient();
111
112private:
113 qreal m_position;
114 QColor m_color;
115};
116
117class Q_QUICK_PRIVATE_EXPORT QQuickGradient : public QObject
118{
119 Q_OBJECT
120
121 Q_PROPERTY(QQmlListProperty<QQuickGradientStop> stops READ stops)
122 Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged REVISION 12)
123 Q_CLASSINFO("DefaultProperty", "stops")
124
125 Q_ENUMS(QGradient::Preset)
126public:
127 QQuickGradient(QObject *parent=nullptr);
128 ~QQuickGradient() override;
129
130 enum Orientation { Vertical = Qt::Vertical,
131 Horizontal = Qt::Horizontal };
132 Q_ENUM(Orientation)
133
134 QQmlListProperty<QQuickGradientStop> stops();
135
136 Orientation orientation() const { return m_orientation; }
137 void setOrientation(Orientation orientation);
138
139 QGradientStops gradientStops() const;
140
141Q_SIGNALS:
142 void updated();
143 void orientationChanged();
144
145private:
146 void doUpdate();
147
148private:
149 QList<QQuickGradientStop *> m_stops;
150 Orientation m_orientation = Vertical;
151 friend class QQuickRectangle;
152 friend class QQuickGradientStop;
153};
154
155class QQuickRectanglePrivate;
156class Q_QUICK_PRIVATE_EXPORT QQuickRectangle : public QQuickItem
157{
158 Q_OBJECT
159
160 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
161 Q_PROPERTY(QJSValue gradient READ gradient WRITE setGradient RESET resetGradient)
162 Q_PROPERTY(QQuickPen * border READ border CONSTANT)
163 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
164public:
165 QQuickRectangle(QQuickItem *parent=nullptr);
166
167 QColor color() const;
168 void setColor(const QColor &);
169
170 QQuickPen *border();
171
172 QJSValue gradient() const;
173 void setGradient(const QJSValue &gradient);
174 void resetGradient();
175
176 qreal radius() const;
177 void setRadius(qreal radius);
178
179Q_SIGNALS:
180 void colorChanged();
181 void radiusChanged();
182
183protected:
184 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
185
186private Q_SLOTS:
187 void doUpdate();
188
189private:
190 Q_DISABLE_COPY(QQuickRectangle)
191 Q_DECLARE_PRIVATE(QQuickRectangle)
192};
193
194QT_END_NAMESPACE
195
196QML_DECLARE_TYPE(QQuickPen)
197QML_DECLARE_TYPE(QQuickGradientStop)
198QML_DECLARE_TYPE(QQuickGradient)
199QML_DECLARE_TYPE(QQuickRectangle)
200
201#endif // QQUICKRECTANGLE_P_H
202