From f50b692f818e1d51a5b456a8619e2bdffe3d2a2a Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Sun, 25 Jun 2017 17:04:38 -0400 Subject: [PATCH] Allow plugins to create (native) root window --- src/QGCApplication.cc | 7 ++----- src/api/QGCCorePlugin.cc | 12 ++++++++++++ src/api/QGCCorePlugin.h | 6 +++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 6709e50..7abc033 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -79,6 +79,7 @@ #include "QGCMapPolygon.h" #include "ParameterManager.h" #include "SettingsManager.h" +#include "QGCCorePlugin.h" #ifndef NO_SERIAL_LINK #include "SerialLink.h" @@ -395,11 +396,7 @@ bool QGCApplication::_initForNormalAppBoot(void) connect(this, &QGCApplication::lastWindowClosed, this, QGCApplication::quit); #ifdef __mobile__ - _qmlAppEngine = new QQmlApplicationEngine(this); - _qmlAppEngine->addImportPath("qrc:/qml"); - _qmlAppEngine->rootContext()->setContextProperty("joystickManager", toolbox()->joystickManager()); - _qmlAppEngine->rootContext()->setContextProperty("debugMessageModel", AppMessages::getModel()); - _qmlAppEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml"))); + _qmlAppEngine = toolbox()->corePlugin()->createRootWindow(this); #else // Start the user interface MainWindow* mainWindow = MainWindow::_create(); diff --git a/src/api/QGCCorePlugin.cc b/src/api/QGCCorePlugin.cc index dfb444d..c450528 100644 --- a/src/api/QGCCorePlugin.cc +++ b/src/api/QGCCorePlugin.cc @@ -7,11 +7,13 @@ * ****************************************************************************/ +#include "QGCApplication.h" #include "QGCCorePlugin.h" #include "QGCOptions.h" #include "QGCSettings.h" #include "FactMetaData.h" #include "SettingsManager.h" +#include "AppMessages.h" #include #include @@ -213,3 +215,13 @@ void QGCCorePlugin::valuesWidgetDefaultSettings(QStringList& largeValues, QStrin Q_UNUSED(smallValues); largeValues << "Vehicle.altitudeRelative" << "Vehicle.groundSpeed" << "Vehicle.flightTime"; } + +QQmlApplicationEngine* QGCCorePlugin::createRootWindow(QObject *parent) +{ + QQmlApplicationEngine* pEngine = new QQmlApplicationEngine(parent); + pEngine->addImportPath("qrc:/qml"); + pEngine->rootContext()->setContextProperty("joystickManager", qgcApp()->toolbox()->joystickManager()); + pEngine->rootContext()->setContextProperty("debugMessageModel", AppMessages::getModel()); + pEngine->load(QUrl(QStringLiteral("qrc:/qml/MainWindowNative.qml"))); + return pEngine; +} diff --git a/src/api/QGCCorePlugin.h b/src/api/QGCCorePlugin.h index 567e851..9e996f7 100644 --- a/src/api/QGCCorePlugin.h +++ b/src/api/QGCCorePlugin.h @@ -27,6 +27,7 @@ class QGCSettings; class QGCCorePlugin_p; class FactMetaData; class QGeoPositionInfoSource; +class QQmlApplicationEngine; class QGCCorePlugin : public QGCTool { @@ -83,9 +84,12 @@ public: /// Allows a plugin to override the specified color name from the palette virtual void paletteOverride(QString colorName, QGCPalette::PaletteColorInfo_t& colorInfo); - /// Allows the plugin the override the default settings for the Values Widget large and small values + /// Allows the plugin to override the default settings for the Values Widget large and small values virtual void valuesWidgetDefaultSettings(QStringList& largeValues, QStringList& smallValues); + /// Allows the plugin to override the creation of the root (native) window. + virtual QQmlApplicationEngine* createRootWindow(QObject* parent); + bool showTouchAreas(void) const { return _showTouchAreas; } bool showAdvancedUI(void) const { return _showAdvancedUI; } void setShowTouchAreas(bool show);