Add more styling options to command line
This commit is contained in:
parent
68983e2fec
commit
66cee1eb09
@ -45,7 +45,7 @@ DeviceControlApplication::DeviceControlApplication(int argc, char *argv[]) : QAp
|
|||||||
qmlRegisterType<NfcThingActionWriter>("Nymea", 1, 0, "NfcThingActionWriter");
|
qmlRegisterType<NfcThingActionWriter>("Nymea", 1, 0, "NfcThingActionWriter");
|
||||||
qmlRegisterSingletonType<NfcHelper>("Nymea", 1, 0, "NfcHelper", NfcHelper::nfcHelperProvider);
|
qmlRegisterSingletonType<NfcHelper>("Nymea", 1, 0, "NfcHelper", NfcHelper::nfcHelperProvider);
|
||||||
|
|
||||||
StyleController *styleController = new StyleController(this);
|
StyleController *styleController = new StyleController("light", this);
|
||||||
|
|
||||||
QQmlFileSelector *styleSelector = new QQmlFileSelector(m_qmlEngine);
|
QQmlFileSelector *styleSelector = new QQmlFileSelector(m_qmlEngine);
|
||||||
styleSelector->setExtraSelectors({styleController->currentStyle()});
|
styleSelector->setExtraSelectors({styleController->currentStyle()});
|
||||||
|
|||||||
@ -91,12 +91,17 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
QCommandLineOption kioskOption = QCommandLineOption({"k", "kiosk"}, "Start the application in kiosk mode.");
|
|
||||||
parser.addOption(kioskOption);
|
|
||||||
QCommandLineOption connectOption = QCommandLineOption({"c", "connect"}, "Connect to nymea:core without discovery.", "host");
|
QCommandLineOption connectOption = QCommandLineOption({"c", "connect"}, "Connect to nymea:core without discovery.", "host");
|
||||||
parser.addOption(connectOption);
|
parser.addOption(connectOption);
|
||||||
|
#ifndef BRANDING
|
||||||
QCommandLineOption styleOption = QCommandLineOption({"s", "style"}, "Override the style. Style in settings will be disabled.", "style");
|
QCommandLineOption styleOption = QCommandLineOption({"s", "style"}, "Override the style. Style in settings will be disabled.", "style");
|
||||||
parser.addOption(styleOption);
|
parser.addOption(styleOption);
|
||||||
|
QCommandLineOption defaultStyleOption = QCommandLineOption({"d", "default-style"}, "The default style to be used if there is no style explicitly selected by the user yet.", "style");
|
||||||
|
defaultStyleOption.setDefaultValue("light");
|
||||||
|
parser.addOption(defaultStyleOption);
|
||||||
|
#endif
|
||||||
|
QCommandLineOption kioskOption = QCommandLineOption({"k", "kiosk"}, "Start the application in kiosk mode.");
|
||||||
|
parser.addOption(kioskOption);
|
||||||
parser.process(application);
|
parser.process(application);
|
||||||
|
|
||||||
// Initialize app log controller as early as possible, but after setting app name etc
|
// Initialize app log controller as early as possible, but after setting app name etc
|
||||||
@ -122,11 +127,16 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QQmlApplicationEngine *engine = new QQmlApplicationEngine();
|
QQmlApplicationEngine *engine = new QQmlApplicationEngine();
|
||||||
|
|
||||||
StyleController styleController;
|
#if defined BRANDING
|
||||||
|
StyleController styleController(BRANDING);
|
||||||
|
styleController.lockToStyle(BRANDING);
|
||||||
|
#else
|
||||||
|
StyleController styleController(parser.value(defaultStyleOption));
|
||||||
if (parser.isSet(styleOption)) {
|
if (parser.isSet(styleOption)) {
|
||||||
qDebug() << "Setting style to" << parser.value(styleOption);
|
qDebug() << "Setting style to" << parser.value(styleOption);
|
||||||
styleController.setCurrentStyle(parser.value(styleOption));
|
styleController.lockToStyle(parser.value(styleOption));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QQmlFileSelector *styleSelector = new QQmlFileSelector(engine);
|
QQmlFileSelector *styleSelector = new QQmlFileSelector(engine);
|
||||||
styleSelector->setExtraSelectors({styleController.currentStyle()});
|
styleSelector->setExtraSelectors({styleController.currentStyle()});
|
||||||
@ -151,11 +161,6 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterSingletonType<AppLogController>("Nymea", 1, 0, "AppLogController", AppLogController::appLogControllerProvider);
|
qmlRegisterSingletonType<AppLogController>("Nymea", 1, 0, "AppLogController", AppLogController::appLogControllerProvider);
|
||||||
qmlRegisterSingletonType(QUrl("qrc:///ui/utils/NymeaUtils.qml"), "Nymea", 1, 0, "NymeaUtils" );
|
qmlRegisterSingletonType(QUrl("qrc:///ui/utils/NymeaUtils.qml"), "Nymea", 1, 0, "NymeaUtils" );
|
||||||
|
|
||||||
#ifdef BRANDING
|
|
||||||
engine->rootContext()->setContextProperty("appBranding", BRANDING);
|
|
||||||
#else
|
|
||||||
engine->rootContext()->setContextProperty("appBranding", "");
|
|
||||||
#endif
|
|
||||||
engine->rootContext()->setContextProperty("appVersion", APP_VERSION);
|
engine->rootContext()->setContextProperty("appVersion", APP_VERSION);
|
||||||
engine->rootContext()->setContextProperty("qtBuildVersion", QT_VERSION_STR);
|
engine->rootContext()->setContextProperty("qtBuildVersion", QT_VERSION_STR);
|
||||||
engine->rootContext()->setContextProperty("qtVersion", qVersion());
|
engine->rootContext()->setContextProperty("qtVersion", qVersion());
|
||||||
|
|||||||
@ -36,22 +36,16 @@
|
|||||||
|
|
||||||
#include "stylecontroller.h"
|
#include "stylecontroller.h"
|
||||||
|
|
||||||
StyleController::StyleController(QObject *parent) : QObject(parent)
|
StyleController::StyleController(const QString &defaultStyle, QObject *parent) : QObject(parent),
|
||||||
|
m_defaultStyle(defaultStyle)
|
||||||
{
|
{
|
||||||
#ifdef BRANDING
|
|
||||||
QQuickStyle::setStyle(QString(":/styles/%1").arg(BRANDING));
|
|
||||||
#else
|
|
||||||
QQuickStyle::setStyle(QString(":/styles/%1").arg(currentStyle()));
|
QQuickStyle::setStyle(QString(":/styles/%1").arg(currentStyle()));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString StyleController::currentStyle() const
|
QString StyleController::currentStyle() const
|
||||||
{
|
{
|
||||||
#ifdef BRANDING
|
|
||||||
return BRANDING;
|
|
||||||
#endif
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString currentSetting = settings.value("style", "light").toString();
|
QString currentSetting = settings.value("style", m_defaultStyle).toString();
|
||||||
// ensure style is available
|
// ensure style is available
|
||||||
if (allStyles().contains(currentSetting)) {
|
if (allStyles().contains(currentSetting)) {
|
||||||
return currentSetting;
|
return currentSetting;
|
||||||
@ -61,6 +55,10 @@ QString StyleController::currentStyle() const
|
|||||||
|
|
||||||
void StyleController::setCurrentStyle(const QString ¤tStyle)
|
void StyleController::setCurrentStyle(const QString ¤tStyle)
|
||||||
{
|
{
|
||||||
|
if (m_locked) {
|
||||||
|
qDebug() << "Ignoring style change request. Style is locked to" << this->currentStyle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!allStyles().contains(currentStyle)) {
|
if (!allStyles().contains(currentStyle)) {
|
||||||
qWarning().nospace() << "No style named: " << currentStyle << ". Available styles are: " << allStyles().join(", ");
|
qWarning().nospace() << "No style named: " << currentStyle << ". Available styles are: " << allStyles().join(", ");
|
||||||
return;
|
return;
|
||||||
@ -73,6 +71,12 @@ void StyleController::setCurrentStyle(const QString ¤tStyle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StyleController::lockToStyle(const QString &style)
|
||||||
|
{
|
||||||
|
setCurrentStyle(style);
|
||||||
|
m_locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
QStringList StyleController::allStyles() const
|
QStringList StyleController::allStyles() const
|
||||||
{
|
{
|
||||||
QDir dir(":/styles/");
|
QDir dir(":/styles/");
|
||||||
@ -80,6 +84,11 @@ QStringList StyleController::allStyles() const
|
|||||||
return dir.entryList(QDir::Dirs);
|
return dir.entryList(QDir::Dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StyleController::locked() const
|
||||||
|
{
|
||||||
|
return m_locked;
|
||||||
|
}
|
||||||
|
|
||||||
void StyleController::setSystemFont(const QFont &font)
|
void StyleController::setSystemFont(const QFont &font)
|
||||||
{
|
{
|
||||||
QApplication::setFont(font);
|
QApplication::setFont(font);
|
||||||
|
|||||||
@ -38,19 +38,26 @@ class StyleController : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString currentStyle READ currentStyle WRITE setCurrentStyle NOTIFY currentStyleChanged)
|
Q_PROPERTY(QString currentStyle READ currentStyle WRITE setCurrentStyle NOTIFY currentStyleChanged)
|
||||||
Q_PROPERTY(QStringList allStyles READ allStyles CONSTANT)
|
Q_PROPERTY(QStringList allStyles READ allStyles CONSTANT)
|
||||||
|
Q_PROPERTY(bool locked READ locked CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StyleController(QObject *parent = nullptr);
|
explicit StyleController(const QString &defaultStyle, QObject *parent = nullptr);
|
||||||
|
|
||||||
QString currentStyle() const;
|
QString currentStyle() const;
|
||||||
void setCurrentStyle(const QString ¤tStyle);
|
void setCurrentStyle(const QString ¤tStyle);
|
||||||
|
void lockToStyle(const QString &style);
|
||||||
|
|
||||||
QStringList allStyles() const;
|
QStringList allStyles() const;
|
||||||
|
bool locked() const;
|
||||||
|
|
||||||
Q_INVOKABLE void setSystemFont(const QFont &font);
|
Q_INVOKABLE void setSystemFont(const QFont &font);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void currentStyleChanged();
|
void currentStyleChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_defaultStyle;
|
||||||
|
bool m_locked = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STYLECONTROLLER_H
|
#endif // STYLECONTROLLER_H
|
||||||
|
|||||||
@ -85,7 +85,6 @@ ApplicationWindow {
|
|||||||
property alias windowHeight: app.height
|
property alias windowHeight: app.height
|
||||||
property bool returnToHome: false
|
property bool returnToHome: false
|
||||||
property string graphStyle: "bars"
|
property string graphStyle: "bars"
|
||||||
property string style: "light"
|
|
||||||
property bool showHiddenOptions: false
|
property bool showHiddenOptions: false
|
||||||
property string cloudEnvironment: "Community"
|
property string cloudEnvironment: "Community"
|
||||||
property bool showConnectionTabs: false
|
property bool showConnectionTabs: false
|
||||||
|
|||||||
@ -282,10 +282,15 @@ Item {
|
|||||||
PlatformHelper.requestPermissions();
|
PlatformHelper.requestPermissions();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
var clientId = PlatformHelper.deviceSerial + "+io.guh.nymeaapp";
|
||||||
|
if ("branding" in app) {
|
||||||
|
clientId += "-" + app.branding;
|
||||||
|
}
|
||||||
|
|
||||||
AWSClient.registerPushNotificationEndpoint(
|
AWSClient.registerPushNotificationEndpoint(
|
||||||
PushNotifications.token,
|
PushNotifications.token,
|
||||||
PlatformHelper.machineHostname,
|
PlatformHelper.machineHostname,
|
||||||
PlatformHelper.deviceSerial + "+io.guh.nymeaapp" + (appBranding.length > 0 ? "-" + appBranding : ""),
|
clientId,
|
||||||
PlatformHelper.deviceManufacturer,
|
PlatformHelper.deviceManufacturer,
|
||||||
PlatformHelper.deviceModel);
|
PlatformHelper.deviceModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ SettingsPageBase {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: app.margins
|
Layout.leftMargin: app.margins
|
||||||
Layout.rightMargin: app.margins
|
Layout.rightMargin: app.margins
|
||||||
visible: appBranding.length === 0
|
visible: !styleController.locked
|
||||||
Label {
|
Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
text: "Style"
|
text: "Style"
|
||||||
|
|||||||
Reference in New Issue
Block a user