Add custom theme

This commit is contained in:
Agel committed 2026-04-14 20:52:07 +02:00
1 parent 598566c2a4
commit 96b7838a4b
9 files changed
+636 -31

No files matched your search

+6 -2
View File
@@ -34,10 +34,9 @@ ApplicationWindow {
x = uiState.windowX
y = uiState.windowY
}
ThemeManager.loadCustomColors(uiState.customThemeColors)
if (uiState.themeName !== "")
ThemeManager.currentThemeName = uiState.themeName
}
Connections {
@@ -139,6 +138,11 @@ ApplicationWindow {
visible: window.currentPage === "history"
}
CustomThemePage {
anchors.fill: parent
visible: window.currentPage === "customTheme"
}
BusyIndicator {
anchors.centerIn: parent
running: window._bookInitializing
+100 -7
View File
@@ -9,9 +9,36 @@ QtObject {
readonly property int animDurationClose: 195
property string currentThemeName: "dark"
readonly property var currentTheme: currentThemeName === "dark" ? DarkTheme : LightTheme
property QtObject customTheme: QtObject {
property color backgroundDeepest: "#010620"
property color backgroundDefault: "#191d35"
property color surface: "#191d35"
property color headerBg: "#14172c"
property color footerBg: "#1a1e36"
property color scrollbarTrack: "#131628"
property color scrollbarThumb: "#36486a"
property color primaryAccent: "#3a5688"
property color buttonAccent: "#5785c1"
property color sidebarButtonText: "#98aaf4"
property color readingText: "#c4c8d8"
property color uiText: "#a2a5b4"
property color headerText: "#8488aa"
property color dimText: "#71738c"
property color counterText: "#606175"
property color gradientTop: "#0e1125"
property color gradientBottom: "#191d35"
property color divider: "#1f2040"
property color overlayBg: "#0e0f11"
property color actionDisabled: "#141724"
}
property var _lastApplied: ({})
readonly property var currentTheme: currentThemeName === "dark" ? DarkTheme
: currentThemeName === "light" ? LightTheme
: customTheme
function setDarkTheme() {
currentThemeName = "dark"
uiState.themeName = "dark"
@@ -22,8 +49,74 @@ QtObject {
uiState.themeName = "light"
}
function toggleTheme() {
currentThemeName = currentThemeName === "dark" ? "light" : "dark"
uiState.themeName = currentThemeName
function setCustomTheme() {
currentThemeName = "custom"
uiState.themeName = "custom"
}
}
function loadCustomColors(map) {
if (map && Object.keys(map).length > 0)
_restoreColors(map)
// Snapshot current state (loaded or defaults) so Revert always has a target
_lastApplied = _captureColors()
}
function applyCustomColors() {
var c = _captureColors()
_lastApplied = c
uiState.customThemeColors = c
}
function revertCustomColors() {
_restoreColors(_lastApplied)
}
function _captureColors() {
return {
backgroundDeepest: customTheme.backgroundDeepest.toString(),
backgroundDefault: customTheme.backgroundDefault.toString(),
surface: customTheme.surface.toString(),
headerBg: customTheme.headerBg.toString(),
footerBg: customTheme.footerBg.toString(),
scrollbarTrack: customTheme.scrollbarTrack.toString(),
scrollbarThumb: customTheme.scrollbarThumb.toString(),
primaryAccent: customTheme.primaryAccent.toString(),
buttonAccent: customTheme.buttonAccent.toString(),
sidebarButtonText: customTheme.sidebarButtonText.toString(),
readingText: customTheme.readingText.toString(),
uiText: customTheme.uiText.toString(),
headerText: customTheme.headerText.toString(),
dimText: customTheme.dimText.toString(),
counterText: customTheme.counterText.toString(),
gradientTop: customTheme.gradientTop.toString(),
gradientBottom: customTheme.gradientBottom.toString(),
divider: customTheme.divider.toString(),
overlayBg: customTheme.overlayBg.toString(),
actionDisabled: customTheme.actionDisabled.toString()
}
}
function _restoreColors(c) {
if (!c) return
if (c.backgroundDeepest) customTheme.backgroundDeepest = c.backgroundDeepest
if (c.backgroundDefault) customTheme.backgroundDefault = c.backgroundDefault
if (c.surface) customTheme.surface = c.surface
if (c.headerBg) customTheme.headerBg = c.headerBg
if (c.footerBg) customTheme.footerBg = c.footerBg
if (c.scrollbarTrack) customTheme.scrollbarTrack = c.scrollbarTrack
if (c.scrollbarThumb) customTheme.scrollbarThumb = c.scrollbarThumb
if (c.primaryAccent) customTheme.primaryAccent = c.primaryAccent
if (c.buttonAccent) customTheme.buttonAccent = c.buttonAccent
if (c.sidebarButtonText) customTheme.sidebarButtonText = c.sidebarButtonText
if (c.readingText) customTheme.readingText = c.readingText
if (c.uiText) customTheme.uiText = c.uiText
if (c.headerText) customTheme.headerText = c.headerText
if (c.dimText) customTheme.dimText = c.dimText
if (c.counterText) customTheme.counterText = c.counterText
if (c.gradientTop) customTheme.gradientTop = c.gradientTop
if (c.gradientBottom) customTheme.gradientBottom = c.gradientBottom
if (c.divider) customTheme.divider = c.divider
if (c.overlayBg) customTheme.overlayBg = c.overlayBg
if (c.actionDisabled) customTheme.actionDisabled = c.actionDisabled
}
}
+11
View File
@@ -98,6 +98,17 @@ Rectangle {
onClicked: ThemeManager.setLightTheme()
}
SideBarButton {
iconText: "\ue40a"
title: "Custom Theme"
rightIconText: "\ue3c9"
onClicked: ThemeManager.setCustomTheme()
onRightIconClicked: {
ThemeManager.setCustomTheme()
sidebar.navigateTo("customTheme")
}
}
// Divider
Rectangle {
width: parent.width
+40 -2
View File
@@ -10,11 +10,16 @@ Rectangle {
property string iconText: ""
property string title: ""
property string rightIconText: ""
signal clicked()
signal rightIconClicked()
Row {
anchors.fill: parent
anchors.left: parent.left
anchors.leftMargin: 16
anchors.top: parent.top
anchors.bottom: parent.bottom
spacing: 16
Text {
@@ -33,9 +38,42 @@ Rectangle {
}
}
// Optional right icon zone — zero-width when unused
Rectangle {
id: rightIconZone
visible: root.rightIconText !== ""
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
width: visible ? 44 : 0
color: "transparent"
Text {
anchors.centerIn: parent
text: root.rightIconText
font.family: "Material Icons Outlined"
font.pixelSize: 18
color: rightIconArea.containsMouse
? Qt.lighter(ThemeManager.currentTheme.sidebarButtonText, 1.3)
: ThemeManager.currentTheme.sidebarButtonText
}
MouseArea {
id: rightIconArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.rightIconClicked()
}
}
// Main click area stops before the right icon zone
MouseArea {
id: mouseArea
anchors.fill: parent
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width - rightIconZone.width
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.clicked()
+439
View File
@@ -0,0 +1,439 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import Asteria
Rectangle {
gradient: Gradient {
GradientStop { position: 0.0; color: ThemeManager.currentTheme.gradientTop }
GradientStop { position: 1.0; color: ThemeManager.currentTheme.gradientBottom }
}
// Apply on navigate away
onVisibleChanged: {
if (!visible && ThemeManager.currentThemeName === "custom")
ThemeManager.applyCustomColors()
}
// ── Fixed top panel ──────────────────────────────────────────────────────
Column {
id: topPanel
anchors.top: parent.top
anchors.topMargin: 8
anchors.left: parent.left
anchors.leftMargin: 8
anchors.right: parent.right
anchors.rightMargin: 8
spacing: 12
Text {
text: "Custom Theme"
font.pixelSize: 13
font.weight: Font.Medium
color: ThemeManager.currentTheme.dimText
leftPadding: 4
}
// Lorem Ipsum preview
Rectangle {
width: parent.width
height: previewColumn.implicitHeight + 24
color: ThemeManager.currentTheme.surface
radius: 6
border.color: ThemeManager.currentTheme.divider
border.width: 1
Column {
id: previewColumn
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 16
spacing: 8
Text {
width: parent.width
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
font.pixelSize: 15
color: ThemeManager.currentTheme.readingText
wrapMode: Text.WordWrap
}
Text {
text: "UI element text \u2022 Header text"
font.pixelSize: 13
color: ThemeManager.currentTheme.uiText
}
Text {
text: "Dim / secondary text \u2022 Counter text"
font.pixelSize: 12
color: ThemeManager.currentTheme.dimText
}
Row {
spacing: 8
Rectangle {
width: accentLabel.implicitWidth + 16
height: accentLabel.implicitHeight + 8
color: ThemeManager.currentTheme.primaryAccent
radius: 3
Text {
id: accentLabel
anchors.centerIn: parent
text: "Primary accent"
font.pixelSize: 12
color: ThemeManager.currentTheme.readingText
}
}
Rectangle {
width: buttonLabel.implicitWidth + 16
height: buttonLabel.implicitHeight + 8
color: ThemeManager.currentTheme.buttonAccent
radius: 3
Text {
id: buttonLabel
anchors.centerIn: parent
text: "Button accent"
font.pixelSize: 12
color: ThemeManager.currentTheme.readingText
}
}
}
}
}
// Divider between fixed panel and scrollable area
Rectangle {
width: parent.width
height: 1
color: ThemeManager.currentTheme.divider
}
}
// ── Fixed bottom bar ─────────────────────────────────────────────────────
Rectangle {
id: bottomBar
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
height: 56
color: ThemeManager.currentTheme.surface
Rectangle {
width: parent.width
height: 1
color: ThemeManager.currentTheme.divider
}
Row {
anchors.centerIn: parent
spacing: 12
Rectangle {
width: revertText.implicitWidth + 32
height: 36
color: revertArea.containsMouse
? Qt.lighter(ThemeManager.currentTheme.surface, 1.2)
: ThemeManager.currentTheme.surface
radius: 4
border.color: ThemeManager.currentTheme.divider
border.width: 1
Text {
id: revertText
anchors.centerIn: parent
text: "Revert"
font.pixelSize: 14
color: ThemeManager.currentTheme.uiText
}
MouseArea {
id: revertArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: ThemeManager.revertCustomColors()
}
}
Rectangle {
width: applyText.implicitWidth + 32
height: 36
color: applyArea.containsMouse
? Qt.lighter(ThemeManager.currentTheme.primaryAccent, 1.2)
: ThemeManager.currentTheme.primaryAccent
radius: 4
Text {
id: applyText
anchors.centerIn: parent
text: "Apply"
font.pixelSize: 14
color: ThemeManager.currentTheme.readingText
}
MouseArea {
id: applyArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: ThemeManager.applyCustomColors()
}
}
}
}
// ── Scrollable color picker rows ─────────────────────────────────────────
// Full width so the scrollbar sits at the screen edge, outside the 8px margin
ScrollView {
anchors.top: topPanel.bottom
anchors.topMargin: 4
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: bottomBar.top
contentWidth: availableWidth
Column {
width: parent.width
leftPadding: 8
rightPadding: 8
bottomPadding: 16
spacing: 0
// ── Background ─────────────────────────────────────────────────
SectionLabel { text: "Background" }
ColorRow {
width: parent.width - 16
label: "Deepest background"
value: ThemeManager.customTheme.backgroundDeepest
apply: function(c) { ThemeManager.customTheme.backgroundDeepest = c }
}
ColorRow {
width: parent.width - 16
label: "Default background"
value: ThemeManager.customTheme.backgroundDefault
apply: function(c) { ThemeManager.customTheme.backgroundDefault = c }
}
ColorRow {
width: parent.width - 16
label: "Gradient top"
value: ThemeManager.customTheme.gradientTop
apply: function(c) { ThemeManager.customTheme.gradientTop = c }
}
ColorRow {
width: parent.width - 16
label: "Gradient bottom"
value: ThemeManager.customTheme.gradientBottom
apply: function(c) { ThemeManager.customTheme.gradientBottom = c }
}
// ── Surfaces ───────────────────────────────────────────────────
SectionLabel { text: "Surfaces" }
ColorRow {
width: parent.width - 16
label: "Surface"
value: ThemeManager.customTheme.surface
apply: function(c) { ThemeManager.customTheme.surface = c }
}
ColorRow {
width: parent.width - 16
label: "Header background"
value: ThemeManager.customTheme.headerBg
apply: function(c) { ThemeManager.customTheme.headerBg = c }
}
ColorRow {
width: parent.width - 16
label: "Footer background"
value: ThemeManager.customTheme.footerBg
apply: function(c) { ThemeManager.customTheme.footerBg = c }
}
ColorRow {
width: parent.width - 16
label: "Overlay background"
value: ThemeManager.customTheme.overlayBg
apply: function(c) { ThemeManager.customTheme.overlayBg = c }
}
ColorRow {
width: parent.width - 16
label: "Scrollbar track"
value: ThemeManager.customTheme.scrollbarTrack
apply: function(c) { ThemeManager.customTheme.scrollbarTrack = c }
}
ColorRow {
width: parent.width - 16
label: "Scrollbar thumb"
value: ThemeManager.customTheme.scrollbarThumb
apply: function(c) { ThemeManager.customTheme.scrollbarThumb = c }
}
ColorRow {
width: parent.width - 16
label: "Divider"
value: ThemeManager.customTheme.divider
apply: function(c) { ThemeManager.customTheme.divider = c }
}
// ── Text ───────────────────────────────────────────────────────
SectionLabel { text: "Text" }
ColorRow {
width: parent.width - 16
label: "Reading text"
value: ThemeManager.customTheme.readingText
apply: function(c) { ThemeManager.customTheme.readingText = c }
}
ColorRow {
width: parent.width - 16
label: "UI text"
value: ThemeManager.customTheme.uiText
apply: function(c) { ThemeManager.customTheme.uiText = c }
}
ColorRow {
width: parent.width - 16
label: "Header text"
value: ThemeManager.customTheme.headerText
apply: function(c) { ThemeManager.customTheme.headerText = c }
}
ColorRow {
width: parent.width - 16
label: "Dim text"
value: ThemeManager.customTheme.dimText
apply: function(c) { ThemeManager.customTheme.dimText = c }
}
ColorRow {
width: parent.width - 16
label: "Counter text"
value: ThemeManager.customTheme.counterText
apply: function(c) { ThemeManager.customTheme.counterText = c }
}
ColorRow {
width: parent.width - 16
label: "Sidebar button text"
value: ThemeManager.customTheme.sidebarButtonText
apply: function(c) { ThemeManager.customTheme.sidebarButtonText = c }
}
// ── Accents ────────────────────────────────────────────────────
SectionLabel { text: "Accents" }
ColorRow {
width: parent.width - 16
label: "Primary accent"
value: ThemeManager.customTheme.primaryAccent
apply: function(c) { ThemeManager.customTheme.primaryAccent = c }
}
ColorRow {
width: parent.width - 16
label: "Button accent"
value: ThemeManager.customTheme.buttonAccent
apply: function(c) { ThemeManager.customTheme.buttonAccent = c }
}
ColorRow {
width: parent.width - 16
label: "Action disabled"
value: ThemeManager.customTheme.actionDisabled
apply: function(c) { ThemeManager.customTheme.actionDisabled = c }
}
}
}
// ── Inline components ────────────────────────────────────────────────────
component SectionLabel: Text {
topPadding: 16
bottomPadding: 4
leftPadding: 4
font.pixelSize: 13
font.weight: Font.Medium
color: ThemeManager.currentTheme.dimText
}
component ColorRow: Item {
id: colorRowRoot
height: 40
property string label: ""
property color value: "black"
property var apply: null // (color) => void
property color _savedValue: "black"
ColorDialog {
id: dlg
onSelectedColorChanged: { if (colorRowRoot.apply) colorRowRoot.apply(selectedColor) }
onRejected: { if (colorRowRoot.apply) colorRowRoot.apply(colorRowRoot._savedValue) }
}
function openPicker() {
_savedValue = value
dlg.selectedColor = value
dlg.open()
}
Text {
anchors.left: colorRowRoot.left
anchors.leftMargin: 4
anchors.verticalCenter: colorRowRoot.verticalCenter
text: colorRowRoot.label
font.pixelSize: 14
color: ThemeManager.currentTheme.uiText
}
Row {
anchors.right: colorRowRoot.right
anchors.verticalCenter: colorRowRoot.verticalCenter
spacing: 8
Rectangle {
width: 32
height: 22
color: colorRowRoot.value
radius: 3
border.color: ThemeManager.currentTheme.divider
border.width: 1
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: colorRowRoot.openPicker()
}
}
Text {
text: colorRowRoot.value.toString().toUpperCase()
font.pixelSize: 11
font.family: "Courier New"
color: ThemeManager.currentTheme.dimText
anchors.verticalCenter: parent.verticalCenter
width: 90
}
}
}
}