1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKCONTEXT2D_P_H
43 #define QQUICKCONTEXT2D_P_H
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativecomponent.h>
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>
56 #define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
58 #ifdef QQUICKCONTEXT2D_DEBUG
59 #include <QElapsedTimer>
66 QT_MODULE(Declarative)
68 class QQuickCanvasItem;
69 class QQuickContext2DCommandBuffer;
70 class QDeclarativePixmap;
72 class Q_DECLARATIVE_EXPORT QQuickContext2D
75 enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging};
76 enum TextAlignType { Start=0, End, Left, Right, Center};
88 GlobalCompositeOperation,
111 QPainterPath clipPath;
114 bool fillPatternRepeatX:1;
115 bool fillPatternRepeatY:1;
116 bool strokePatternRepeatX:1;
117 bool strokePatternRepeatY:1;
118 Qt::FillRule fillRule;
121 Qt::PenCapStyle lineCap;
122 Qt::PenJoinStyle lineJoin;
128 QPainter::CompositionMode globalCompositeOperation;
130 QQuickContext2D::TextAlignType textAlign;
131 QQuickContext2D::TextBaseLineType textBaseline;
134 QQuickContext2D(QQuickCanvasItem* item);
137 inline QQuickCanvasItem* canvas() const {return m_canvas;}
138 inline QQuickContext2DCommandBuffer* buffer() const {return m_buffer;}
140 v8::Handle<v8::Object> v8value() const;
141 void setV8Engine(QV8Engine *eng);
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);
164 bool isPointInPath(qreal x, qreal y) const;
166 QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
167 QImage createImage(const QUrl& url);
170 QStack<QQuickContext2D::State> m_stateStack;
171 QQuickCanvasItem* m_canvas;
172 QQuickContext2DCommandBuffer* m_buffer;
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;
183 QML_DECLARE_TYPE(QQuickContext2D)
187 #endif // QQUICKCONTEXT2D_P_H