Add more styling options to command line

This commit is contained in:
Michael Zanetti 2020-12-09 00:47:30 +01:00
parent 68983e2fec
commit 66cee1eb09
7 changed files with 48 additions and 23 deletions

View File

@ -45,7 +45,7 @@ DeviceControlApplication::DeviceControlApplication(int argc, char *argv[]) : QAp
qmlRegisterType<NfcThingActionWriter>("Nymea", 1, 0, "NfcThingActionWriter");
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);
styleSelector->setExtraSelectors({styleController->currentStyle()});

View File

@ -91,12 +91,17 @@ int main(int argc, char *argv[])
QCommandLineParser parser;
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");
parser.addOption(connectOption);
#ifndef BRANDING
QCommandLineOption styleOption = QCommandLineOption({"s", "style"}, "Override the style. Style in settings will be disabled.", "style");
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);
// 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();
StyleController styleController;
#if defined BRANDING
StyleController styleController(BRANDING);
styleController.lockToStyle(BRANDING);
#else
StyleController styleController(parser.value(defaultStyleOption));
if (parser.isSet(styleOption)) {
qDebug() << "Setting style to" << parser.value(styleOption);
styleController.setCurrentStyle(parser.value(styleOption));
styleController.lockToStyle(parser.value(styleOption));
}
#endif
QQmlFileSelector *styleSelector = new QQmlFileSelector(engine);
styleSelector->setExtraSelectors({styleController.currentStyle()});
@ -151,11 +161,6 @@ int main(int argc, char *argv[])
qmlRegisterSingletonType<AppLogController>("Nymea", 1, 0, "AppLogController", AppLogController::appLogControllerProvider);
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("qtBuildVersion", QT_VERSION_STR);
engine->rootContext()->setContextProperty("qtVersion", qVersion());

View File

@ -36,22 +36,16 @@
#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()));
#endif
}
QString StyleController::currentStyle() const
{
#ifdef BRANDING
return BRANDING;
#endif
QSettings settings;
QString currentSetting = settings.value("style", "light").toString();
QString currentSetting = settings.value("style", m_defaultStyle).toString();
// ensure style is available
if (allStyles().contains(currentSetting)) {
return currentSetting;
@ -61,6 +55,10 @@ QString StyleController::currentStyle() const
void StyleController::setCurrentStyle(const QString &currentStyle)
{
if (m_locked) {
qDebug() << "Ignoring style change request. Style is locked to" << this->currentStyle();
return;
}
if (!allStyles().contains(currentStyle)) {
qWarning().nospace() << "No style named: " << currentStyle << ". Available styles are: " << allStyles().join(", ");
return;
@ -73,6 +71,12 @@ void StyleController::setCurrentStyle(const QString &currentStyle)
}
}
void StyleController::lockToStyle(const QString &style)
{
setCurrentStyle(style);
m_locked = true;
}
QStringList StyleController::allStyles() const
{
QDir dir(":/styles/");
@ -80,6 +84,11 @@ QStringList StyleController::allStyles() const
return dir.entryList(QDir::Dirs);
}
bool StyleController::locked() const
{
return m_locked;
}
void StyleController::setSystemFont(const QFont &font)
{
QApplication::setFont(font);

View File

@ -38,19 +38,26 @@ class StyleController : public QObject
Q_OBJECT
Q_PROPERTY(QString currentStyle READ currentStyle WRITE setCurrentStyle NOTIFY currentStyleChanged)
Q_PROPERTY(QStringList allStyles READ allStyles CONSTANT)
Q_PROPERTY(bool locked READ locked CONSTANT)
public:
explicit StyleController(QObject *parent = nullptr);
explicit StyleController(const QString &defaultStyle, QObject *parent = nullptr);
QString currentStyle() const;
void setCurrentStyle(const QString &currentStyle);
void lockToStyle(const QString &style);
QStringList allStyles() const;
bool locked() const;
Q_INVOKABLE void setSystemFont(const QFont &font);
signals:
void currentStyleChanged();
private:
QString m_defaultStyle;
bool m_locked = false;
};
#endif // STYLECONTROLLER_H

View File

@ -85,7 +85,6 @@ ApplicationWindow {
property alias windowHeight: app.height
property bool returnToHome: false
property string graphStyle: "bars"
property string style: "light"
property bool showHiddenOptions: false
property string cloudEnvironment: "Community"
property bool showConnectionTabs: false

View File

@ -282,10 +282,15 @@ Item {
PlatformHelper.requestPermissions();
}
} else {
var clientId = PlatformHelper.deviceSerial + "+io.guh.nymeaapp";
if ("branding" in app) {
clientId += "-" + app.branding;
}
AWSClient.registerPushNotificationEndpoint(
PushNotifications.token,
PlatformHelper.machineHostname,
PlatformHelper.deviceSerial + "+io.guh.nymeaapp" + (appBranding.length > 0 ? "-" + appBranding : ""),
clientId,
PlatformHelper.deviceManufacturer,
PlatformHelper.deviceModel);
}

View File

@ -47,7 +47,7 @@ SettingsPageBase {
Layout.fillWidth: true
Layout.leftMargin: app.margins
Layout.rightMargin: app.margins
visible: appBranding.length === 0
visible: !styleController.locked
Label {
Layout.fillWidth: true
text: "Style"