~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to src/quick/util/qquickpath_p.h

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
20
**
 
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.
 
28
**
 
29
** Other Usage
 
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.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QQUICKPATH_H
 
43
#define QQUICKPATH_H
 
44
 
 
45
#include <qqml.h>
 
46
 
 
47
#include <private/qqmlnullablevalue_p_p.h>
 
48
#include <private/qbezier_p.h>
 
49
 
 
50
#include <QtCore/QObject>
 
51
#include <QtGui/QPainterPath>
 
52
 
 
53
QT_BEGIN_HEADER
 
54
 
 
55
QT_BEGIN_NAMESPACE
 
56
 
 
57
class QQuickCurve;
 
58
struct QQuickPathData
 
59
{
 
60
    int index;
 
61
    QPointF endPoint;
 
62
    QList<QQuickCurve*> curves;
 
63
};
 
64
 
 
65
class Q_AUTOTEST_EXPORT QQuickPathElement : public QObject
 
66
{
 
67
    Q_OBJECT
 
68
public:
 
69
    QQuickPathElement(QObject *parent=0) : QObject(parent) {}
 
70
Q_SIGNALS:
 
71
    void changed();
 
72
};
 
73
 
 
74
class Q_AUTOTEST_EXPORT QQuickPathAttribute : public QQuickPathElement
 
75
{
 
76
    Q_OBJECT
 
77
 
 
78
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
 
79
    Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
 
80
public:
 
81
    QQuickPathAttribute(QObject *parent=0) : QQuickPathElement(parent), _value(0) {}
 
82
 
 
83
 
 
84
    QString name() const;
 
85
    void setName(const QString &name);
 
86
 
 
87
    qreal value() const;
 
88
    void setValue(qreal value);
 
89
 
 
90
Q_SIGNALS:
 
91
    void nameChanged();
 
92
    void valueChanged();
 
93
 
 
94
private:
 
95
    QString _name;
 
96
    qreal _value;
 
97
};
 
98
 
 
99
class Q_AUTOTEST_EXPORT QQuickCurve : public QQuickPathElement
 
100
{
 
101
    Q_OBJECT
 
102
 
 
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)
 
107
public:
 
108
    QQuickCurve(QObject *parent=0) : QQuickPathElement(parent) {}
 
109
 
 
110
    qreal x() const;
 
111
    void setX(qreal x);
 
112
    bool hasX();
 
113
 
 
114
    qreal y() const;
 
115
    void setY(qreal y);
 
116
    bool hasY();
 
117
 
 
118
    qreal relativeX() const;
 
119
    void setRelativeX(qreal x);
 
120
    bool hasRelativeX();
 
121
 
 
122
    qreal relativeY() const;
 
123
    void setRelativeY(qreal y);
 
124
    bool hasRelativeY();
 
125
 
 
126
    virtual void addToPath(QPainterPath &, const QQuickPathData &) {}
 
127
 
 
128
Q_SIGNALS:
 
129
    void xChanged();
 
130
    void yChanged();
 
131
    void relativeXChanged();
 
132
    void relativeYChanged();
 
133
 
 
134
private:
 
135
    QQmlNullableValue<qreal> _x;
 
136
    QQmlNullableValue<qreal> _y;
 
137
    QQmlNullableValue<qreal> _relativeX;
 
138
    QQmlNullableValue<qreal> _relativeY;
 
139
};
 
140
 
 
141
class Q_AUTOTEST_EXPORT QQuickPathLine : public QQuickCurve
 
142
{
 
143
    Q_OBJECT
 
144
public:
 
145
    QQuickPathLine(QObject *parent=0) : QQuickCurve(parent) {}
 
146
 
 
147
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
148
};
 
149
 
 
150
class Q_AUTOTEST_EXPORT QQuickPathQuad : public QQuickCurve
 
151
{
 
152
    Q_OBJECT
 
153
 
 
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)
 
158
public:
 
159
    QQuickPathQuad(QObject *parent=0) : QQuickCurve(parent), _controlX(0), _controlY(0) {}
 
160
 
 
161
    qreal controlX() const;
 
162
    void setControlX(qreal x);
 
163
 
 
164
    qreal controlY() const;
 
165
    void setControlY(qreal y);
 
166
 
 
167
    qreal relativeControlX() const;
 
168
    void setRelativeControlX(qreal x);
 
169
    bool hasRelativeControlX();
 
170
 
 
171
    qreal relativeControlY() const;
 
172
    void setRelativeControlY(qreal y);
 
173
    bool hasRelativeControlY();
 
174
 
 
175
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
176
 
 
177
Q_SIGNALS:
 
178
    void controlXChanged();
 
179
    void controlYChanged();
 
180
    void relativeControlXChanged();
 
181
    void relativeControlYChanged();
 
182
 
 
183
private:
 
184
    qreal _controlX;
 
185
    qreal _controlY;
 
186
    QQmlNullableValue<qreal> _relativeControlX;
 
187
    QQmlNullableValue<qreal> _relativeControlY;
 
188
};
 
189
 
 
190
class Q_AUTOTEST_EXPORT QQuickPathCubic : public QQuickCurve
 
191
{
 
192
    Q_OBJECT
 
193
 
 
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)
 
202
public:
 
203
    QQuickPathCubic(QObject *parent=0) : QQuickCurve(parent), _control1X(0), _control1Y(0), _control2X(0), _control2Y(0) {}
 
204
 
 
205
    qreal control1X() const;
 
206
    void setControl1X(qreal x);
 
207
 
 
208
    qreal control1Y() const;
 
209
    void setControl1Y(qreal y);
 
210
 
 
211
    qreal control2X() const;
 
212
    void setControl2X(qreal x);
 
213
 
 
214
    qreal control2Y() const;
 
215
    void setControl2Y(qreal y);
 
216
 
 
217
    qreal relativeControl1X() const;
 
218
    void setRelativeControl1X(qreal x);
 
219
    bool hasRelativeControl1X();
 
220
 
 
221
    qreal relativeControl1Y() const;
 
222
    void setRelativeControl1Y(qreal y);
 
223
    bool hasRelativeControl1Y();
 
224
 
 
225
    qreal relativeControl2X() const;
 
226
    void setRelativeControl2X(qreal x);
 
227
    bool hasRelativeControl2X();
 
228
 
 
229
    qreal relativeControl2Y() const;
 
230
    void setRelativeControl2Y(qreal y);
 
231
    bool hasRelativeControl2Y();
 
232
 
 
233
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
234
 
 
235
Q_SIGNALS:
 
236
    void control1XChanged();
 
237
    void control1YChanged();
 
238
    void control2XChanged();
 
239
    void control2YChanged();
 
240
    void relativeControl1XChanged();
 
241
    void relativeControl1YChanged();
 
242
    void relativeControl2XChanged();
 
243
    void relativeControl2YChanged();
 
244
 
 
245
private:
 
246
    qreal _control1X;
 
247
    qreal _control1Y;
 
248
    qreal _control2X;
 
249
    qreal _control2Y;
 
250
    QQmlNullableValue<qreal> _relativeControl1X;
 
251
    QQmlNullableValue<qreal> _relativeControl1Y;
 
252
    QQmlNullableValue<qreal> _relativeControl2X;
 
253
    QQmlNullableValue<qreal> _relativeControl2Y;
 
254
};
 
255
 
 
256
class Q_AUTOTEST_EXPORT QQuickPathCatmullRomCurve : public QQuickCurve
 
257
{
 
258
    Q_OBJECT
 
259
public:
 
260
    QQuickPathCatmullRomCurve(QObject *parent=0) : QQuickCurve(parent) {}
 
261
 
 
262
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
263
};
 
264
 
 
265
class Q_AUTOTEST_EXPORT QQuickPathArc : public QQuickCurve
 
266
{
 
267
    Q_OBJECT
 
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)
 
272
 
 
273
public:
 
274
    QQuickPathArc(QObject *parent=0)
 
275
        : QQuickCurve(parent), _radiusX(0), _radiusY(0), _useLargeArc(false), _direction(Clockwise) {}
 
276
 
 
277
    enum ArcDirection { Clockwise, Counterclockwise };
 
278
    Q_ENUMS(ArcDirection)
 
279
 
 
280
    qreal radiusX() const;
 
281
    void setRadiusX(qreal);
 
282
 
 
283
    qreal radiusY() const;
 
284
    void setRadiusY(qreal);
 
285
 
 
286
    bool useLargeArc() const;
 
287
    void setUseLargeArc(bool);
 
288
 
 
289
    ArcDirection direction() const;
 
290
    void setDirection(ArcDirection direction);
 
291
 
 
292
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
293
 
 
294
Q_SIGNALS:
 
295
    void radiusXChanged();
 
296
    void radiusYChanged();
 
297
    void useLargeArcChanged();
 
298
    void directionChanged();
 
299
 
 
300
private:
 
301
    qreal _radiusX;
 
302
    qreal _radiusY;
 
303
    bool _useLargeArc;
 
304
    ArcDirection _direction;
 
305
};
 
306
 
 
307
class Q_AUTOTEST_EXPORT QQuickPathSvg : public QQuickCurve
 
308
{
 
309
    Q_OBJECT
 
310
    Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
 
311
public:
 
312
    QQuickPathSvg(QObject *parent=0) : QQuickCurve(parent) {}
 
313
 
 
314
    QString path() const;
 
315
    void setPath(const QString &path);
 
316
 
 
317
    void addToPath(QPainterPath &path, const QQuickPathData &);
 
318
 
 
319
Q_SIGNALS:
 
320
    void pathChanged();
 
321
 
 
322
private:
 
323
    QString _path;
 
324
};
 
325
 
 
326
class Q_AUTOTEST_EXPORT QQuickPathPercent : public QQuickPathElement
 
327
{
 
328
    Q_OBJECT
 
329
    Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged)
 
330
public:
 
331
    QQuickPathPercent(QObject *parent=0) : QQuickPathElement(parent) {}
 
332
 
 
333
    qreal value() const;
 
334
    void setValue(qreal value);
 
335
 
 
336
signals:
 
337
    void valueChanged();
 
338
 
 
339
private:
 
340
    qreal _value;
 
341
};
 
342
 
 
343
struct QQuickCachedBezier
 
344
{
 
345
    QQuickCachedBezier() : isValid(false) {}
 
346
    QBezier bezier;
 
347
    int element;
 
348
    qreal bezLength;
 
349
    qreal currLength;
 
350
    qreal p;
 
351
    bool isValid;
 
352
};
 
353
 
 
354
class QQuickPathPrivate;
 
355
class Q_AUTOTEST_EXPORT QQuickPath : public QObject, public QQmlParserStatus
 
356
{
 
357
    Q_OBJECT
 
358
 
 
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)
 
366
public:
 
367
    QQuickPath(QObject *parent=0);
 
368
    ~QQuickPath();
 
369
 
 
370
    QQmlListProperty<QQuickPathElement> pathElements();
 
371
 
 
372
    qreal startX() const;
 
373
    void setStartX(qreal x);
 
374
    bool hasStartX() const;
 
375
 
 
376
    qreal startY() const;
 
377
    void setStartY(qreal y);
 
378
    bool hasStartY() const;
 
379
 
 
380
    bool isClosed() const;
 
381
    bool hasEnd() const;
 
382
 
 
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;
 
389
 
 
390
Q_SIGNALS:
 
391
    void changed();
 
392
    void startXChanged();
 
393
    void startYChanged();
 
394
 
 
395
protected:
 
396
    virtual void componentComplete();
 
397
    virtual void classBegin();
 
398
 
 
399
private Q_SLOTS:
 
400
    void processPath();
 
401
 
 
402
private:
 
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;
 
409
        }
 
410
        qreal percent;      //massaged percent along the painter path
 
411
        qreal scale;
 
412
        qreal origpercent;  //'real' percent along the painter path
 
413
        QHash<QString, qreal> values;
 
414
    };
 
415
 
 
416
    void interpolate(int idx, const QString &name, qreal value);
 
417
    void endpoint(const QString &name);
 
418
    void createPointCache() const;
 
419
 
 
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);
 
424
 
 
425
private:
 
426
    Q_DISABLE_COPY(QQuickPath)
 
427
    Q_DECLARE_PRIVATE(QQuickPath)
 
428
    friend class QQuickPathAnimationUpdater;
 
429
 
 
430
public:
 
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);
 
433
};
 
434
 
 
435
QT_END_NAMESPACE
 
436
 
 
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)
 
448
 
 
449
QT_END_HEADER
 
450
 
 
451
#endif // QQUICKPATH_H