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
24QT_BEGIN_NAMESPACE
25
26class Q_QUICK_PRIVATE_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)
35public:
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
49Q_SIGNALS:
50 void widthChanged();
51 void colorChanged();
52 void pixelAlignedChanged();
53
54private:
55 qreal m_width;
56 QColor m_color;
57 bool m_aligned : 1;
58 bool m_valid : 1;
59};
60
61class Q_QUICK_PRIVATE_EXPORT QQuickGradientStop : public QObject
62{
63 Q_OBJECT
64
65 Q_PROPERTY(qreal position READ position WRITE setPosition FINAL)
66 Q_PROPERTY(QColor color READ color WRITE setColor FINAL)
67 QML_NAMED_ELEMENT(GradientStop)
68 QML_ADDED_IN_VERSION(2, 0)
69
70public:
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
79private:
80 void updateGradient();
81
82private:
83 qreal m_position;
84 QColor m_color;
85};
86
87class Q_QUICK_PRIVATE_EXPORT QQuickGradient : public QObject
88{
89 Q_OBJECT
90
91 Q_PROPERTY(QQmlListProperty<QQuickGradientStop> stops READ stops FINAL)
92 Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged REVISION(2, 12) FINAL)
93 Q_CLASSINFO("DefaultProperty", "stops")
94 QML_NAMED_ELEMENT(Gradient)
95 QML_ADDED_IN_VERSION(2, 0)
96 QML_EXTENDED_NAMESPACE(QGradient)
97
98public:
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
113Q_SIGNALS:
114 void updated();
115 void orientationChanged();
116
117private:
118 void doUpdate();
119
120private:
121 QList<QQuickGradientStop *> m_stops;
122 Orientation m_orientation = Vertical;
123 friend class QQuickRectangle;
124 friend class QQuickGradientStop;
125};
126
127class QQuickRectanglePrivate;
128class Q_QUICK_PRIVATE_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 FINAL)
134 Q_PROPERTY(QQuickPen * border READ border CONSTANT FINAL)
135 Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
136 QML_NAMED_ELEMENT(Rectangle)
137 QML_ADDED_IN_VERSION(2, 0)
138public:
139 QQuickRectangle(QQuickItem *parent=nullptr);
140
141 QColor color() const;
142 void setColor(const QColor &);
143
144 QQuickPen *border();
145
146 QJSValue gradient() const;
147 void setGradient(const QJSValue &gradient);
148 void resetGradient();
149
150 qreal radius() const;
151 void setRadius(qreal radius);
152
153Q_SIGNALS:
154 void colorChanged();
155 void radiusChanged();
156
157protected:
158 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
159
160private Q_SLOTS:
161 void doUpdate();
162
163private:
164 Q_DISABLE_COPY(QQuickRectangle)
165 Q_DECLARE_PRIVATE(QQuickRectangle)
166};
167
168QT_END_NAMESPACE
169
170QML_DECLARE_TYPE(QQuickPen)
171QML_DECLARE_TYPE(QQuickGradientStop)
172QML_DECLARE_TYPE(QQuickGradient)
173QML_DECLARE_TYPE(QQuickRectangle)
174
175#endif // QQUICKRECTANGLE_P_H
176

source code of qtdeclarative/src/quick/items/qquickrectangle_p.h