1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVERECT_H
43 #define QDECLARATIVERECT_H
45 #include "qdeclarativeitem.h"
47 #include <QtGui/qbrush.h>
49 #include <private/qdeclarativeglobal_p.h>
55 QT_MODULE(Declarative)
56 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativePen : public QObject
60 Q_PROPERTY(int width READ width WRITE setWidth NOTIFY penChanged)
61 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY penChanged)
63 QDeclarativePen(QObject *parent=0)
64 : QObject(parent), _width(1), _color("#000000"), _valid(false)
67 int width() const { return _width; }
70 QColor color() const { return _color; }
71 void setColor(const QColor &c);
73 bool isValid() { return _valid; }
84 class Q_AUTOTEST_EXPORT QDeclarativeGradientStop : public QObject
88 Q_PROPERTY(qreal position READ position WRITE setPosition)
89 Q_PROPERTY(QColor color READ color WRITE setColor)
92 QDeclarativeGradientStop(QObject *parent=0) : QObject(parent) {}
94 qreal position() const { return m_position; }
95 void setPosition(qreal position) { m_position = position; updateGradient(); }
97 QColor color() const { return m_color; }
98 void setColor(const QColor &color) { m_color = color; updateGradient(); }
101 void updateGradient();
108 class Q_AUTOTEST_EXPORT QDeclarativeGradient : public QObject
112 Q_PROPERTY(QDeclarativeListProperty<QDeclarativeGradientStop> stops READ stops)
113 Q_CLASSINFO("DefaultProperty", "stops")
116 QDeclarativeGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {}
117 ~QDeclarativeGradient() { delete m_gradient; }
119 QDeclarativeListProperty<QDeclarativeGradientStop> stops() { return QDeclarativeListProperty<QDeclarativeGradientStop>(this, m_stops); }
121 const QGradient *gradient() const;
130 QList<QDeclarativeGradientStop *> m_stops;
131 mutable QGradient *m_gradient;
132 friend class QDeclarativeGradientStop;
135 class QDeclarativeRectanglePrivate;
136 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeRectangle : public QDeclarativeItem
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)
145 QDeclarativeRectangle(QDeclarativeItem *parent=0);
147 QColor color() const;
148 void setColor(const QColor &);
150 QDeclarativePen *border();
152 QDeclarativeGradient *gradient() const;
153 void setGradient(QDeclarativeGradient *gradient);
155 qreal radius() const;
156 void setRadius(qreal radius);
158 QRectF boundingRect() const;
160 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
164 void radiusChanged();
170 void generateRoundedRect();
171 void generateBorderedRect();
172 void drawRect(QPainter &painter);
175 Q_DISABLE_COPY(QDeclarativeRectangle)
176 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeRectangle)
181 QML_DECLARE_TYPE(QDeclarativePen)
182 QML_DECLARE_TYPE(QDeclarativeGradientStop)
183 QML_DECLARE_TYPE(QDeclarativeGradient)
184 QML_DECLARE_TYPE(QDeclarativeRectangle)
188 #endif // QDECLARATIVERECT_H