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 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
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 <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 QDeclarativePen : 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 | QDeclarativePen(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 QDeclarativeGradientStop : 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 | QDeclarativeGradientStop(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 QDeclarativeGradient : public QObject
|
---|
109 | {
|
---|
110 | Q_OBJECT
|
---|
111 |
|
---|
112 | Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGradientStop> stops READ stops)
|
---|
113 | Q_CLASSINFO("DefaultProperty", "stops")
|
---|
114 |
|
---|
115 | public:
|
---|
116 | QDeclarativeGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {}
|
---|
117 | ~QDeclarativeGradient() { delete m_gradient; }
|
---|
118 |
|
---|
119 | QDeclarativeListProperty<QDeclarativeGradientStop> stops() { return QDeclarativeListProperty<QDeclarativeGradientStop>(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<QDeclarativeGradientStop *> m_stops;
|
---|
131 | mutable QGradient *m_gradient;
|
---|
132 | friend class QDeclarativeGradientStop;
|
---|
133 | };
|
---|
134 |
|
---|
135 | class QDeclarativeRectanglePrivate;
|
---|
136 | class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeRectangle : public QDeclarativeItem
|
---|
137 | {
|
---|
138 | Q_OBJECT
|
---|
139 |
|
---|
140 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
---|
141 | Q_PROPERTY(QDeclarativeGradient *gradient READ gradient WRITE setGradient)
|
---|
142 | Q_PROPERTY(QDeclarativePen * border READ border CONSTANT)
|
---|
143 | Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
|
---|
144 | public:
|
---|
145 | QDeclarativeRectangle(QDeclarativeItem *parent=0);
|
---|
146 |
|
---|
147 | QColor color() const;
|
---|
148 | void setColor(const QColor &);
|
---|
149 |
|
---|
150 | QDeclarativePen *border();
|
---|
151 |
|
---|
152 | QDeclarativeGradient *gradient() const;
|
---|
153 | void setGradient(QDeclarativeGradient *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(QDeclarativeRectangle)
|
---|
176 | Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeRectangle)
|
---|
177 | };
|
---|
178 |
|
---|
179 | QT_END_NAMESPACE
|
---|
180 |
|
---|
181 | QML_DECLARE_TYPE(QDeclarativePen)
|
---|
182 | QML_DECLARE_TYPE(QDeclarativeGradientStop)
|
---|
183 | QML_DECLARE_TYPE(QDeclarativeGradient)
|
---|
184 | QML_DECLARE_TYPE(QDeclarativeRectangle)
|
---|
185 |
|
---|
186 | QT_END_HEADER
|
---|
187 |
|
---|
188 | #endif // QDECLARATIVERECT_H
|
---|