diff --git a/app/app.pro b/app/app.pro index a5812b6..438223f 100644 --- a/app/app.pro +++ b/app/app.pro @@ -32,7 +32,6 @@ SOURCE_DIR=src SOURCES += \ $${SOURCE_DIR}/main/app/appcomponents.cpp \ $${SOURCE_DIR}/main/app/main.cpp \ - $${SOURCE_DIR}/main/app/style.cpp \ $${SOURCE_DIR}/main/debug/refcounter.cpp \ $${SOURCE_DIR}/main/repository/appearancerepository.cpp \ $${SOURCE_DIR}/main/repository/db.cpp \ @@ -86,7 +85,6 @@ RESOURCES += \ HEADERS += \ $${SOURCE_DIR}/main/app/appcomponents.h \ - $${SOURCE_DIR}/main/app/style.h \ $${SOURCE_DIR}/main/debug/refcounter.h \ $${SOURCE_DIR}/main/repository/appearancerepository.h \ $${SOURCE_DIR}/main/repository/db.h \ @@ -115,6 +113,7 @@ HEADERS += \ $${SOURCE_DIR}/main/viewmodel/rhymeentitymapper.h \ $${SOURCE_DIR}/main/viewmodel/rhymelistmodel.h \ $${SOURCE_DIR}/main/viewmodel/rhymeviewmodel.h \ + $${SOURCE_DIR}/main/viewmodel/styleenum.h \ $${SOURCE_DIR}/main/viewmodel/suggestiondisplaydata.h \ $${SOURCE_DIR}/main/viewmodel/suggestionentitymapper.h \ $${SOURCE_DIR}/main/viewmodel/suggestionlistmodel.h \ diff --git a/app/resources/i18n/PoetAssistant_en_US.ts b/app/resources/i18n/PoetAssistant_en_US.ts index 7640214..9f0dff5 100644 --- a/app/resources/i18n/PoetAssistant_en_US.ts +++ b/app/resources/i18n/PoetAssistant_en_US.ts @@ -215,6 +215,21 @@ Dark + + Theme (restarts the app) + + + Basic + + + Fusion + + + Material + + + Universal + No rhymes for %1 diff --git a/app/resources/qml/PreferencesWindow.qml b/app/resources/qml/PreferencesWindow.qml index f45343c..ba6c86c 100644 --- a/app/resources/qml/PreferencesWindow.qml +++ b/app/resources/qml/PreferencesWindow.qml @@ -20,6 +20,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts import NightMode +import Theme Dialog { id: dlgPreference @@ -85,7 +86,39 @@ Dialog { ] Component.onCompleted: currentIndex = indexOfValue(preferencesViewModel.nightMode) - onActivated: preferencesViewModel.nightMode = currentIndex + onActivated: preferencesViewModel.nightMode = currentValue + } + + Text { + text: qsTrId("preferences_label_style") + Accessible.name: text + color: Style.primaryText + } + + StyledComboBox { + textRole: "text" + valueRole: "value" + model: [ + { + text: qsTrId("preferences_label_style_basic"), + value: Theme.Basic + }, + { + text: qsTrId("preferences_label_style_fusion"), + value: Theme.Fusion + }, + { + text: qsTrId("preferences_label_style_material"), + value: Theme.Material + }, + { + text: qsTrId("preferences_label_style_universal"), + value: Theme.Universal + }, + ] + + Component.onCompleted: currentIndex = indexOfValue(preferencesViewModel.style) + onActivated: preferencesViewModel.style = currentValue } } } diff --git a/app/resources/qml/TtsControlsView.qml b/app/resources/qml/TtsControlsView.qml index 7fdf055..6e0b4de 100644 --- a/app/resources/qml/TtsControlsView.qml +++ b/app/resources/qml/TtsControlsView.qml @@ -63,8 +63,8 @@ RowLayout{ AnnotatedToolButton { iconsource: ttsViewModel.playButtonIcon label: qsTrId(ttsViewModel.playButtonLabel) - icon.height: 32 - icon.width: 32 + icon.height: 48 + icon.width: 48 anchors.centerIn: parent onClicked: { if (taPoem.selectedText) { diff --git a/app/src/main/app/appcomponents.h b/app/src/main/app/appcomponents.h index fa3cc69..8524a54 100644 --- a/app/src/main/app/appcomponents.h +++ b/app/src/main/app/appcomponents.h @@ -68,9 +68,7 @@ class AppComponents : public QObject SuggestionViewModel suggestionViewModel; public: SuggestionListModel suggestionListModel; -private: AppearanceRepository appearanceRepository; -public: PreferencesViewModel preferencesViewModel; MainViewModel mainViewModel; }; diff --git a/app/src/main/app/main.cpp b/app/src/main/app/main.cpp index c430628..c42e3a8 100644 --- a/app/src/main/app/main.cpp +++ b/app/src/main/app/main.cpp @@ -20,7 +20,6 @@ along with Poet Assistant. If not, see . #include "appcomponents.h" #include "colortypeenum.h" #include "nightmodeenum.h" -#include "style.h" #include #include @@ -31,10 +30,13 @@ along with Poet Assistant. If not, see . void setupEngine(QQmlApplicationEngine &engine, AppComponents &components) { + qmlClearTypeRegistrations(); qmlRegisterUncreatableType("ColorType", 1, 0, "ColorType", "Not creatable as it is an enum type"); qmlRegisterUncreatableType("NightMode", 1, 0, "NightMode", "Not creatable as it is an enum type"); + qmlRegisterUncreatableType("Theme", 1, 0, "Theme", + "Not creatable as it is an enum type"); engine.rootContext()->setContextProperty("mainViewModel", QVariant::fromValue(&components.mainViewModel)); engine.rootContext()->setContextProperty("rhymeListModel", @@ -53,7 +55,9 @@ void setupEngine(QQmlApplicationEngine &engine, AppComponents &components) QVariant::fromValue(&components.suggestionListModel)); engine.rootContext()->setContextProperty("preferencesViewModel", QVariant::fromValue(&components.preferencesViewModel)); - engine.rootContext()->setContextProperty("theme", Style::setStyle()); + QString style = AppearanceRepository::getName(components.appearanceRepository.getStyle()); + QQuickStyle::setStyle(style); + engine.rootContext()->setContextProperty("theme", style); engine.load(QUrl("qrc:/qml/main.qml")); } @@ -74,7 +78,22 @@ int main(int argc, char *argv[]) QFuture future = db.openDb(); future.waitForFinished(); // TODO AppComponents components(&db); - QQmlApplicationEngine engine; - setupEngine(engine, components); + QQmlApplicationEngine *engine = new QQmlApplicationEngine(); + setupEngine(*engine, components); + QObject context; + QObject::connect(&components.appearanceRepository, &AppearanceRepository::styleChanged, + &context, [ &context, &engine, &components] { + engine->clearComponentCache(); + engine->deleteLater(); + QObject::connect(engine, &QObject::destroyed, &context, [&engine, &components]{ + engine = new QQmlApplicationEngine(); + setupEngine(*engine, components); + }); + }); + // Prevent QML errors when closing the app + // https://bugreports.qt.io/browse/QTBUG-81247?page=com.googlecode.jira-suite-utilities%3Atransitions-summary-tabpanel + QObject::connect(&a, &QGuiApplication::aboutToQuit, &context, [&engine] { + engine->deleteLater(); + }); return a.exec(); } diff --git a/app/src/main/app/style.cpp b/app/src/main/app/style.cpp deleted file mode 100644 index e758b96..0000000 --- a/app/src/main/app/style.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/** -Copyright (c) 2022 - present Carmen Alvarez - -This file is part of Poet Assistant. - -Poet Assistant is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Poet Assistant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Poet Assistant. If not, see . -*/ - -#include "style.h" -#include - -Style::Style() -{ -} - -QString Style::setStyle() -{ - QString style = QQuickStyle::name(); - if (!supportedStyles.contains(style)) { - style = "Basic"; - QQuickStyle::setStyle(style); - } - return style; -} diff --git a/app/src/main/repository/appearancerepository.cpp b/app/src/main/repository/appearancerepository.cpp index 741fe46..e99a172 100644 --- a/app/src/main/repository/appearancerepository.cpp +++ b/app/src/main/repository/appearancerepository.cpp @@ -35,3 +35,27 @@ AppearanceRepository::NightMode AppearanceRepository::getNightMode() { return static_cast(settings.value(nightModeSetting, NightMode::Auto).toInt()); } + +void AppearanceRepository::setStyle(AppearanceRepository::Style style) +{ + settings.setValue(styleSetting, style); + emit styleChanged(); +} + +AppearanceRepository::Style AppearanceRepository::getStyle() +{ + return static_cast