Add Q_DISABLE_COPY to QQuickContext2D
[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 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 QQUICKCONTEXT2D_P_H
43 #define QQUICKCONTEXT2D_P_H
44
45 #include <QtQuick/qtquickglobal.h>
46 #include <QtQml/qqml.h>
47 #include <QtQml/qqmlcomponent.h>
48 #include <private/qquickcanvascontext_p.h>
49 #include <private/qquickcanvasitem_p.h>
50 #include <QtGui/qpainter.h>
51 #include <QtGui/qpainterpath.h>
52 #include <QtCore/qstring.h>
53 #include <QtCore/qstack.h>
54 #include <QtCore/qqueue.h>
55 #include <private/qv8engine_p.h>
56
57
58
59 //#define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
60
61 #ifdef QQUICKCONTEXT2D_DEBUG
62 #include <QElapsedTimer>
63 #endif
64
65 QT_BEGIN_HEADER
66
67 QT_BEGIN_NAMESPACE
68
69 class QQuickContext2DCommandBuffer;
70 class QQuickContext2DTexture;
71 class QQuickPixmap;
72 class QSGTexture;
73
74
75 class QQuickContext2D : public QQuickCanvasContext
76 {
77 public:
78     Q_DISABLE_COPY(QQuickContext2D)
79
80     enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging};
81     enum TextAlignType { Start=0, End, Left, Right, Center};
82     enum PaintCommand {
83         Invalid = 0,
84         UpdateMatrix,
85         ClearRect,
86         FillRect,
87         StrokeRect,
88         Fill,
89         Stroke,
90         Clip,
91         UpdateBrush,
92         GlobalAlpha,
93         GlobalCompositeOperation,
94         StrokeStyle,
95         FillStyle,
96         LineWidth,
97         LineCap,
98         LineJoin,
99         MiterLimit,
100         ShadowOffsetX,
101         ShadowOffsetY,
102         ShadowBlur,
103         ShadowColor,
104         Font,
105         TextBaseline,
106         TextAlign,
107         FillText,
108         StrokeText,
109         DrawImage,
110         GetImageData
111     };
112
113     struct State {
114         State()
115             : strokeStyle(QColor("#000000"))
116             , fillStyle(QColor("#000000"))
117             , fillPatternRepeatX(false)
118             , fillPatternRepeatY(false)
119             , strokePatternRepeatX(false)
120             , strokePatternRepeatY(false)
121             , invertibleCTM(true)
122             , fillRule(Qt::WindingFill)
123             , globalAlpha(1.0)
124             , lineWidth(1)
125             , lineCap(Qt::FlatCap)
126             , lineJoin(Qt::MiterJoin)
127             , miterLimit(10)
128             , shadowOffsetX(0)
129             , shadowOffsetY(0)
130             , shadowBlur(0)
131             , shadowColor(qRgba(0, 0, 0, 0))
132             , globalCompositeOperation(QPainter::CompositionMode_SourceOver)
133             , font(QFont(QLatin1String("sans-serif"), 10))
134             , textAlign(QQuickContext2D::Start)
135             , textBaseline(QQuickContext2D::Alphabetic)
136         {
137         }
138
139         QTransform matrix;
140         QPainterPath clipPath;
141         QBrush strokeStyle;
142         QBrush fillStyle;
143         bool fillPatternRepeatX:1;
144         bool fillPatternRepeatY:1;
145         bool strokePatternRepeatX:1;
146         bool strokePatternRepeatY:1;
147         bool invertibleCTM:1;
148         Qt::FillRule fillRule;
149         qreal globalAlpha;
150         qreal lineWidth;
151         Qt::PenCapStyle lineCap;
152         Qt::PenJoinStyle lineJoin;
153         qreal miterLimit;
154         qreal shadowOffsetX;
155         qreal shadowOffsetY;
156         qreal shadowBlur;
157         QColor shadowColor;
158         QPainter::CompositionMode globalCompositeOperation;
159         QFont font;
160         QQuickContext2D::TextAlignType textAlign;
161         QQuickContext2D::TextBaseLineType textBaseline;
162     };
163
164     QQuickContext2D(QObject *parent = 0);
165     ~QQuickContext2D();
166
167     QStringList contextNames() const;
168     void init(QQuickCanvasItem *canvasItem, const QVariantMap &args);
169     void prepare(const QSize& canvasSize, const QSize& tileSize, const QRect& canvasWindow, const QRect& dirtyRect, bool smooth);
170     void flush();
171     void sync();
172     QSGDynamicTexture *texture() const;
173     QImage toImage(const QRectF& bounds);
174
175     v8::Handle<v8::Object> v8value() const;
176     void setV8Engine(QV8Engine *eng);
177
178     QQuickCanvasItem* canvas() const { return m_canvas; }
179     QQuickContext2DCommandBuffer* buffer() const { return m_buffer; }
180     QQuickContext2DCommandBuffer* nextBuffer();
181
182     bool bufferValid() const { return m_buffer != 0; }
183     void popState();
184     void pushState();
185     void reset();
186
187     void fill();
188     void clip();
189     void stroke();
190     void fillRect(qreal x, qreal y, qreal w, qreal h);
191     void strokeRect(qreal x, qreal y, qreal w, qreal h);
192     void clearRect(qreal x, qreal y, qreal w, qreal h);
193     void drawText(const QString& text, qreal x, qreal y, bool fill);
194
195     //Transform APIs
196     void scale(qreal x,  qreal y);
197     void rotate(qreal angle);
198     void shear(qreal h, qreal v);
199     void translate(qreal x, qreal y);
200     void transform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f);
201     void setTransform(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f);
202
203     // Path APIs
204     void beginPath();
205     void closePath();
206     void moveTo(qreal x, qreal y);
207     void lineTo(qreal x, qreal y);
208     void quadraticCurveTo(qreal cpx, qreal cpy, qreal x, qreal y);
209     void bezierCurveTo(qreal cp1x, qreal cp1y,
210                        qreal cp2x, qreal cp2y, qreal x, qreal y);
211     void arcTo(qreal x1, qreal y1, qreal x2, qreal y2, qreal radius);
212     void rect(qreal x, qreal y, qreal w, qreal h);
213     void roundedRect(qreal x, qreal y,qreal w, qreal h, qreal xr, qreal yr);
214     void ellipse(qreal x, qreal y,qreal w, qreal h);
215     void text(const QString& str, qreal x, qreal y);
216     void arc(qreal x, qreal y, qreal radius,
217              qreal startAngle, qreal endAngle,
218              bool anticlockwise);
219     void addArcTo(const QPointF& p1, const QPointF& p2, float radius);
220
221     bool isPointInPath(qreal x, qreal y) const;
222
223     QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
224     QImage createImage(const QUrl& url);
225
226     State state;
227     QStack<QQuickContext2D::State> m_stateStack;
228     QQuickCanvasItem* m_canvas;
229     QQuickContext2DCommandBuffer* m_buffer;
230     QPainterPath m_path;
231     v8::Local<v8::Value> m_fillStyle;
232     v8::Local<v8::Value> m_strokeStyle;
233     v8::Handle<v8::Value> m_v8path;
234     QV8Engine *m_v8engine;
235     v8::Persistent<v8::Object> m_v8value;
236     QQuickContext2DTexture *m_texture;
237     QQuickCanvasItem::RenderTarget m_renderTarget;
238     QQuickCanvasItem::RenderStrategy m_renderStrategy;
239     QQueue<QQuickContext2DCommandBuffer*> m_bufferQueue;
240     QMutex m_bufferMutex;
241 };
242
243
244 QT_END_NAMESPACE
245 QML_DECLARE_TYPE(QQuickContext2D)
246
247 QT_END_HEADER
248
249 #endif // QQUICKCONTEXT2D_P_H