Browse Source

Merge pull request #1260 from DonLakeFlyer/UIWork

Qml Test dialog theme selection support
QGC4.4
Don Gagne 10 years ago
parent
commit
fd6b895bfe
  1. 15
      src/QGCQmlWidgetHolder.cpp
  2. 3
      src/QGCQmlWidgetHolder.h
  3. 18
      src/QGCQuickWidget.cc
  4. 4
      src/QGCQuickWidget.h
  5. 19
      src/QmlControls/QmlTest.qml

15
src/QGCQmlWidgetHolder.cpp

@ -25,7 +25,6 @@ @@ -25,7 +25,6 @@
/// @author Don Gagne <don@thegagnes.com>
#include "QGCQmlWidgetHolder.h"
#include "QGCMessageBox.h"
QGCQmlWidgetHolder::QGCQmlWidgetHolder(QWidget *parent) :
QWidget(parent)
@ -46,17 +45,5 @@ void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot) @@ -46,17 +45,5 @@ void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot)
bool QGCQmlWidgetHolder::setSource(const QUrl& qmlUrl)
{
_ui.qmlWidget->setSource(qmlUrl);
if (_ui.qmlWidget->status() != QQuickWidget::Ready) {
QString errorList;
foreach (QQmlError error, _ui.qmlWidget->errors()) {
errorList += error.toString();
errorList += "\n";
}
QGCMessageBox::warning(tr("Qml Error"), tr("Source not ready: %1\nErrors:\n%2").arg(_ui.qmlWidget->status()).arg(errorList));
return false;
}
return true;
return _ui.qmlWidget->setSource(qmlUrl);
}

3
src/QGCQmlWidgetHolder.h

@ -49,7 +49,8 @@ public: @@ -49,7 +49,8 @@ public:
/// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot);
/// Sets the QML into the control
/// Sets the QML into the control. Will display errors message box if error occurs loading source.
/// @return true: source loaded, false: source not loaded, errors occured
bool setSource(const QUrl& qmlUrl);
private:

18
src/QGCQuickWidget.cc

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
#include "QGCQuickWidget.h"
#include "AutoPilotPluginManager.h"
#include "QGCMessageBox.h"
#include <QQmlContext>
#include <QQmlEngine>
@ -43,3 +44,20 @@ void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot) @@ -43,3 +44,20 @@ void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot)
{
rootContext()->setContextProperty("autopilot", autoPilot);
}
bool QGCQuickWidget::setSource(const QUrl& qmlUrl)
{
QQuickWidget::setSource(qmlUrl);
if (status() != Ready) {
QString errorList;
foreach (QQmlError error, errors()) {
errorList += error.toString();
errorList += "\n";
}
QGCMessageBox::warning(tr("Qml Error"), tr("Source not ready: Status(%1)\nErrors:\n%2").arg(status()).arg(errorList));
return false;
}
return true;
}

4
src/QGCQuickWidget.h

@ -42,6 +42,10 @@ public: @@ -42,6 +42,10 @@ public:
/// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot);
/// Sets the QML into the control. Will display errors message box if error occurs loading source.
/// @return true: source loaded, false: source not loaded, errors occured
bool setSource(const QUrl& qmlUrl);
};
#endif

19
src/QmlControls/QmlTest.qml

@ -11,6 +11,24 @@ Rectangle { @@ -11,6 +11,24 @@ Rectangle {
property var palette: QGCPalette { colorGroupEnabled: true }
color: palette.window
Column {
Row {
ExclusiveGroup { id: themeGroup }
QGCRadioButton {
text: "Light"
exclusiveGroup: themeGroup
onClicked: { palette.globalTheme = QGCPalette.Light }
}
QGCRadioButton {
text: "Dark"
exclusiveGroup: themeGroup
onClicked: { palette.globalTheme = QGCPalette.Dark }
}
}
Row {
spacing: 30
@ -468,3 +486,4 @@ Rectangle { @@ -468,3 +486,4 @@ Rectangle {
}
}
}
}

Loading…
Cancel
Save