Fix test fails related to QTBUG-22237
[profile/ivi/qtdeclarative.git] / src / declarative / items / context2d / qquickcontext2d_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 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 ** 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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKCONTEXT2D_P_H
43 #define QQUICKCONTEXT2D_P_H
44
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativecomponent.h>
47
48 #include <QtGui/qpainter.h>
49 #include <QtGui/qpainterpath.h>
50 #include <QtCore/qstring.h>
51 #include <QtCore/qstack.h>
52 #include <private/qv8engine_p.h>
53
54
55
56 #define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
57
58 #ifdef QQUICKCONTEXT2D_DEBUG
59 #include <QElapsedTimer>
60 #endif
61
62 QT_BEGIN_HEADER
63
64 QT_BEGIN_NAMESPACE
65
66 QT_MODULE(Declarative)
67
68 class QQuickCanvasItem;
69 class QQuickContext2DCommandBuffer;
70 class QDeclarativePixmap;
71
72 class Q_DECLARATIVE_EXPORT QQuickContext2D
73 {
74 public:
75     enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging};
76     enum TextAlignType { Start=0, End, Left, Right, Center};
77     enum PaintCommand {
78         Invalid = 0,
79         UpdateMatrix,
80         ClearRect,
81         FillRect,
82         StrokeRect,
83         Fill,
84         Stroke,
85         Clip,
86         UpdateBrush,
87         GlobalAlpha,
88         GlobalCompositeOperation,
89         StrokeStyle,
90         FillStyle,
91         LineWidth,
92         LineCap,
93         LineJoin,
94         MiterLimit,
95         ShadowOffsetX,
96         ShadowOffsetY,
97         ShadowBlur,
98         ShadowColor,
99         Font,
100         TextBaseline,
101         TextAlign,
102         FillText,
103         StrokeText,
104         DrawImage,
105         GetImageData
106     };
107
108
109     struct State {
110         QTransform matrix;
111         QPainterPath clipPath;
112         QBrush strokeStyle;
113         QBrush fillStyle;
114         bool fillPatternRepeatX:1;
115         bool fillPatternRepeatY:1;
116         bool strokePatternRepeatX:1;
117         bool strokePatternRepeatY:1;
118         Qt::FillRule fillRule;
119         qreal globalAlpha;
120         qreal lineWidth;
121         Qt::PenCapStyle lineCap;
122         Qt::PenJoinStyle lineJoin;
123         qreal miterLimit;
124         qreal shadowOffsetX;
125         qreal shadowOffsetY;
126         qreal shadowBlur;
127         QColor shadowColor;
128         QPainter::CompositionMode globalCompositeOperation;
129         QFont font;
130         QQuickContext2D::TextAlignType textAlign;
131         QQuickContext2D::TextBaseLineType textBaseline;
132     };
133
134     QQuickContext2D(QQuickCanvasItem* item);
135     ~QQuickContext2D();
136
137     inline QQuickCanvasItem*  canvas() const {return m_canvas;}
138     inline QQuickContext2DCommandBuffer* buffer() const {return m_buffer;}
139
140     v8::Handle<v8::Object> v8value() const;
141     void setV8Engine(QV8Engine *eng);
142     void popState();
143     void pushState();
144     void reset();
145
146     // path API
147     void beginPath();
148     void closePath();
149     void moveTo(qreal x, qreal y);
150     void lineTo(qreal x, qreal y);
151     void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y);
152     void bezierCurveTo(qreal cp1x, qreal cp1y,
153                        qreal cp2x, qreal cp2y, qreal x, qreal y);
154     void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius);
155     void rect(qreal x, qreal y, qreal w, qreal h);
156     void roundedRect(qreal x, qreal y,qreal w, qreal h, qreal xr, qreal yr);
157     void ellipse(qreal x, qreal y,qreal w, qreal h);
158     void text(const QString& str, qreal x, qreal y);
159     void arc(qreal x, qreal y, qreal radius,
160              qreal startAngle, qreal endAngle,
161              bool anticlockwise, bool transform=true);
162     void addArcTo(const QPointF& p1, const QPointF& p2, float radius);
163
164     bool isPointInPath(qreal x, qreal y) const;
165
166     QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
167     QImage createImage(const QUrl& url);
168
169     State state;
170     QStack<QQuickContext2D::State> m_stateStack;
171     QQuickCanvasItem* m_canvas;
172     QQuickContext2DCommandBuffer* m_buffer;
173     QPainterPath m_path;
174     v8::Local<v8::Value> m_fillStyle;
175     v8::Local<v8::Value> m_strokeStyle;
176     v8::Handle<v8::Value> m_v8path;
177     QV8Engine *m_v8engine;
178     v8::Persistent<v8::Object> m_v8value;
179 };
180
181
182 QT_END_NAMESPACE
183 QML_DECLARE_TYPE(QQuickContext2D)
184
185 QT_END_HEADER
186
187 #endif // QQUICKCONTEXT2D_P_H