1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQUICKWIDGET_H |
41 | #define QQUICKWIDGET_H |
42 | |
43 | #include <QtWidgets/qwidget.h> |
44 | #include <QtQuick/qquickwindow.h> |
45 | #include <QtCore/qurl.h> |
46 | #include <QtQuickWidgets/qtquickwidgetsglobal.h> |
47 | #include <QtGui/qimage.h> |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QQmlEngine; |
52 | class QQmlContext; |
53 | class QQmlError; |
54 | class QQuickItem; |
55 | class QQmlComponent; |
56 | |
57 | class QQuickWidgetPrivate; |
58 | class Q_QUICKWIDGETS_EXPORT QQuickWidget : public QWidget |
59 | { |
60 | Q_OBJECT |
61 | Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) |
62 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
63 | Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true) |
64 | |
65 | public: |
66 | explicit QQuickWidget(QWidget *parent = nullptr); |
67 | QQuickWidget(QQmlEngine* engine, QWidget *parent); |
68 | explicit QQuickWidget(const QUrl &source, QWidget *parent = nullptr); |
69 | ~QQuickWidget() override; |
70 | |
71 | QUrl source() const; |
72 | |
73 | QQmlEngine* engine() const; |
74 | QQmlContext* rootContext() const; |
75 | |
76 | QQuickItem *rootObject() const; |
77 | |
78 | enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }; |
79 | Q_ENUM(ResizeMode) |
80 | ResizeMode resizeMode() const; |
81 | void setResizeMode(ResizeMode); |
82 | |
83 | enum Status { Null, Ready, Loading, Error }; |
84 | Q_ENUM(Status) |
85 | Status status() const; |
86 | |
87 | QList<QQmlError> errors() const; |
88 | |
89 | QSize sizeHint() const override; |
90 | QSize initialSize() const; |
91 | |
92 | void setFormat(const QSurfaceFormat &format); |
93 | QSurfaceFormat format() const; |
94 | |
95 | QImage grabFramebuffer() const; |
96 | |
97 | void setClearColor(const QColor &color); |
98 | |
99 | QQuickWindow *quickWindow() const; |
100 | |
101 | public Q_SLOTS: |
102 | void setSource(const QUrl&); |
103 | void setContent(const QUrl& url, QQmlComponent *component, QObject *item); |
104 | |
105 | Q_SIGNALS: |
106 | void statusChanged(QQuickWidget::Status); |
107 | void sceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); |
108 | |
109 | private Q_SLOTS: |
110 | // ### Qt 6: make these truly private slots through Q_PRIVATE_SLOT |
111 | void continueExecute(); |
112 | void createFramebufferObject(); |
113 | void destroyFramebufferObject(); |
114 | void triggerUpdate(); |
115 | void propagateFocusObjectChanged(QObject *focusObject); |
116 | |
117 | protected: |
118 | void resizeEvent(QResizeEvent *) override; |
119 | void timerEvent(QTimerEvent*) override; |
120 | |
121 | void keyPressEvent(QKeyEvent *) override; |
122 | void keyReleaseEvent(QKeyEvent *) override; |
123 | void mousePressEvent(QMouseEvent *) override; |
124 | void mouseReleaseEvent(QMouseEvent *) override; |
125 | void mouseMoveEvent(QMouseEvent *) override; |
126 | void mouseDoubleClickEvent(QMouseEvent *) override; |
127 | |
128 | void showEvent(QShowEvent *) override; |
129 | void hideEvent(QHideEvent *) override; |
130 | |
131 | void focusInEvent(QFocusEvent * event) override; |
132 | void focusOutEvent(QFocusEvent * event) override; |
133 | |
134 | #if QT_CONFIG(wheelevent) |
135 | void wheelEvent(QWheelEvent *) override; |
136 | #endif |
137 | |
138 | #if QT_CONFIG(quick_draganddrop) |
139 | void dragEnterEvent(QDragEnterEvent *) override; |
140 | void dragMoveEvent(QDragMoveEvent *) override; |
141 | void dragLeaveEvent(QDragLeaveEvent *) override; |
142 | void dropEvent(QDropEvent *) override; |
143 | #endif |
144 | |
145 | bool event(QEvent *) override; |
146 | void paintEvent(QPaintEvent *event) override; |
147 | bool focusNextPrevChild(bool next) override; |
148 | |
149 | private: |
150 | Q_DISABLE_COPY(QQuickWidget) |
151 | Q_DECLARE_PRIVATE(QQuickWidget) |
152 | }; |
153 | |
154 | QT_END_NAMESPACE |
155 | |
156 | #endif // QQuickWidget_H |
157 | |