Initial import from qtquick2.
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgrectangle_p.h
1 // Commit: ac5c099cc3c5b8c7eec7a49fdeb8a21037230350
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
15 ** this package.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGRECTANGLE_P_H
44 #define QSGRECTANGLE_P_H
45
46 #include "qsgitem.h"
47
48 #include <QtGui/qbrush.h>
49
50 #include <private/qdeclarativeglobal_p.h>
51
52 QT_BEGIN_HEADER
53
54 QT_BEGIN_NAMESPACE
55
56 QT_MODULE(Declarative)
57 class Q_DECLARATIVE_PRIVATE_EXPORT QSGPen : public QObject
58 {
59     Q_OBJECT
60
61     Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged)
62     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged)
63 public:
64     QSGPen(QObject *parent=0);
65
66     int width() const;
67     void setWidth(int w);
68
69     QColor color() const;
70     void setColor(const QColor &c);
71
72     bool isValid() const;
73
74 Q_SIGNALS:
75     void penChanged();
76
77 private:
78     int _width;
79     QColor _color;
80     bool _valid;
81 };
82
83 class Q_AUTOTEST_EXPORT QSGGradientStop : public QObject
84 {
85     Q_OBJECT
86
87     Q_PROPERTY(qreal position READ position WRITE setPosition)
88     Q_PROPERTY(QColor color READ color WRITE setColor)
89
90 public:
91     QSGGradientStop(QObject *parent=0);
92
93     qreal position() const;
94     void setPosition(qreal position);
95
96     QColor color() const;
97     void setColor(const QColor &color);
98
99 private:
100     void updateGradient();
101
102 private:
103     qreal m_position;
104     QColor m_color;
105 };
106
107 class Q_AUTOTEST_EXPORT QSGGradient : public QObject
108 {
109     Q_OBJECT
110
111     Q_PROPERTY(QDeclarativeListProperty<QSGGradientStop> stops READ stops)
112     Q_CLASSINFO("DefaultProperty", "stops")
113
114 public:
115     QSGGradient(QObject *parent=0);
116     ~QSGGradient();
117
118     QDeclarativeListProperty<QSGGradientStop> stops();
119
120     const QGradient *gradient() const;
121
122 Q_SIGNALS:
123     void updated();
124
125 private:
126     void doUpdate();
127
128 private:
129     QList<QSGGradientStop *> m_stops;
130     mutable QGradient *m_gradient;
131     friend class QSGRectangle;
132     friend class QSGGradientStop;
133 };
134
135 class QSGRectanglePrivate;
136 class Q_DECLARATIVE_PRIVATE_EXPORT QSGRectangle : public QSGItem
137 {
138     Q_OBJECT
139
140     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
141     Q_PROPERTY(QSGGradient *gradient READ gradient WRITE setGradient)
142     Q_PROPERTY(QSGPen * border READ border CONSTANT)
143     Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
144 public:
145     QSGRectangle(QSGItem *parent=0);
146
147     QColor color() const;
148     void setColor(const QColor &);
149
150     QSGPen *border();
151
152     QSGGradient *gradient() const;
153     void setGradient(QSGGradient *gradient);
154
155     qreal radius() const;
156     void setRadius(qreal radius);
157
158     QRectF boundingRect() const;
159
160 Q_SIGNALS:
161     void colorChanged();
162     void radiusChanged();
163
164 protected:
165     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
166
167 private Q_SLOTS:
168     void doUpdate();
169
170 private:
171     Q_DISABLE_COPY(QSGRectangle)
172     Q_DECLARE_PRIVATE(QSGRectangle)
173 };
174
175 QT_END_NAMESPACE
176
177 QML_DECLARE_TYPE(QSGPen)
178 QML_DECLARE_TYPE(QSGGradientStop)
179 QML_DECLARE_TYPE(QSGGradient)
180 QML_DECLARE_TYPE(QSGRectangle)
181
182 QT_END_HEADER
183
184 #endif // QSGRECTANGLE_P_H