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