2 ******************************************************************************
4 * @file quickwidgetproxy.cpp
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2015.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "quickwidgetproxy.h"
31 #include <QQmlContext>
35 * Note: QQuickWidget is an alternative to using QQuickView and QWidget::createWindowContainer().
36 * The restrictions on stacking order do not apply, making QQuickWidget the more flexible alternative,
37 * behaving more like an ordinary widget. This comes at the expense of performance.
38 * Unlike QQuickWindow and QQuickView, QQuickWidget involves rendering into OpenGL framebuffer objects.
39 * This will naturally carry a minor performance hit.
41 * Note: Using QQuickWidget disables the threaded render loop on all platforms.
42 * This means that some of the benefits of threaded rendering, for example Animator classes
43 * and vsync driven animations, will not be available.
45 * Note: Avoid calling winId() on a QQuickWidget. This function triggers the creation of a native window,
46 * resulting in reduced performance and possibly rendering glitches.
47 * The entire purpose of QQuickWidget is to render Quick scenes without a separate native window,
48 * hence making it a native widget should always be avoided.
50 QuickWidgetProxy::QuickWidgetProxy(QWidget
*parent
) : QObject(parent
)
60 m_quickWidget
= new QQuickWidget(parent
);
61 m_quickWidget
->setResizeMode(QQuickWidget::SizeRootObjectToView
);
63 void (QuickWidgetProxy::*f
)(QQuickWidget::Status
) = &QuickWidgetProxy::onStatusChanged
;
64 connect(m_quickWidget
, &QQuickWidget::statusChanged
, this, f
);
65 connect(m_quickWidget
, &QQuickWidget::sceneGraphError
, this, &QuickWidgetProxy::onSceneGraphError
);
67 m_quickView
= new QQuickView();
68 m_quickView
->setResizeMode(QQuickView::SizeRootObjectToView
);
69 m_container
= QWidget::createWindowContainer(m_quickView
, parent
);
70 m_container
->setMinimumSize(64, 64);
71 m_container
->setSizePolicy(QSizePolicy::MinimumExpanding
, QSizePolicy::MinimumExpanding
);
73 void (QuickWidgetProxy::*f
)(QQuickView::Status
) = &QuickWidgetProxy::onStatusChanged
;
74 connect(m_quickView
, &QQuickView::statusChanged
, this, f
);
75 connect(m_quickView
, &QQuickView::sceneGraphError
, this, &QuickWidgetProxy::onSceneGraphError
);
79 QuickWidgetProxy::~QuickWidgetProxy()
90 QWidget
*QuickWidgetProxy::widget()
99 QQmlEngine
*QuickWidgetProxy::engine() const
102 return m_quickWidget
->engine();
104 return m_quickView
->engine();
108 void QuickWidgetProxy::setSource(const QUrl
&url
)
111 m_quickWidget
->setSource(url
);
113 m_quickView
->setSource(url
);
117 QList
<QQmlError
> QuickWidgetProxy::errors() const
120 return m_quickWidget
->errors();
122 return m_quickView
->errors();
126 void QuickWidgetProxy::onStatusChanged(QQuickWidget::Status status
)
129 case QQuickWidget::Null
:
130 qWarning() << "QuickWidgetProxy - status Null";
132 case QQuickWidget::Ready
:
133 // qDebug() << "QuickWidgetProxy - status Ready";
135 case QQuickWidget::Loading
:
136 // qDebug() << "QuickWidgetProxy - status Loading";
138 case QQuickWidget::Error
:
139 qWarning() << "QuickWidgetProxy - status Error";
140 foreach(const QQmlError
&error
, errors()) {
141 qWarning() << error
.description();
147 void QuickWidgetProxy::onStatusChanged(QQuickView::Status status
)
150 case QQuickView::Null
:
151 qWarning() << "QuickWidgetProxy - status Null";
153 case QQuickView::Ready
:
154 // qDebug() << "QuickWidgetProxy - status Ready";
156 case QQuickView::Loading
:
157 // qDebug() << "QuickWidgetProxy - status Loading";
159 case QQuickView::Error
:
160 qWarning() << "QuickWidgetProxy - status Error";
161 foreach(const QQmlError
&error
, errors()) {
162 qWarning() << error
.description();
168 void QuickWidgetProxy::onSceneGraphError(QQuickWindow::SceneGraphError error
, const QString
&message
)
170 qWarning() << QString("Scenegraph error %1: %2").arg(error
).arg(message
);