add a styleController to have better control over styles
This commit is contained in:
parent
5922a48b65
commit
256149c5de
15
mea/main.cpp
15
mea/main.cpp
@ -53,6 +53,7 @@
|
||||
#include "models/eventdescriptorparamsfiltermodel.h"
|
||||
#include "basicconfiguration.h"
|
||||
#include "wifisetup/networkmanagercontroler.h"
|
||||
#include "stylecontroller.h"
|
||||
|
||||
static QObject* interfacesModel_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
@ -166,15 +167,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
Engine::instance();
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QQmlApplicationEngine *engine = new QQmlApplicationEngine();
|
||||
#ifdef BRANDING
|
||||
engine.rootContext()->setContextProperty("appBranding", BRANDING);
|
||||
QQuickStyle::setStyle(QString(":/styles/%1").arg(BRANDING));
|
||||
engine->rootContext()->setContextProperty("appBranding", BRANDING);
|
||||
#else
|
||||
QSettings settings;
|
||||
QQuickStyle::setStyle(":/styles/" + settings.value("style", "light").toString());
|
||||
engine->rootContext()->setContextProperty("appBranding", "");
|
||||
#endif
|
||||
engine.load(QUrl(QLatin1String("qrc:/ui/main.qml")));
|
||||
|
||||
StyleController styleController;
|
||||
engine->rootContext()->setContextProperty("styleController", &styleController);
|
||||
|
||||
engine->load(QUrl(QLatin1String("qrc:/ui/main.qml")));
|
||||
|
||||
return application.exec();
|
||||
}
|
||||
|
||||
@ -45,7 +45,8 @@ HEADERS += engine.h \
|
||||
wifisetup/wirelessaccesspoint.h \
|
||||
wifisetup/wirelessaccesspoints.h \
|
||||
wifisetup/wirelesssetupmanager.h \
|
||||
wifisetup/networkmanagercontroler.h
|
||||
wifisetup/networkmanagercontroler.h \
|
||||
stylecontroller.h
|
||||
|
||||
|
||||
SOURCES += main.cpp \
|
||||
@ -87,7 +88,8 @@ SOURCES += main.cpp \
|
||||
wifisetup/wirelessaccesspoint.cpp \
|
||||
wifisetup/wirelessaccesspoints.cpp \
|
||||
wifisetup/wirelesssetupmanager.cpp \
|
||||
wifisetup/networkmanagercontroler.cpp
|
||||
wifisetup/networkmanagercontroler.cpp \
|
||||
stylecontroller.cpp
|
||||
|
||||
withavahi {
|
||||
DEFINES += WITH_AVAHI
|
||||
|
||||
38
mea/stylecontroller.cpp
Normal file
38
mea/stylecontroller.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <QSettings>
|
||||
#include <QQuickStyle>
|
||||
#include <QDir>
|
||||
|
||||
#include "stylecontroller.h"
|
||||
|
||||
StyleController::StyleController(QObject *parent) : QObject(parent)
|
||||
{
|
||||
#ifdef BRANDING
|
||||
QQuickStyle::setStyle(QString(":/styles/%1").arg(BRANDING));
|
||||
#else
|
||||
QQuickStyle::setStyle(QString(":/styles/%1").arg(currentStyle()));
|
||||
#endif
|
||||
}
|
||||
|
||||
QString StyleController::currentStyle() const
|
||||
{
|
||||
#ifdef BRANDING
|
||||
return BRANDING;
|
||||
#endif
|
||||
QSettings settings;
|
||||
return settings.value("style", "light").toString();
|
||||
}
|
||||
|
||||
void StyleController::setCurrentStyle(const QString ¤tStyle)
|
||||
{
|
||||
QSettings settings;
|
||||
if (settings.value("style").toString() != currentStyle) {
|
||||
settings.setValue("style", currentStyle);
|
||||
emit currentStyleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList StyleController::allStyles() const
|
||||
{
|
||||
QDir dir(":/styles/");
|
||||
return dir.entryList(QDir::Dirs);
|
||||
}
|
||||
25
mea/stylecontroller.h
Normal file
25
mea/stylecontroller.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef STYLECONTROLLER_H
|
||||
#define STYLECONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class StyleController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString currentStyle READ currentStyle WRITE setCurrentStyle NOTIFY currentStyleChanged)
|
||||
Q_PROPERTY(QStringList allStyles READ allStyles CONSTANT)
|
||||
|
||||
public:
|
||||
explicit StyleController(QObject *parent = nullptr);
|
||||
|
||||
QString currentStyle() const;
|
||||
void setCurrentStyle(const QString ¤tStyle);
|
||||
|
||||
QStringList allStyles() const;
|
||||
|
||||
signals:
|
||||
void currentStyleChanged();
|
||||
|
||||
};
|
||||
|
||||
#endif // STYLECONTROLLER_H
|
||||
@ -1,7 +1,6 @@
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 2.1
|
||||
import QtQuick.Layouts 1.2
|
||||
|
||||
import "components"
|
||||
import Mea 1.0
|
||||
|
||||
@ -22,6 +21,7 @@ Page {
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: app.margins
|
||||
|
||||
BusyIndicator {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
@ -77,5 +77,4 @@ Page {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -10,40 +10,13 @@ Page {
|
||||
|
||||
readonly property bool haveHosts: discovery.discoveryModel.count > 0
|
||||
|
||||
header: GuhHeader {
|
||||
text: qsTr("Connect nymea")
|
||||
backButtonVisible: false
|
||||
menuButtonVisible: true
|
||||
onMenuPressed: connectionMenu.open()
|
||||
}
|
||||
|
||||
Menu {
|
||||
id: connectionMenu
|
||||
width: implicitWidth + app.margins
|
||||
|
||||
IconMenuItem {
|
||||
iconSource: "../images/network-vpn.svg"
|
||||
text: qsTr("Manual connect")
|
||||
onTriggered: pageStack.push(manualConnectPage)
|
||||
}
|
||||
|
||||
MenuSeparator {}
|
||||
|
||||
IconMenuItem {
|
||||
iconSource: "../images/bluetooth.svg"
|
||||
text: qsTr("Wireless setup")
|
||||
onTriggered: pageStack.push(Qt.resolvedUrl("BluetoothDiscoveryPage.qml"))
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
print("completed connectPage. last connected host:", settings.lastConnectedHost)
|
||||
if (settings.lastConnectedHost.length > 0) {
|
||||
pageStack.push(connectingPage)
|
||||
Engine.connection.connect(settings.lastConnectedHost)
|
||||
} else {
|
||||
pageStack.push(discoveryPage)
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,130 +30,170 @@ Page {
|
||||
}
|
||||
onConnectionError: {
|
||||
pageStack.pop(root)
|
||||
pageStack.push(discoveryPage)
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.topMargin: app.bigMargins
|
||||
spacing: app.margins
|
||||
Component {
|
||||
id: discoveryPage
|
||||
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
spacing: app.margins
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.haveHosts ? qsTr("Oh, look!") : qsTr("Uh oh")
|
||||
//color: "black"
|
||||
font.pixelSize: app.largeFont
|
||||
Page {
|
||||
header: GuhHeader {
|
||||
text: qsTr("Connect nymea")
|
||||
backButtonVisible: false
|
||||
menuButtonVisible: true
|
||||
onMenuPressed: connectionMenu.open()
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.haveHosts ?
|
||||
qsTr("There are %1 nymea boxes in your network! Which one would you like to use?").arg(discovery.discoveryModel.count)
|
||||
: qsTr("There doesn't seem to be a nymea box installed in your network. Please make sure your nymea box is correctly set up and connected.")
|
||||
wrapMode: Text.WordWrap
|
||||
Timer {
|
||||
id: startupTimer
|
||||
interval: 5000
|
||||
repeat: false
|
||||
running: true
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 1
|
||||
color: Material.accent
|
||||
}
|
||||
Menu {
|
||||
id: connectionMenu
|
||||
width: implicitWidth + app.margins
|
||||
|
||||
ListView {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
model: discovery.discoveryModel
|
||||
clip: true
|
||||
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
height: app.delegateHeight
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: app.margins
|
||||
Label {
|
||||
text: model.name
|
||||
}
|
||||
Label {
|
||||
text: model.hostAddress
|
||||
font.pixelSize: app.smallFont
|
||||
}
|
||||
IconMenuItem {
|
||||
iconSource: "../images/network-vpn.svg"
|
||||
text: qsTr("Manual connect")
|
||||
onTriggered: pageStack.push(manualConnectPage)
|
||||
}
|
||||
onClicked: {
|
||||
print("Should connect to", model.nymeaRpcUrl)
|
||||
Engine.connection.connect(model.nymeaRpcUrl)
|
||||
pageStack.push(connectingPage)
|
||||
|
||||
MenuSeparator {}
|
||||
|
||||
IconMenuItem {
|
||||
iconSource: "../images/bluetooth.svg"
|
||||
text: qsTr("Wireless setup")
|
||||
onTriggered: pageStack.push(Qt.resolvedUrl("BluetoothDiscoveryPage.qml"))
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: app.margins
|
||||
visible: !root.haveHosts
|
||||
|
||||
Label {
|
||||
text: qsTr("Searching for nymea boxes...")
|
||||
ColumnLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
spacing: app.margins
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.haveHosts ? qsTr("Oh, look!") : startupTimer.running ? qsTr("Just a moment...") : qsTr("Uh oh")
|
||||
//color: "black"
|
||||
font.pixelSize: app.largeFont
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: root.haveHosts ?
|
||||
qsTr("There are %1 nymea boxes in your network! Which one would you like to use?").arg(discovery.discoveryModel.count)
|
||||
: startupTimer.running ? qsTr("We haven't found any nymea boxes in your network yet.")
|
||||
: qsTr("There doesn't seem to be a nymea box installed in your network. Please make sure your nymea box is correctly set up and connected.")
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
running: visible
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 1
|
||||
color: Material.accent
|
||||
}
|
||||
|
||||
ListView {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
model: discovery.discoveryModel
|
||||
clip: true
|
||||
|
||||
delegate: ItemDelegate {
|
||||
width: parent.width
|
||||
height: app.delegateHeight
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: app.margins
|
||||
Label {
|
||||
text: model.name
|
||||
}
|
||||
Label {
|
||||
text: model.hostAddress
|
||||
font.pixelSize: app.smallFont
|
||||
}
|
||||
}
|
||||
onClicked: {
|
||||
print("Should connect to", model.nymeaRpcUrl)
|
||||
Engine.connection.connect(model.nymeaRpcUrl)
|
||||
pageStack.push(connectingPage)
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: app.margins
|
||||
visible: !root.haveHosts
|
||||
|
||||
Label {
|
||||
text: qsTr("Searching for nymea boxes...")
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
running: visible
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 1
|
||||
color: Material.accent
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
visible: root.haveHosts
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Not the ones you're looking for? We're looking for more!")
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
BusyIndicator { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 1
|
||||
color: Material.accent
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
visible: root.haveHosts
|
||||
Label {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Not the ones you're looking for? We're looking for more!")
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
BusyIndicator { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Component {
|
||||
id: manualConnectPage
|
||||
|
||||
Page {
|
||||
|
||||
header: GuhHeader {
|
||||
text: qsTr("Manual connect to nymea")
|
||||
text: qsTr("Manual connection")
|
||||
onBackPressed: pageStack.pop()
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors { left: parent.left; top: parent.top; right: parent.right }
|
||||
anchors.margins: app.margins
|
||||
spacing: app.margins
|
||||
|
||||
GridLayout {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
columns: 2
|
||||
|
||||
Label {
|
||||
text: qsTr("Protocol")
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: connectionTypeComboBox
|
||||
Layout.fillWidth: true
|
||||
Layout.columnSpan: 2
|
||||
model: [ qsTr("TCP"), qsTr("Websocket") ]
|
||||
}
|
||||
|
||||
@ -264,7 +277,7 @@ Page {
|
||||
spacing: app.margins
|
||||
|
||||
Label {
|
||||
text: qsTr("Connecting to your nymea box...")
|
||||
text: qsTr("Trying to connect...")
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: app.largeFont
|
||||
Layout.fillWidth: true
|
||||
@ -275,7 +288,8 @@ Page {
|
||||
Layout.fillWidth: true
|
||||
onClicked: {
|
||||
Engine.connection.disconnect()
|
||||
pageStack.pop();
|
||||
pageStack.pop(root);
|
||||
pageStack.push(discoveryPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,20 +68,19 @@ Page {
|
||||
text: "Style"
|
||||
}
|
||||
ComboBox {
|
||||
model: ["light", "dark", "maveo"]
|
||||
currentIndex: {
|
||||
switch (settings.style) {
|
||||
case "light":
|
||||
return 0;
|
||||
case "dark":
|
||||
return 1;
|
||||
case "maveo":
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
model: styleController.allStyles
|
||||
currentIndex: styleController.allStyles.indexOf(styleController.currentStyle)
|
||||
|
||||
onActivated: {
|
||||
settings.style = model[index]
|
||||
styleController.currentStyle = model[index]
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: styleController
|
||||
onCurrentStyleChanged: {
|
||||
var popup = styleChangedDialog.createObject(root)
|
||||
popup.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,6 +166,7 @@ Page {
|
||||
Button {
|
||||
id: debugServerButton
|
||||
Layout.fillWidth: true
|
||||
Layout.margins: app.margins
|
||||
visible: debugServerEnabledSwitch.checked
|
||||
text: qsTr("Open debug interface")
|
||||
onClicked: Qt.openUrlExternally("http://" + Engine.connection.hostAddress + "/debug")
|
||||
@ -192,4 +192,30 @@ Page {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: styleChangedDialog
|
||||
Dialog {
|
||||
width: Math.min(parent.width * .8, contentLabel.implicitWidth)
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
modal: true
|
||||
|
||||
title: qsTr("Style changed")
|
||||
|
||||
standardButtons: Dialog.Ok
|
||||
|
||||
ColumnLayout {
|
||||
id: content
|
||||
anchors { left: parent.left; top: parent.top; right: parent.right }
|
||||
|
||||
Label {
|
||||
id: contentLabel
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
text: qsTr("The application needs to be restarted for style changes to take effect.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,14 @@ ApplicationWindow {
|
||||
height: 580
|
||||
visibility: settings.viewMode
|
||||
font: Qt.application.font
|
||||
title: {
|
||||
switch (appBranding) {
|
||||
case "maveo":
|
||||
return qsTr("Maveo Pro Box Dashboard")
|
||||
default:
|
||||
return "Mea";
|
||||
}
|
||||
}
|
||||
|
||||
property int margins: 14
|
||||
property int bigMargins: 20
|
||||
@ -109,7 +117,10 @@ ApplicationWindow {
|
||||
|
||||
onClosing: {
|
||||
if (Qt.platform.os == "android") {
|
||||
if (pageStack.depth > 1) {
|
||||
// If we're connected, allow going back up to MainPage
|
||||
if ((Engine.jsonRpcClient.connected && pageStack.depth > 1)
|
||||
// if we're not connected, only allow using the back button in wizards
|
||||
|| (!Engine.jsonRpcClient.connected && pageStack.depth > 3)) {
|
||||
close.accepted = false;
|
||||
pageStack.pop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user