1 /****************************************************************************
3 ** Copyright (C) 2012 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 ** 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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVERECT_H
43 #define QDECLARATIVERECT_H
45 #include "qdeclarativeitem.h"
47 #include <QtGui/qbrush.h>
49 #include <QtDeclarative/private/qdeclarativeglobal_p.h>
55 QT_MODULE(Declarative)
56 class Q_QTQUICK1_EXPORT QDeclarative1Pen : 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 QDeclarative1Pen(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 QDeclarative1GradientStop : public QObject
88 Q_PROPERTY(qreal position READ position WRITE setPosition)
89 Q_PROPERTY(QColor color READ color WRITE setColor)
92 QDeclarative1GradientStop(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 QDeclarative1Gradient : public QObject
112 Q_PROPERTY(QDeclarativeListProperty<QDeclarative1GradientStop> stops READ stops)
113 Q_CLASSINFO("DefaultProperty", "stops")
116 QDeclarative1Gradient(QObject *parent=0) : QObject(parent), m_gradient(0) {}
117 ~QDeclarative1Gradient() { delete m_gradient; }
119 QDeclarativeListProperty<QDeclarative1GradientStop> stops() { return QDeclarativeListProperty<QDeclarative1GradientStop>(this, m_stops); }
121 const QGradient *gradient() const;
130 QList<QDeclarative1GradientStop *> m_stops;
131 mutable QGradient *m_gradient;
132 friend class QDeclarative1GradientStop;
135 class QDeclarative1RectanglePrivate;
136 class Q_QTQUICK1_EXPORT QDeclarative1Rectangle : public QDeclarativeItem
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)
145 QDeclarative1Rectangle(QDeclarativeItem *parent=0);
147 QColor color() const;
148 void setColor(const QColor &);
150 QDeclarative1Pen *border();
152 QDeclarative1Gradient *gradient() const;
153 void setGradient(QDeclarative1Gradient *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(QDeclarative1Rectangle)
176 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarative1Rectangle)
181 QML_DECLARE_TYPE(QDeclarative1Pen)
182 QML_DECLARE_TYPE(QDeclarative1GradientStop)
183 QML_DECLARE_TYPE(QDeclarative1Gradient)
184 QML_DECLARE_TYPE(QDeclarative1Rectangle)
188 #endif // QDECLARATIVERECT_H