Merge branch 'master' into refactor
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativerectangle_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVERECT_H
43 #define QDECLARATIVERECT_H
44
45 #include "qdeclarativeitem.h"
46
47 #include <QtGui/qbrush.h>
48
49 #include <QtDeclarative/private/qdeclarativeglobal_p.h>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 QT_MODULE(Declarative)
56 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1Pen : public QObject
57 {
58     Q_OBJECT
59
60     Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged)
61     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged)
62 public:
63     QDeclarative1Pen(QObject *parent=0)
64         : QObject(parent), _width(1), _color("#000000"), _valid(false)
65     {}
66
67     int width() const { return _width; }
68     void setWidth(int w);
69
70     QColor color() const { return _color; }
71     void setColor(const QColor &c);
72
73     bool isValid() { return _valid; }
74
75 Q_SIGNALS:
76     void penChanged();
77
78 private:
79     int _width;
80     QColor _color;
81     bool _valid;
82 };
83
84 class Q_AUTOTEST_EXPORT QDeclarative1GradientStop : public QObject
85 {
86     Q_OBJECT
87
88     Q_PROPERTY(qreal position READ position WRITE setPosition)
89     Q_PROPERTY(QColor color READ color WRITE setColor)
90
91 public:
92     QDeclarative1GradientStop(QObject *parent=0) : QObject(parent) {}
93
94     qreal position() const { return m_position; }
95     void setPosition(qreal position) { m_position = position; updateGradient(); }
96
97     QColor color() const { return m_color; }
98     void setColor(const QColor &color) { m_color = color; updateGradient(); }
99
100 private:
101     void updateGradient();
102
103 private:
104     qreal m_position;
105     QColor m_color;
106 };
107
108 class Q_AUTOTEST_EXPORT QDeclarative1Gradient : public QObject
109 {
110     Q_OBJECT
111
112     Q_PROPERTY(QDeclarativeListProperty<QDeclarative1GradientStop> stops READ stops)
113     Q_CLASSINFO("DefaultProperty", "stops")
114
115 public:
116     QDeclarative1Gradient(QObject *parent=0) : QObject(parent), m_gradient(0) {}
117     ~QDeclarative1Gradient() { delete m_gradient; }
118
119     QDeclarativeListProperty<QDeclarative1GradientStop> stops() { return QDeclarativeListProperty<QDeclarative1GradientStop>(this, m_stops); }
120
121     const QGradient *gradient() const;
122
123 Q_SIGNALS:
124     void updated();
125
126 private:
127     void doUpdate();
128
129 private:
130     QList<QDeclarative1GradientStop *> m_stops;
131     mutable QGradient *m_gradient;
132     friend class QDeclarative1GradientStop;
133 };
134
135 class QDeclarative1RectanglePrivate;
136 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarative1Rectangle : public QDeclarativeItem
137 {
138     Q_OBJECT
139
140     Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
141     Q_PROPERTY(QDeclarative1Gradient *gradient READ gradient WRITE setGradient)
142     Q_PROPERTY(QDeclarative1Pen * border READ border CONSTANT)
143     Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
144 public:
145     QDeclarative1Rectangle(QDeclarativeItem *parent=0);
146
147     QColor color() const;
148     void setColor(const QColor &);
149
150     QDeclarative1Pen *border();
151
152     QDeclarative1Gradient *gradient() const;
153     void setGradient(QDeclarative1Gradient *gradient);
154
155     qreal radius() const;
156     void setRadius(qreal radius);
157
158     QRectF boundingRect() const;
159
160     void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
161
162 Q_SIGNALS:
163     void colorChanged();
164     void radiusChanged();
165
166 private Q_SLOTS:
167     void doUpdate();
168
169 private:
170     void generateRoundedRect();
171     void generateBorderedRect();
172     void drawRect(QPainter &painter);
173
174 private:
175     Q_DISABLE_COPY(QDeclarative1Rectangle)
176     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Rectangle)
177 };
178
179 QT_END_NAMESPACE
180
181 QML_DECLARE_TYPE(QDeclarative1Pen)
182 QML_DECLARE_TYPE(QDeclarative1GradientStop)
183 QML_DECLARE_TYPE(QDeclarative1Gradient)
184 QML_DECLARE_TYPE(QDeclarative1Rectangle)
185
186 QT_END_HEADER
187
188 #endif // QDECLARATIVERECT_H