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 QQUICKWIDGET_H |
5 | #define QQUICKWIDGET_H |
6 | |
7 | #include <QtWidgets/qwidget.h> |
8 | #include <QtQuick/qquickwindow.h> |
9 | #include <QtCore/qurl.h> |
10 | #include <QtQuickWidgets/qtquickwidgetsglobal.h> |
11 | #include <QtGui/qimage.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QQmlEngine; |
16 | class QQmlContext; |
17 | class QQmlError; |
18 | class QQuickItem; |
19 | class QQmlComponent; |
20 | |
21 | class QQuickWidgetPrivate; |
22 | class Q_QUICKWIDGETS_EXPORT QQuickWidget : public QWidget |
23 | { |
24 | Q_OBJECT |
25 | Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) |
26 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
27 | Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true) |
28 | |
29 | public: |
30 | explicit QQuickWidget(QWidget *parent = nullptr); |
31 | QQuickWidget(QQmlEngine* engine, QWidget *parent); |
32 | explicit QQuickWidget(const QUrl &source, QWidget *parent = nullptr); |
33 | ~QQuickWidget() override; |
34 | |
35 | QUrl source() const; |
36 | |
37 | QQmlEngine* engine() const; |
38 | QQmlContext* rootContext() const; |
39 | |
40 | QQuickItem *rootObject() const; |
41 | |
42 | enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }; |
43 | Q_ENUM(ResizeMode) |
44 | ResizeMode resizeMode() const; |
45 | void setResizeMode(ResizeMode); |
46 | |
47 | enum Status { Null, Ready, Loading, Error }; |
48 | Q_ENUM(Status) |
49 | Status status() const; |
50 | |
51 | QList<QQmlError> errors() const; |
52 | |
53 | QSize sizeHint() const override; |
54 | QSize initialSize() const; |
55 | |
56 | void setFormat(const QSurfaceFormat &format); |
57 | QSurfaceFormat format() const; |
58 | |
59 | QImage grabFramebuffer() const; |
60 | |
61 | void setClearColor(const QColor &color); |
62 | |
63 | QQuickWindow *quickWindow() const; |
64 | |
65 | public Q_SLOTS: |
66 | void setSource(const QUrl&); |
67 | void setContent(const QUrl& url, QQmlComponent *component, QObject *item); |
68 | |
69 | Q_SIGNALS: |
70 | void statusChanged(QQuickWidget::Status); |
71 | void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); |
72 | |
73 | private Q_SLOTS: |
74 | // ### Qt 6: make these truly private slots through Q_PRIVATE_SLOT |
75 | void continueExecute(); |
76 | void createFramebufferObject(); |
77 | void destroyFramebufferObject(); |
78 | void triggerUpdate(); |
79 | void propagateFocusObjectChanged(QObject *focusObject); |
80 | |
81 | protected: |
82 | void resizeEvent(QResizeEvent *) override; |
83 | void timerEvent(QTimerEvent*) override; |
84 | |
85 | void keyPressEvent(QKeyEvent *) override; |
86 | void keyReleaseEvent(QKeyEvent *) override; |
87 | void mousePressEvent(QMouseEvent *) override; |
88 | void mouseReleaseEvent(QMouseEvent *) override; |
89 | void mouseMoveEvent(QMouseEvent *) override; |
90 | void mouseDoubleClickEvent(QMouseEvent *) override; |
91 | |
92 | void showEvent(QShowEvent *) override; |
93 | void hideEvent(QHideEvent *) override; |
94 | |
95 | void focusInEvent(QFocusEvent * event) override; |
96 | void focusOutEvent(QFocusEvent * event) override; |
97 | |
98 | #if QT_CONFIG(wheelevent) |
99 | void wheelEvent(QWheelEvent *) override; |
100 | #endif |
101 | |
102 | #if QT_CONFIG(quick_draganddrop) |
103 | void dragEnterEvent(QDragEnterEvent *) override; |
104 | void dragMoveEvent(QDragMoveEvent *) override; |
105 | void dragLeaveEvent(QDragLeaveEvent *) override; |
106 | void dropEvent(QDropEvent *) override; |
107 | #endif |
108 | |
109 | bool event(QEvent *) override; |
110 | void paintEvent(QPaintEvent *event) override; |
111 | bool focusNextPrevChild(bool next) override; |
112 | |
113 | private: |
114 | Q_DISABLE_COPY(QQuickWidget) |
115 | Q_DECLARE_PRIVATE(QQuickWidget) |
116 | }; |
117 | |
118 | QT_END_NAMESPACE |
119 | |
120 | #endif // QQuickWidget_H |
121 |