Add DarkTheme and LightTheme switching

This commit is contained in:
Agel committed 2026-03-31 20:43:37 +02:00
1 parent 7409ba789a
commit ff88cf581b
17 files changed
+206 -73

No files matched your search

+8 -2
View File
@@ -101,7 +101,11 @@ target_link_libraries(asteria-qt PRIVATE PkgConfig::MINIZIP Qt6::Xml)
# Set resource aliases so src/qml/* maps to qrc:/Asteria/* # Set resource aliases so src/qml/* maps to qrc:/Asteria/*
set_source_files_properties(src/qml/Main.qml PROPERTIES QT_RESOURCE_ALIAS Main.qml) set_source_files_properties(src/qml/Main.qml PROPERTIES QT_RESOURCE_ALIAS Main.qml)
set_source_files_properties(src/qml/Theme.qml PROPERTIES QT_RESOURCE_ALIAS Theme.qml set_source_files_properties(src/qml/DarkTheme.qml PROPERTIES QT_RESOURCE_ALIAS DarkTheme.qml
QT_QML_SINGLETON_TYPE TRUE)
set_source_files_properties(src/qml/LightTheme.qml PROPERTIES QT_RESOURCE_ALIAS LightTheme.qml
QT_QML_SINGLETON_TYPE TRUE)
set_source_files_properties(src/qml/ThemeManager.qml PROPERTIES QT_RESOURCE_ALIAS ThemeManager.qml
QT_QML_SINGLETON_TYPE TRUE) QT_QML_SINGLETON_TYPE TRUE)
set_source_files_properties(src/qml/components/Header.qml PROPERTIES QT_RESOURCE_ALIAS components/Header.qml) set_source_files_properties(src/qml/components/Header.qml PROPERTIES QT_RESOURCE_ALIAS components/Header.qml)
set_source_files_properties(src/qml/components/SideBar.qml PROPERTIES QT_RESOURCE_ALIAS components/SideBar.qml) set_source_files_properties(src/qml/components/SideBar.qml PROPERTIES QT_RESOURCE_ALIAS components/SideBar.qml)
@@ -122,7 +126,9 @@ qt_add_qml_module(asteria-qt
VERSION 1.0 VERSION 1.0
QML_FILES QML_FILES
src/qml/Main.qml src/qml/Main.qml
src/qml/Theme.qml src/qml/DarkTheme.qml
src/qml/LightTheme.qml
src/qml/ThemeManager.qml
src/qml/components/Header.qml src/qml/components/Header.qml
src/qml/components/SideBar.qml src/qml/components/SideBar.qml
src/qml/components/PageView.qml src/qml/components/PageView.qml
+12
View File
@@ -189,6 +189,16 @@ void AppState::setSidebarOpen(bool open)
emit sidebarOpenChanged(); emit sidebarOpenChanged();
} }
QString AppState::themeName() const { return m_themeName; }
void AppState::setThemeName(const QString &themeName)
{
if (m_themeName == themeName)
return;
m_themeName = themeName;
emit themeNameChanged();
}
void AppState::addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress) void AppState::addOrUpdateLibraryBook(const QString &filePath, const QString &title, const QString &author, double progress)
{ {
QString lastOpened = QDateTime::currentDateTime().toString(Qt::ISODate); QString lastOpened = QDateTime::currentDateTime().toString(Qt::ISODate);
@@ -284,6 +294,7 @@ void AppState::save()
s.setValue(QStringLiteral("preferences/verticalMargin"), m_verticalMargin); s.setValue(QStringLiteral("preferences/verticalMargin"), m_verticalMargin);
s.setValue(QStringLiteral("preferences/fontSize"), m_fontSize); s.setValue(QStringLiteral("preferences/fontSize"), m_fontSize);
s.setValue(QStringLiteral("preferences/lineSpacing"), m_lineSpacing); s.setValue(QStringLiteral("preferences/lineSpacing"), m_lineSpacing);
s.setValue(QStringLiteral("preferences/themeName"), m_themeName);
s.setValue(QStringLiteral("window/width"), m_windowWidth); s.setValue(QStringLiteral("window/width"), m_windowWidth);
s.setValue(QStringLiteral("window/height"), m_windowHeight); s.setValue(QStringLiteral("window/height"), m_windowHeight);
s.setValue(QStringLiteral("window/x"), m_windowX); s.setValue(QStringLiteral("window/x"), m_windowX);
@@ -305,6 +316,7 @@ void AppState::restore()
m_verticalMargin = s.value(QStringLiteral("preferences/verticalMargin"), 8).toInt(); m_verticalMargin = s.value(QStringLiteral("preferences/verticalMargin"), 8).toInt();
m_fontSize = s.value(QStringLiteral("preferences/fontSize"), 16).toInt(); m_fontSize = s.value(QStringLiteral("preferences/fontSize"), 16).toInt();
m_lineSpacing = s.value(QStringLiteral("preferences/lineSpacing"), 1.6).toDouble(); m_lineSpacing = s.value(QStringLiteral("preferences/lineSpacing"), 1.6).toDouble();
m_themeName = s.value(QStringLiteral("preferences/themeName"), QStringLiteral("dark")).toString();
m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt(); m_windowWidth = s.value(QStringLiteral("window/width"), 1024).toInt();
m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt(); m_windowHeight = s.value(QStringLiteral("window/height"), 768).toInt();
m_windowX = s.value(QStringLiteral("window/x"), -1).toInt(); m_windowX = s.value(QStringLiteral("window/x"), -1).toInt();
+6
View File
@@ -25,10 +25,14 @@ class AppState : public QObject {
Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged) Q_PROPERTY(QVariantList libraryBooks READ libraryBooks NOTIFY libraryBooksChanged)
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged) Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged) Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
public: public:
explicit AppState(QObject *parent = nullptr); explicit AppState(QObject *parent = nullptr);
QString themeName() const;
void setThemeName(const QString &themeName);
QString lastFilePath() const; QString lastFilePath() const;
void setLastFilePath(const QString &path); void setLastFilePath(const QString &path);
@@ -104,6 +108,7 @@ signals:
void libraryBooksChanged(); void libraryBooksChanged();
void lastPageChanged(); void lastPageChanged();
void sidebarOpenChanged(); void sidebarOpenChanged();
void themeNameChanged();
private: private:
void loadLibraryBooks(); void loadLibraryBooks();
@@ -124,6 +129,7 @@ private:
QVariantList m_libraryBooks; QVariantList m_libraryBooks;
QString m_lastPage = QStringLiteral("starter"); QString m_lastPage = QStringLiteral("starter");
bool m_sidebarOpen = false; bool m_sidebarOpen = false;
QString m_themeName = QStringLiteral("dark");
}; };
#endif // APPSTATE_H #endif // APPSTATE_H
+1 -8
View File
@@ -18,16 +18,9 @@ QtObject {
readonly property color dimText: "#71738c" readonly property color dimText: "#71738c"
readonly property color counterText: "#606175" readonly property color counterText: "#606175"
readonly property int sidebarWidth: 240
readonly property color gradientTop: "#0e1125" readonly property color gradientTop: "#0e1125"
readonly property color gradientBottom: "#191d35" readonly property color gradientBottom: "#191d35"
readonly property color divider: Qt.rgba(1, 1, 1, 0.12) readonly property color divider: Qt.rgba(1, 1, 1, 0.12)
readonly property color overlayBg: Qt.rgba(0.055, 0.055, 0.067, 0.4) readonly property color overlayBg: Qt.rgba(0.055, 0.055, 0.067, 0.4)
readonly property color actionDisabled: "#141724" readonly property color actionDisabled: "#141724"
}
readonly property int headerHeight: 64
readonly property int footerHeight: 28
readonly property int animDurationOpen: 225
readonly property int animDurationClose: 195
}
+26
View File
@@ -0,0 +1,26 @@
pragma Singleton
import QtQuick
QtObject {
readonly property color backgroundDeepest: "#f5f5f5"
readonly property color backgroundDefault: "#ffffff"
readonly property color surface: "#f0f0f0"
readonly property color headerBg: "#e8e8e8"
readonly property color footerBg: "#e0e0e0"
readonly property color scrollbarTrack: "#d0d0d0"
readonly property color scrollbarThumb: "#a0a0a0"
readonly property color primaryAccent: "#3a5688"
readonly property color buttonAccent: "#5785c1"
readonly property color sidebarButtonText: "#333333"
readonly property color readingText: "#222222"
readonly property color uiText: "#444444"
readonly property color headerText: "#555555"
readonly property color dimText: "#666666"
readonly property color counterText: "#777777"
readonly property color gradientTop: "#f8f8f8"
readonly property color gradientBottom: "#f0f0f0"
readonly property color divider: Qt.rgba(0, 0, 0, 0.12)
readonly property color overlayBg: Qt.rgba(0.95, 0.95, 0.95, 0.4)
readonly property color actionDisabled: "#e0e0e0"
}
+16 -2
View File
@@ -1,6 +1,7 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import Asteria import Asteria
import QtQml
ApplicationWindow { ApplicationWindow {
id: window id: window
@@ -8,7 +9,7 @@ ApplicationWindow {
height: 768 height: 768
visible: true visible: true
title: "Asteria" title: "Asteria"
color: Theme.backgroundDeepest color: ThemeManager.currentTheme.backgroundDeepest
FontLoader { FontLoader {
id: materialIcons id: materialIcons
@@ -30,6 +31,12 @@ ApplicationWindow {
x = appState.windowX x = appState.windowX
y = appState.windowY y = appState.windowY
} }
// Initialize theme from AppState
if (appState.themeName !== "") {
ThemeManager.currentThemeName = appState.themeName
}
if (appState.lastFilePath !== "") { if (appState.lastFilePath !== "") {
window._restoringState = true window._restoringState = true
bookController.openBook(appState.lastFileUrl()) bookController.openBook(appState.lastFileUrl())
@@ -40,6 +47,13 @@ ApplicationWindow {
window.currentPage = savedPage window.currentPage = savedPage
} }
} }
Connections {
target: appState
function onThemeNameChanged() {
ThemeManager.currentThemeName = appState.themeName
}
}
Timer { Timer {
id: geometrySaveTimer id: geometrySaveTimer
@@ -93,7 +107,7 @@ ApplicationWindow {
Item { Item {
id: contentArea id: contentArea
width: parent.width width: parent.width
height: parent.height - header.height - (footerLoader.active ? Theme.footerHeight : 0) height: parent.height - header.height - (footerLoader.active ? ThemeManager.currentTheme.footerHeight : 0)
StarterPage { StarterPage {
anchors.fill: parent anchors.fill: parent
+40
View File
@@ -0,0 +1,40 @@
pragma Singleton
import QtQuick
QtObject {
readonly property int sidebarWidth: 240
readonly property int headerHeight: 64
readonly property int footerHeight: 28
readonly property int animDurationOpen: 225
readonly property int animDurationClose: 195
property string currentThemeName: "dark"
readonly property var currentTheme: currentThemeName === "dark" ? DarkTheme : LightTheme
function setDarkTheme() {
currentThemeName = "dark"
if (appState) {
appState.themeName = "dark"
}
}
function setLightTheme() {
currentThemeName = "light"
if (appState) {
appState.themeName = "light"
}
}
function toggleTheme() {
currentThemeName = currentThemeName === "dark" ? "light" : "dark"
if (appState) {
appState.themeName = currentThemeName
}
}
onCurrentThemeNameChanged: {
// This ensures UI updates when theme changes
// The actual theme switching happens through the currentTheme property
}
}
+4 -4
View File
@@ -4,7 +4,7 @@ import Asteria
Rectangle { Rectangle {
id: overlay id: overlay
color: Theme.overlayBg color: ThemeManager.currentTheme.overlayBg
visible: bookController.errorMessage !== "" visible: bookController.errorMessage !== ""
MouseArea { MouseArea {
@@ -16,7 +16,7 @@ Rectangle {
anchors.centerIn: parent anchors.centerIn: parent
width: Math.min(overlay.width * 0.7, 440) width: Math.min(overlay.width * 0.7, 440)
height: dialogColumn.implicitHeight + 48 height: dialogColumn.implicitHeight + 48
color: Theme.surface color: ThemeManager.currentTheme.surface
radius: 8 radius: 8
Column { Column {
@@ -35,7 +35,7 @@ Rectangle {
width: parent.width width: parent.width
text: bookController.errorMessage text: bookController.errorMessage
font.pixelSize: 15 font.pixelSize: 15
color: Theme.readingText color: ThemeManager.currentTheme.readingText
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
wrapMode: Text.Wrap wrapMode: Text.Wrap
} }
@@ -53,7 +53,7 @@ Rectangle {
implicitWidth: 80 implicitWidth: 80
implicitHeight: 36 implicitHeight: 36
radius: 4 radius: 4
color: parent.hovered ? Qt.lighter(Theme.primaryAccent, 1.15) : Theme.primaryAccent color: parent.hovered ? Qt.lighter(ThemeManager.currentTheme.primaryAccent, 1.15) : ThemeManager.currentTheme.primaryAccent
} }
onClicked: bookController.clearError() onClicked: bookController.clearError()
} }
+7 -7
View File
@@ -3,13 +3,13 @@ import QtQuick.Controls
import Asteria import Asteria
Rectangle { Rectangle {
height: Theme.footerHeight height: ThemeManager.currentTheme.footerHeight
color: Theme.footerBg color: ThemeManager.currentTheme.footerBg
Rectangle { Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
color: Theme.divider color: ThemeManager.currentTheme.divider
anchors.top: parent.top anchors.top: parent.top
} }
@@ -28,7 +28,7 @@ Rectangle {
text: "\ue5cb" text: "\ue5cb"
font.family: "Material Icons Outlined" font.family: "Material Icons Outlined"
font.pixelSize: 16 font.pixelSize: 16
color: prevBtn.enabled ? Theme.dimText : Theme.actionDisabled color: prevBtn.enabled ? ThemeManager.currentTheme.dimText : ThemeManager.currentTheme.actionDisabled
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
@@ -45,7 +45,7 @@ Rectangle {
: "" : ""
font.pixelSize: 11 font.pixelSize: 11
font.bold: true font.bold: true
color: Theme.dimText color: ThemeManager.currentTheme.dimText
} }
// Next chapter button // Next chapter button
@@ -63,7 +63,7 @@ Rectangle {
text: "\ue5cc" text: "\ue5cc"
font.family: "Material Icons Outlined" font.family: "Material Icons Outlined"
font.pixelSize: 16 font.pixelSize: 16
color: nextBtn.enabled ? Theme.dimText : Theme.actionDisabled color: nextBtn.enabled ? ThemeManager.currentTheme.dimText : ThemeManager.currentTheme.actionDisabled
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
@@ -81,6 +81,6 @@ Rectangle {
: "" : ""
font.pixelSize: 11 font.pixelSize: 11
font.bold: true font.bold: true
color: Theme.counterText color: ThemeManager.currentTheme.counterText
} }
} }
+5 -5
View File
@@ -4,9 +4,9 @@ import Asteria
Rectangle { Rectangle {
id: header id: header
height: barsVisible ? Theme.headerHeight : 0 height: barsVisible ? ThemeManager.currentTheme.headerHeight : 0
clip: true clip: true
color: Theme.surface color: ThemeManager.currentTheme.surface
property bool sidebarOpen: false property bool sidebarOpen: false
property string currentPage: "starter" property string currentPage: "starter"
@@ -28,7 +28,7 @@ Rectangle {
contentItem: Text { contentItem: Text {
text: "\u2630" text: "\u2630"
font.pixelSize: 24 font.pixelSize: 24
color: Theme.buttonAccent color: ThemeManager.currentTheme.buttonAccent
} }
background: Item {} background: Item {}
onClicked: header.menuClicked() onClicked: header.menuClicked()
@@ -44,7 +44,7 @@ Rectangle {
} }
} }
font.pixelSize: 16 font.pixelSize: 16
color: Theme.headerText color: ThemeManager.currentTheme.headerText
} }
Row { Row {
@@ -58,7 +58,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 16 font.pixelSize: 16
font.bold: true font.bold: true
color: Theme.dimText color: ThemeManager.currentTheme.dimText
Timer { Timer {
running: true running: true
+5 -5
View File
@@ -53,8 +53,8 @@ Rectangle {
} }
gradient: Gradient { gradient: Gradient {
GradientStop { position: 0.0; color: Theme.gradientTop } GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
GradientStop { position: 1.0; color: Theme.gradientBottom } GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
} }
function updateContentWidth() { function updateContentWidth() {
@@ -81,7 +81,7 @@ Rectangle {
textFormat: Text.RichText textFormat: Text.RichText
font.pixelSize: appState.fontSize font.pixelSize: appState.fontSize
lineHeight: appState.lineSpacing lineHeight: appState.lineSpacing
color: Theme.readingText color: ThemeManager.currentTheme.readingText
text: model.content text: model.content
} }
@@ -101,11 +101,11 @@ Rectangle {
contentItem: Rectangle { contentItem: Rectangle {
implicitWidth: 18 implicitWidth: 18
radius: 3 radius: 3
color: Theme.scrollbarThumb color: ThemeManager.currentTheme.scrollbarThumb
} }
background: Rectangle { background: Rectangle {
implicitWidth: 18 implicitWidth: 18
color: Theme.scrollbarTrack color: ThemeManager.currentTheme.scrollbarTrack
} }
} }
+17 -17
View File
@@ -4,9 +4,9 @@ import Asteria
Rectangle { Rectangle {
id: sidebar id: sidebar
width: sidebarOpen ? Theme.sidebarWidth : 0 width: sidebarOpen ? ThemeManager.sidebarWidth : 0
clip: true clip: true
color: Theme.surface color: ThemeManager.currentTheme.surface
property bool sidebarOpen: false property bool sidebarOpen: false
@@ -17,7 +17,7 @@ Rectangle {
Behavior on width { Behavior on width {
NumberAnimation { NumberAnimation {
duration: sidebarOpen ? Theme.animDurationOpen : Theme.animDurationClose duration: sidebarOpen ? ThemeManager.animDurationOpen : ThemeManager.animDurationClose
easing.type: Easing.OutQuad easing.type: Easing.OutQuad
} }
} }
@@ -25,25 +25,25 @@ Rectangle {
Text { Text {
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 16 anchors.leftMargin: 16
y: Theme.headerHeight / 2 - height / 2 y: ThemeManager.headerHeight / 2 - height / 2
text: "Asteria" text: "Asteria"
font.pixelSize: 18 font.pixelSize: 18
font.bold: true font.bold: true
color: Theme.uiText color: ThemeManager.currentTheme.uiText
} }
// Close button aligned with main header row // Close button aligned with main header row
Button { Button {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 12 anchors.rightMargin: 12
y: Theme.headerHeight / 2 - height / 2 y: ThemeManager.headerHeight / 2 - height / 2
z: 1 z: 1
flat: true flat: true
contentItem: Text { contentItem: Text {
text: "\ue5cb" text: "\ue5cb"
font.family: "Material Icons Outlined" font.family: "Material Icons Outlined"
font.pixelSize: 24 font.pixelSize: 24
color: Theme.sidebarButtonText color: DarkTheme.sidebarButtonText
} }
background: Item {} background: Item {}
onClicked: sidebar.closeDrawer() onClicked: sidebar.closeDrawer()
@@ -51,8 +51,8 @@ Rectangle {
Column { Column {
id: navColumn id: navColumn
y: Theme.headerHeight y: ThemeManager.headerHeight
width: Theme.sidebarWidth width: ThemeManager.sidebarWidth
SideBarButton { SideBarButton {
iconText: "\ue86d" iconText: "\ue86d"
@@ -83,26 +83,26 @@ Rectangle {
Rectangle { Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
color: Theme.divider color: ThemeManager.currentTheme.divider
} }
SideBarButton { SideBarButton {
iconText: "\ue3a9" iconText: "\ue3a9"
title: "Dark Theme" title: "Dark Theme"
onClicked: {} // Non-functional onClicked: ThemeManager.setDarkTheme()
} }
SideBarButton { SideBarButton {
iconText: "\ue3a6" iconText: "\ue3a6"
title: "Light Theme" title: "Light Theme"
onClicked: {} // Non-functional onClicked: ThemeManager.setLightTheme()
} }
// Divider // Divider
Rectangle { Rectangle {
width: parent.width width: parent.width
height: 1 height: 1
color: Theme.divider color: ThemeManager.currentTheme.divider
} }
SideBarButton { SideBarButton {
@@ -123,7 +123,7 @@ Rectangle {
id: tocDivider id: tocDivider
width: parent.width width: parent.width
height: 1 height: 1
color: Theme.divider color: ThemeManager.currentTheme.divider
} }
Text { Text {
@@ -135,7 +135,7 @@ Rectangle {
text: "Contents" text: "Contents"
font.pixelSize: 10 font.pixelSize: 10
font.bold: true font.bold: true
color: Theme.dimText color: ThemeManager.currentTheme.dimText
font.letterSpacing: 1 font.letterSpacing: 1
} }
@@ -162,8 +162,8 @@ Rectangle {
text: modelData.title text: modelData.title
font.pixelSize: 13 font.pixelSize: 13
color: readingModel.currentChapter === modelData.chapterIndex color: readingModel.currentChapter === modelData.chapterIndex
? Theme.sidebarButtonText ? ThemeManager.sidebarButtonText
: Theme.uiText : ThemeManager.uiText
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }
+3 -3
View File
@@ -6,7 +6,7 @@ Rectangle {
id: root id: root
height: 48 height: 48
width: parent ? parent.width : 240 width: parent ? parent.width : 240
color: mouseArea.containsMouse ? Qt.lighter(Theme.headerBg, 1.3) : "transparent" color: mouseArea.containsMouse ? Qt.lighter(ThemeManager.currentTheme.headerBg, 1.3) : "transparent"
property string iconText: "" property string iconText: ""
property string title: "" property string title: ""
@@ -22,14 +22,14 @@ Rectangle {
text: root.iconText text: root.iconText
font.family: "Material Icons Outlined" font.family: "Material Icons Outlined"
font.pixelSize: 24 font.pixelSize: 24
color: Theme.sidebarButtonText color: ThemeManager.currentTheme.sidebarButtonText
} }
Text { Text {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: root.title text: root.title
font.pixelSize: 14 font.pixelSize: 14
color: Theme.sidebarButtonText color: ThemeManager.currentTheme.sidebarButtonText
} }
} }
+7 -7
View File
@@ -3,14 +3,14 @@ import QtQuick.Controls
import Asteria import Asteria
Rectangle { Rectangle {
color: Theme.backgroundDefault color: ThemeManager.currentTheme.backgroundDefault
Text { Text {
visible: appState.libraryBooks.length === 0 visible: appState.libraryBooks.length === 0
anchors.centerIn: parent anchors.centerIn: parent
text: "No books read yet.\nOpen a book to start your library." text: "No books read yet.\nOpen a book to start your library."
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
color: Theme.dimText color: ThemeManager.currentTheme.dimText
font.pixelSize: 14 font.pixelSize: 14
lineHeight: 1.6 lineHeight: 1.6
} }
@@ -27,7 +27,7 @@ Rectangle {
id: bookRow id: bookRow
width: ListView.view.width width: ListView.view.width
height: bookInfoCol.implicitHeight + 24 height: bookInfoCol.implicitHeight + 24
color: Theme.surface color: ThemeManager.currentTheme.surface
radius: 4 radius: 4
Row { Row {
@@ -47,7 +47,7 @@ Rectangle {
Text { Text {
width: parent.width width: parent.width
text: modelData.title || "Unknown Title" text: modelData.title || "Unknown Title"
color: Theme.uiText color: ThemeManager.currentTheme.uiText
font.pixelSize: 14 font.pixelSize: 14
font.bold: true font.bold: true
elide: Text.ElideRight elide: Text.ElideRight
@@ -57,14 +57,14 @@ Rectangle {
visible: modelData.author !== "" visible: modelData.author !== ""
width: parent.width width: parent.width
text: modelData.author text: modelData.author
color: Theme.dimText color: ThemeManager.currentTheme.dimText
font.pixelSize: 12 font.pixelSize: 12
elide: Text.ElideRight elide: Text.ElideRight
} }
Text { Text {
text: Math.round(modelData.progress * 100) + "%" text: Math.round(modelData.progress * 100) + "%"
color: Theme.buttonAccent color: ThemeManager.currentTheme.buttonAccent
font.pixelSize: 12 font.pixelSize: 12
} }
} }
@@ -77,7 +77,7 @@ Rectangle {
text: "\ue872" text: "\ue872"
font.family: "Material Icons Outlined" font.family: "Material Icons Outlined"
font.pixelSize: 20 font.pixelSize: 20
color: Theme.dimText color: ThemeManager.currentTheme.dimText
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
+11 -11
View File
@@ -4,8 +4,8 @@ import Asteria
Rectangle { Rectangle {
gradient: Gradient { gradient: Gradient {
GradientStop { position: 0.0; color: Theme.gradientTop } GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
GradientStop { position: 1.0; color: Theme.gradientBottom } GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
} }
ScrollView { ScrollView {
@@ -22,7 +22,7 @@ Rectangle {
text: "Reading" text: "Reading"
font.pixelSize: 13 font.pixelSize: 13
font.weight: Font.Medium font.weight: Font.Medium
color: Theme.dimText color: ThemeManager.currentTheme.dimText
leftPadding: 4 leftPadding: 4
} }
@@ -38,7 +38,7 @@ Rectangle {
id: labelH id: labelH
text: "Horizontal margin" text: "Horizontal margin"
font.pixelSize: 15 font.pixelSize: 15
color: Theme.uiText color: ThemeManager.currentTheme.uiText
leftPadding: 4 leftPadding: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -46,7 +46,7 @@ Rectangle {
id: valueH id: valueH
text: appState.horizontalMargin + " px" text: appState.horizontalMargin + " px"
font.pixelSize: 13 font.pixelSize: 13
color: Theme.dimText color: ThemeManager.currentTheme.dimText
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 4 anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -75,7 +75,7 @@ Rectangle {
id: labelV id: labelV
text: "Vertical margin" text: "Vertical margin"
font.pixelSize: 15 font.pixelSize: 15
color: Theme.uiText color: ThemeManager.currentTheme.uiText
leftPadding: 4 leftPadding: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -83,7 +83,7 @@ Rectangle {
id: valueV id: valueV
text: appState.verticalMargin + " px" text: appState.verticalMargin + " px"
font.pixelSize: 13 font.pixelSize: 13
color: Theme.dimText color: ThemeManager.currentTheme.dimText
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 4 anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -112,7 +112,7 @@ Rectangle {
id: labelF id: labelF
text: "Font size" text: "Font size"
font.pixelSize: 15 font.pixelSize: 15
color: Theme.uiText color: ThemeManager.currentTheme.uiText
leftPadding: 4 leftPadding: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -120,7 +120,7 @@ Rectangle {
id: valueF id: valueF
text: appState.fontSize + " px" text: appState.fontSize + " px"
font.pixelSize: 13 font.pixelSize: 13
color: Theme.dimText color: ThemeManager.currentTheme.dimText
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 4 anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
@@ -149,7 +149,7 @@ Rectangle {
id: labelL id: labelL
text: "Line spacing" text: "Line spacing"
font.pixelSize: 15 font.pixelSize: 15
color: Theme.uiText color: ThemeManager.currentTheme.uiText
leftPadding: 4 leftPadding: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
} }
@@ -157,7 +157,7 @@ Rectangle {
id: valueL id: valueL
text: appState.lineSpacing.toFixed(1) + "×" text: appState.lineSpacing.toFixed(1) + "×"
font.pixelSize: 13 font.pixelSize: 13
color: Theme.dimText color: ThemeManager.currentTheme.dimText
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 4 anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
+2 -2
View File
@@ -3,8 +3,8 @@ import Asteria
Rectangle { Rectangle {
gradient: Gradient { gradient: Gradient {
GradientStop { position: 0.0; color: Theme.gradientTop } GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
GradientStop { position: 1.0; color: Theme.gradientBottom } GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
} }
Image { Image {
+36
View File
@@ -265,6 +265,7 @@ private slots:
QSignalSpy spyHeight(&state, &AppState::windowHeightChanged); QSignalSpy spyHeight(&state, &AppState::windowHeightChanged);
QSignalSpy spyX(&state, &AppState::windowXChanged); QSignalSpy spyX(&state, &AppState::windowXChanged);
QSignalSpy spyY(&state, &AppState::windowYChanged); QSignalSpy spyY(&state, &AppState::windowYChanged);
QSignalSpy spyTheme(&state, &AppState::themeNameChanged);
state.restore(); state.restore();
@@ -282,6 +283,41 @@ private slots:
QCOMPARE(spyHeight.count(), 0); QCOMPARE(spyHeight.count(), 0);
QCOMPARE(spyX.count(), 0); QCOMPARE(spyX.count(), 0);
QCOMPARE(spyY.count(), 0); QCOMPARE(spyY.count(), 0);
QCOMPARE(spyTheme.count(), 0);
}
void saveAndRestoreThemeName()
{
{
AppState state;
state.setThemeName(QStringLiteral("light"));
state.save();
}
AppState state2;
state2.restore();
QCOMPARE(state2.themeName(), QStringLiteral("light"));
}
void themeNameDefaultsToDark()
{
AppState state;
QCOMPARE(state.themeName(), QStringLiteral("dark"));
}
void themeNameSetterEmitsSignal()
{
AppState state;
QSignalSpy spy(&state, &AppState::themeNameChanged);
state.setThemeName(QStringLiteral("light"));
QCOMPARE(spy.count(), 1);
}
void themeNameSetterDoesNotEmitForSameValue()
{
AppState state;
QSignalSpy spy(&state, &AppState::themeNameChanged);
state.setThemeName(QStringLiteral("dark")); // Same as default
QCOMPARE(spy.count(), 0);
} }
// Library tests // Library tests