1
/****************************************************************************
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/
6
** This file is part of the QtQml module of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** GNU Lesser General Public License Usage
10
** This file may be used under the terms of the GNU Lesser General Public
11
** License version 2.1 as published by the Free Software Foundation and
12
** appearing in the file LICENSE.LGPL included in the packaging of this
13
** file. Please review the following information to ensure the GNU Lesser
14
** General Public License version 2.1 requirements will be met:
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
** In addition, as a special exception, Nokia gives you certain additional
18
** rights. These rights are described in the Nokia Qt LGPL Exception
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
** GNU General Public License Usage
22
** Alternatively, this file may be used under the terms of the GNU General
23
** Public License version 3.0 as published by the Free Software Foundation
24
** and appearing in the file LICENSE.GPL included in the packaging of this
25
** file. Please review the following information to ensure the GNU General
26
** Public License version 3.0 requirements will be met:
27
** http://www.gnu.org/copyleft/gpl.html.
30
** Alternatively, this file may be used in accordance with the terms and
31
** conditions contained in a signed written agreement between you and Nokia.
40
****************************************************************************/
47
#include <private/qqmlnullablevalue_p_p.h>
48
#include <private/qbezier_p.h>
50
#include <QtCore/QObject>
51
#include <QtGui/QPainterPath>
62
QList<QQuickCurve*> curves;
65
class Q_AUTOTEST_EXPORT QQuickPathElement : public QObject
69
QQuickPathElement(QObject *parent=0) : QObject(parent) {}
74
class Q_AUTOTEST_EXPORT QQuickPathAttribute : public QQuickPathElement
78
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
79
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
81
QQuickPathAttribute(QObject *parent=0) : QQuickPathElement(parent), _value(0) {}
85
void setName(const QString &name);
88
void setValue(qreal value);
99
class Q_AUTOTEST_EXPORT QQuickCurve : public QQuickPathElement
103
Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged)
104
Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged)
105
Q_PROPERTY(qreal relativeX READ relativeX WRITE setRelativeX NOTIFY relativeXChanged)
106
Q_PROPERTY(qreal relativeY READ relativeY WRITE setRelativeY NOTIFY relativeYChanged)
108
QQuickCurve(QObject *parent=0) : QQuickPathElement(parent) {}
118
qreal relativeX() const;
119
void setRelativeX(qreal x);
122
qreal relativeY() const;
123
void setRelativeY(qreal y);
126
virtual void addToPath(QPainterPath &, const QQuickPathData &) {}
131
void relativeXChanged();
132
void relativeYChanged();
135
QQmlNullableValue<qreal> _x;
136
QQmlNullableValue<qreal> _y;
137
QQmlNullableValue<qreal> _relativeX;
138
QQmlNullableValue<qreal> _relativeY;
141
class Q_AUTOTEST_EXPORT QQuickPathLine : public QQuickCurve
145
QQuickPathLine(QObject *parent=0) : QQuickCurve(parent) {}
147
void addToPath(QPainterPath &path, const QQuickPathData &);
150
class Q_AUTOTEST_EXPORT QQuickPathQuad : public QQuickCurve
154
Q_PROPERTY(qreal controlX READ controlX WRITE setControlX NOTIFY controlXChanged)
155
Q_PROPERTY(qreal controlY READ controlY WRITE setControlY NOTIFY controlYChanged)
156
Q_PROPERTY(qreal relativeControlX READ relativeControlX WRITE setRelativeControlX NOTIFY relativeControlXChanged)
157
Q_PROPERTY(qreal relativeControlY READ relativeControlY WRITE setRelativeControlY NOTIFY relativeControlYChanged)
159
QQuickPathQuad(QObject *parent=0) : QQuickCurve(parent), _controlX(0), _controlY(0) {}
161
qreal controlX() const;
162
void setControlX(qreal x);
164
qreal controlY() const;
165
void setControlY(qreal y);
167
qreal relativeControlX() const;
168
void setRelativeControlX(qreal x);
169
bool hasRelativeControlX();
171
qreal relativeControlY() const;
172
void setRelativeControlY(qreal y);
173
bool hasRelativeControlY();
175
void addToPath(QPainterPath &path, const QQuickPathData &);
178
void controlXChanged();
179
void controlYChanged();
180
void relativeControlXChanged();
181
void relativeControlYChanged();
186
QQmlNullableValue<qreal> _relativeControlX;
187
QQmlNullableValue<qreal> _relativeControlY;
190
class Q_AUTOTEST_EXPORT QQuickPathCubic : public QQuickCurve
194
Q_PROPERTY(qreal control1X READ control1X WRITE setControl1X NOTIFY control1XChanged)
195
Q_PROPERTY(qreal control1Y READ control1Y WRITE setControl1Y NOTIFY control1YChanged)
196
Q_PROPERTY(qreal control2X READ control2X WRITE setControl2X NOTIFY control2XChanged)
197
Q_PROPERTY(qreal control2Y READ control2Y WRITE setControl2Y NOTIFY control2YChanged)
198
Q_PROPERTY(qreal relativeControl1X READ relativeControl1X WRITE setRelativeControl1X NOTIFY relativeControl1XChanged)
199
Q_PROPERTY(qreal relativeControl1Y READ relativeControl1Y WRITE setRelativeControl1Y NOTIFY relativeControl1YChanged)
200
Q_PROPERTY(qreal relativeControl2X READ relativeControl2X WRITE setRelativeControl2X NOTIFY relativeControl2XChanged)
201
Q_PROPERTY(qreal relativeControl2Y READ relativeControl2Y WRITE setRelativeControl2Y NOTIFY relativeControl2YChanged)
203
QQuickPathCubic(QObject *parent=0) : QQuickCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {}
205
qreal control1X() const;
206
void setControl1X(qreal x);
208
qreal control1Y() const;
209
void setControl1Y(qreal y);
211
qreal control2X() const;
212
void setControl2X(qreal x);
214
qreal control2Y() const;
215
void setControl2Y(qreal y);
217
qreal relativeControl1X() const;
218
void setRelativeControl1X(qreal x);
219
bool hasRelativeControl1X();
221
qreal relativeControl1Y() const;
222
void setRelativeControl1Y(qreal y);
223
bool hasRelativeControl1Y();
225
qreal relativeControl2X() const;
226
void setRelativeControl2X(qreal x);
227
bool hasRelativeControl2X();
229
qreal relativeControl2Y() const;
230
void setRelativeControl2Y(qreal y);
231
bool hasRelativeControl2Y();
233
void addToPath(QPainterPath &path, const QQuickPathData &);
236
void control1XChanged();
237
void control1YChanged();
238
void control2XChanged();
239
void control2YChanged();
240
void relativeControl1XChanged();
241
void relativeControl1YChanged();
242
void relativeControl2XChanged();
243
void relativeControl2YChanged();
250
QQmlNullableValue<qreal> _relativeControl1X;
251
QQmlNullableValue<qreal> _relativeControl1Y;
252
QQmlNullableValue<qreal> _relativeControl2X;
253
QQmlNullableValue<qreal> _relativeControl2Y;
256
class Q_AUTOTEST_EXPORT QQuickPathCatmullRomCurve : public QQuickCurve
260
QQuickPathCatmullRomCurve(QObject *parent=0) : QQuickCurve(parent) {}
262
void addToPath(QPainterPath &path, const QQuickPathData &);
265
class Q_AUTOTEST_EXPORT QQuickPathArc : public QQuickCurve
268
Q_PROPERTY(qreal radiusX READ radiusX WRITE setRadiusX NOTIFY radiusXChanged)
269
Q_PROPERTY(qreal radiusY READ radiusY WRITE setRadiusY NOTIFY radiusYChanged)
270
Q_PROPERTY(bool useLargeArc READ useLargeArc WRITE setUseLargeArc NOTIFY useLargeArcChanged)
271
Q_PROPERTY(ArcDirection direction READ direction WRITE setDirection NOTIFY directionChanged)
274
QQuickPathArc(QObject *parent=0)
275
: QQuickCurve(parent), _radiusX(0), _radiusY(0), _useLargeArc(false), _direction(Clockwise) {}
277
enum ArcDirection { Clockwise, Counterclockwise };
278
Q_ENUMS(ArcDirection)
280
qreal radiusX() const;
281
void setRadiusX(qreal);
283
qreal radiusY() const;
284
void setRadiusY(qreal);
286
bool useLargeArc() const;
287
void setUseLargeArc(bool);
289
ArcDirection direction() const;
290
void setDirection(ArcDirection direction);
292
void addToPath(QPainterPath &path, const QQuickPathData &);
295
void radiusXChanged();
296
void radiusYChanged();
297
void useLargeArcChanged();
298
void directionChanged();
304
ArcDirection _direction;
307
class Q_AUTOTEST_EXPORT QQuickPathSvg : public QQuickCurve
310
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
312
QQuickPathSvg(QObject *parent=0) : QQuickCurve(parent) {}
314
QString path() const;
315
void setPath(const QString &path);
317
void addToPath(QPainterPath &path, const QQuickPathData &);
326
class Q_AUTOTEST_EXPORT QQuickPathPercent : public QQuickPathElement
329
Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
331
QQuickPathPercent(QObject *parent=0) : QQuickPathElement(parent) {}
334
void setValue(qreal value);
343
struct QQuickCachedBezier
345
QQuickCachedBezier() : isValid(false) {}
354
class QQuickPathPrivate;
355
class Q_AUTOTEST_EXPORT QQuickPath : public QObject, public QQmlParserStatus
359
Q_INTERFACES(QQmlParserStatus)
360
Q_PROPERTY(QQmlListProperty<QQuickPathElement> pathElements READ pathElements)
361
Q_PROPERTY(qreal startX READ startX WRITE setStartX NOTIFY startXChanged)
362
Q_PROPERTY(qreal startY READ startY WRITE setStartY NOTIFY startYChanged)
363
Q_PROPERTY(bool closed READ isClosed NOTIFY changed)
364
Q_CLASSINFO("DefaultProperty", "pathElements")
365
Q_INTERFACES(QQmlParserStatus)
367
QQuickPath(QObject *parent=0);
370
QQmlListProperty<QQuickPathElement> pathElements();
372
qreal startX() const;
373
void setStartX(qreal x);
374
bool hasStartX() const;
376
qreal startY() const;
377
void setStartY(qreal y);
378
bool hasStartY() const;
380
bool isClosed() const;
383
QPainterPath path() const;
384
QStringList attributes() const;
385
qreal attributeAt(const QString &, qreal) const;
386
QPointF pointAt(qreal) const;
387
QPointF sequentialPointAt(qreal p, qreal *angle = 0) const;
388
void invalidateSequentialHistory() const;
392
void startXChanged();
393
void startYChanged();
396
virtual void componentComplete();
397
virtual void classBegin();
403
struct AttributePoint {
404
AttributePoint() : percent(0), scale(1), origpercent(0) {}
405
AttributePoint(const AttributePoint &other)
406
: percent(other.percent), scale(other.scale), origpercent(other.origpercent), values(other.values) {}
407
AttributePoint &operator=(const AttributePoint &other) {
408
percent = other.percent; scale = other.scale; origpercent = other.origpercent; values = other.values; return *this;
410
qreal percent; //massaged percent along the painter path
412
qreal origpercent; //'real' percent along the painter path
413
QHash<QString, qreal> values;
416
void interpolate(int idx, const QString &name, qreal value);
417
void endpoint(const QString &name);
418
void createPointCache() const;
420
static void interpolate(QList<AttributePoint> &points, int idx, const QString &name, qreal value);
421
static void endpoint(QList<AttributePoint> &attributePoints, const QString &name);
422
static QPointF forwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = 0);
423
static QPointF backwardsPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = 0);
426
Q_DISABLE_COPY(QQuickPath)
427
Q_DECLARE_PRIVATE(QQuickPath)
428
friend class QQuickPathAnimationUpdater;
431
QPainterPath createPath(const QPointF &startPoint, const QPointF &endPoint, const QStringList &attributes, qreal &pathLength, QList<AttributePoint> &attributePoints, bool *closed = 0);
432
static QPointF sequentialPointAt(const QPainterPath &path, const qreal &pathLength, const QList<AttributePoint> &attributePoints, QQuickCachedBezier &prevBez, qreal p, qreal *angle = 0);
437
QML_DECLARE_TYPE(QQuickPathElement)
438
QML_DECLARE_TYPE(QQuickPathAttribute)
439
QML_DECLARE_TYPE(QQuickCurve)
440
QML_DECLARE_TYPE(QQuickPathLine)
441
QML_DECLARE_TYPE(QQuickPathQuad)
442
QML_DECLARE_TYPE(QQuickPathCubic)
443
QML_DECLARE_TYPE(QQuickPathCatmullRomCurve)
444
QML_DECLARE_TYPE(QQuickPathArc)
445
QML_DECLARE_TYPE(QQuickPathSvg)
446
QML_DECLARE_TYPE(QQuickPathPercent)
447
QML_DECLARE_TYPE(QQuickPath)
451
#endif // QQUICKPATH_H