Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickcanvasitem_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKCANVASITEM_P_H
5#define QQUICKCANVASITEM_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_canvas);
21
22#include <QtQuick/qquickitem.h>
23#include <private/qqmlrefcount_p.h>
24#include <QtCore/QThread>
25#include <QtCore/qmutex.h>
26#include <QtGui/QImage>
27
29
31
33class QQuickPixmap;
34class QQmlV4Function;
35
36class QQuickCanvasPixmap final : public QQmlRefCounted<QQuickCanvasPixmap>
37{
38public:
42
43 QImage image();
44
45 qreal width() const;
46 qreal height() const;
47 bool isValid() const;
48 QQuickPixmap *pixmap() const { return m_pixmap;}
49
50private:
51 QQuickPixmap *m_pixmap;
52 QImage m_image;
53};
54
56{
58
59 Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged FINAL)
67 QML_NAMED_ELEMENT(Canvas)
69
70public:
74 };
76
81 };
83
86
87 bool isAvailable() const;
88
89 QString contextType() const;
91
92 QJSValue context() const;
93
94 QSizeF canvasSize() const;
95 void setCanvasSize(const QSizeF &);
96
97 QSize tileSize() const;
98 void setTileSize(const QSize &);
99
100 QRectF canvasWindow() const;
101 void setCanvasWindow(const QRectF& rect);
102
105
107 void setRenderStrategy(RenderStrategy strategy);
108
110
111 QImage toImage(const QRectF& rect = QRectF()) const;
112
114
117
119 Q_INVOKABLE void markDirty(const QRectF& dirtyRect = QRectF());
120
121 Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize = QSizeF()) const;
122 Q_INVOKABLE QString toDataURL(const QString& type = QLatin1String("image/png")) const;
124
125 bool isTextureProvider() const override;
126 QSGTextureProvider *textureProvider() const override;
127
129 void paint(const QRect &region);
130 void painted();
140
141public Q_SLOTS:
142 void loadImage(const QUrl& url, QSizeF sourceSize = QSizeF());
143 void unloadImage(const QUrl& url);
144 bool isImageLoaded(const QUrl& url) const;
145 bool isImageLoading(const QUrl& url) const;
146 bool isImageError(const QUrl& url) const;
147
148private Q_SLOTS:
149 void sceneGraphInitialized();
150 void checkAnimationCallbacks();
151 void invalidateSceneGraph();
152 void schedulePolish();
153
154protected:
155 void componentComplete() override;
157 void updatePolish() override;
159 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
160 void releaseResources() override;
161 bool event(QEvent *event) override;
162private:
163 Q_DECLARE_PRIVATE(QQuickCanvasItem)
164 Q_INVOKABLE void delayedCreate();
165 bool createContext(const QString &contextType);
166 void initializeContext(QQuickCanvasContext *context, const QVariantMap &args = QVariantMap());
167 static QRect tiledRect(const QRectF &window, const QSize &tileSize);
168 bool isPaintConnected();
169};
170
172{
174public:
177
179
180private:
181 QQmlEngine *m_engine;
182 QObject *m_eventLoopQuitHack;
184 static QMutex renderThreadsMutex;
185};
186
188
190
191#endif //QQUICKCANVASITEM_P_H
\inmodule QtCore
Definition qcoreevent.h:45
\inmodule QtCore
Definition qhash.h:818
\inmodule QtGui
Definition qimage.h:37
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
\inmodule QtCore
Definition qmutex.h:285
\inmodule QtCore
Definition qobject.h:90
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void setTileSize(const QSize &)
void renderStrategyChanged()
void renderTargetChanged()
void setCanvasWindow(const QRectF &rect)
Q_INVOKABLE QString toDataURL(const QString &type=QLatin1String("image/png")) const
\qmlmethod string QtQuick::Canvas::toDataURL(string mimeType)
bool isTextureProvider() const override
Returns true if this item is a texture provider.
void paint(const QRect &region)
bool isImageLoaded(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoaded(url image) Returns true if the image is successfully loaded...
void setCanvasSize(const QSizeF &)
void setRenderStrategy(RenderStrategy strategy)
RenderStrategy renderStrategy
QQmlRefPointer< QQuickCanvasPixmap > loadedPixmap(const QUrl &url, QSizeF sourceSize=QSizeF())
void updatePolish() override
This function should perform any layout as required for this item.
QQuickCanvasContext * rawContext() const
Q_INVOKABLE void cancelRequestAnimationFrame(QQmlV4Function *args)
\qmlmethod QtQuick::Canvas::cancelRequestAnimationFrame(int handle)
QSGTextureProvider * textureProvider() const override
Returns the texture provider for an item.
void setContextType(const QString &contextType)
bool isAvailable() const
\qmlproperty bool QtQuick::Canvas::available
Q_INVOKABLE bool save(const QString &filename, const QSizeF &imageSize=QSizeF()) const
\qmlmethod bool QtQuick::Canvas::save(string filename, size imageSize = undefined)
void availableChanged()
Q_INVOKABLE void getContext(QQmlV4Function *args)
\qmlmethod object QtQuick::Canvas::getContext(string contextId, ... args)
void unloadImage(const QUrl &url)
\qmlmethod QtQuick::Canvas::unloadImage(url image)
bool isImageError(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageError(url image)
void contextTypeChanged()
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QImage toImage(const QRectF &rect=QRectF()) const
void tileSizeChanged()
void canvasSizeChanged()
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void canvasWindowChanged()
void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override
Called when change occurs for this item.
void releaseResources() override
This function is called when an item should release graphics resources which are not already managed ...
bool isImageLoading(const QUrl &url) const
\qmlmethod QtQuick::Canvas::isImageLoading(url image) Returns true if the image is currently loading.
RenderTarget renderTarget
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
Q_INVOKABLE void markDirty(const QRectF &dirtyRect=QRectF())
\qmlmethod QtQuick::Canvas::markDirty(rect area)
void setRenderTarget(RenderTarget target)
void loadImage(const QUrl &url, QSizeF sourceSize=QSizeF())
\qmlsignal QtQuick::Canvas::imageLoaded()
Q_INVOKABLE void requestPaint()
\qmlmethod QtQuick::Canvas::requestPaint()
Q_INVOKABLE void requestAnimationFrame(QQmlV4Function *args)
\qmlmethod int QtQuick::Canvas::requestAnimationFrame(callback)
QQuickPixmap * pixmap() const
static QQuickContext2DRenderThread * instance(QQmlEngine *engine)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
QQuickWindow * window() const
Returns the window in which this item is rendered.
QQuickItem * parent
\qmlproperty Item QtQuick::Item::parent This property holds the visual parent of the item.
Definition qquickitem.h:68
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
Definition qquickitem.h:143
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore\reentrant
Definition qrect.h:30
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
Definition qsgnode.h:37
The QSGTextureProvider class encapsulates texture based entities in QML.
\inmodule QtCore
Definition qsize.h:207
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Definition qurl.h:94
rect
[4]
Combined button and popup list for selecting options.
Definition image.cpp:4
QMap< QString, QVariant > QVariantMap
GLenum type
GLenum target
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
struct _cl_event * event
#define QML_DECLARE_TYPE(TYPE)
Definition qqml.h:19
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_INVOKABLE
#define Q_SLOTS
#define Q_SIGNALS
double qreal
Definition qtypes.h:92
QUrl url("example.com")
[constructor-url-reference]
QJSValueList args
QJSEngine engine
[0]
\inmodule QtQuick
Definition qquickitem.h:158