1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKCANVASITEM_P_H
43 #define QQUICKCANVASITEM_P_H
45 #include <QtQuick/qquickitem.h>
46 #include <private/qv8engine_p.h>
52 class QQuickContext2D;
53 class QQuickCanvasItemPrivate;
54 class Q_QUICK_EXPORT QQuickCanvasItem : public QQuickItem
58 Q_ENUMS(ImageFilterMode)
60 Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged)
61 Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged)
62 Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged)
63 Q_PROPERTY(bool renderInThread READ renderInThread WRITE setRenderInThread NOTIFY renderInThreadChanged)
64 Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged)
71 enum ImageFilterMode {
82 QQuickCanvasItem(QQuickItem *parent = 0);
85 QSizeF canvasSize() const;
86 void setCanvasSize(const QSizeF &);
88 QSize tileSize() const;
89 void setTileSize(const QSize &);
91 QRectF canvasWindow() const;
92 void setCanvasWindow(const QRectF& rect);
94 bool renderInThread() const;
95 void setRenderInThread(bool renderInThread);
97 RenderTarget renderTarget() const;
98 void setRenderTarget(RenderTarget target);
100 QQuickContext2D* context() const;
101 QImage toImage(const QRectF& region = QRectF()) const;
103 QImage loadedImage(const QUrl& url);
106 void paint(QDeclarativeV8Handle context, const QRect ®ion);
108 void canvasSizeChanged();
109 void tileSizeChanged();
110 void renderInThreadChanged();
111 void textureChanged();
112 void canvasWindowChanged();
113 void renderTargetChanged();
116 QString toDataURL(const QString& type = QLatin1String("image/png")) const;
117 QDeclarativeV8Handle getContext(const QString & = QLatin1String("2d"));
118 void markDirty(const QRectF& region);
119 void requestPaint() {markDirty(canvasWindow());}
120 // Save current canvas to disk
121 bool save(const QString& filename) const;
122 void loadImage(const QUrl& url);
123 void unloadImage(const QUrl& url);
124 bool isImageLoaded(const QUrl& url) const;
125 bool isImageLoading(const QUrl& url) const;
126 bool isImageError(const QUrl& url) const;
128 void _doPainting(const QRectF& region);
130 virtual void componentComplete();
131 virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
132 virtual void geometryChanged(const QRectF &newGeometry,
133 const QRectF &oldGeometry);
134 virtual void updatePolish();
136 void createContext();
137 void createTexture();
138 Q_DECLARE_PRIVATE(QQuickCanvasItem)
139 friend class QQuickContext2D;
140 friend class QQuickContext2DTexture;
144 QML_DECLARE_TYPE(QQuickCanvasItem)
148 #endif //QQUICKCANVASITEM_P_H