1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 <QtQuick/qtquickglobal.h>
46 #include <QtDeclarative/qdeclarative.h>
47 #include <QtDeclarative/qdeclarativecomponent.h>
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>
57 #define QQUICKCONTEXT2D_DEBUG //enable this for just DEBUG purpose!
59 #ifdef QQUICKCONTEXT2D_DEBUG
60 #include <QElapsedTimer>
67 class QQuickCanvasItem;
68 class QQuickContext2DCommandBuffer;
69 class QDeclarativePixmap;
71 class Q_QUICK_EXPORT QQuickContext2D
74 enum TextBaseLineType { Alphabetic=0, Top, Middle, Bottom, Hanging};
75 enum TextAlignType { Start=0, End, Left, Right, Center};
87 GlobalCompositeOperation,
110 : strokeStyle(QColor("#000000"))
111 , fillStyle(QColor("#000000"))
112 , fillPatternRepeatX(false)
113 , fillPatternRepeatY(false)
114 , strokePatternRepeatX(false)
115 , strokePatternRepeatY(false)
116 , fillRule(Qt::WindingFill)
119 , lineCap(Qt::FlatCap)
120 , lineJoin(Qt::MiterJoin)
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)
134 QPainterPath clipPath;
137 bool fillPatternRepeatX:1;
138 bool fillPatternRepeatY:1;
139 bool strokePatternRepeatX:1;
140 bool strokePatternRepeatY:1;
141 Qt::FillRule fillRule;
144 Qt::PenCapStyle lineCap;
145 Qt::PenJoinStyle lineJoin;
151 QPainter::CompositionMode globalCompositeOperation;
153 QQuickContext2D::TextAlignType textAlign;
154 QQuickContext2D::TextBaseLineType textBaseline;
157 QQuickContext2D(QQuickCanvasItem* item);
160 inline QQuickCanvasItem* canvas() const {return m_canvas;}
161 inline QQuickContext2DCommandBuffer* buffer() const {return m_buffer;}
163 v8::Handle<v8::Object> v8value() const;
164 void setV8Engine(QV8Engine *eng);
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);
187 bool isPointInPath(qreal x, qreal y) const;
189 QPainterPath createTextGlyphs(qreal x, qreal y, const QString& text);
190 QImage createImage(const QUrl& url);
193 QStack<QQuickContext2D::State> m_stateStack;
194 QQuickCanvasItem* m_canvas;
195 QQuickContext2DCommandBuffer* m_buffer;
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;
206 QML_DECLARE_TYPE(QQuickContext2D)
210 #endif // QQUICKCONTEXT2D_P_H