Add PCN theme system

Coexist with the old theme system for now. QML components have to be
updated to use the new system.
This commit is contained in:
miruka
2020-11-17 08:24:55 -04:00
parent 1af1d30c48
commit 42f04b013e
15 changed files with 159 additions and 16 deletions

8
src/gui/Base/Class.qml Normal file
View File

@@ -0,0 +1,8 @@
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
QtObject {
property string name
}

View File

@@ -8,10 +8,15 @@ import QtQuick.Layouts 1.12
Button {
id: button
property Theme ntheme: Theme {
target: button
classes: Class { name: "Button" }
}
readonly property alias iconItem: contentItem.icon
readonly property alias label: contentItem.label
property color backgroundColor: theme.controls.button.background
property color backgroundColor: ntheme.data.background
property color focusLineColor:
Qt.colorEqual(icon.color, theme.icons.colorize) ?
theme.controls.button.focusedBorder :

25
src/gui/Base/Theme.qml Normal file
View File

@@ -0,0 +1,25 @@
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
QtObject {
id: root
property Item target
default property list<Class> classes
readonly property var matchablePathRegex: utils.getClassPathRegex(target)
readonly property var themeRules: window.themeRules
readonly property var data: {
const newData = {}
for (const [path, section] of Object.entries(themeRules))
if (matchablePathRegex.test(path))
for (const [name, value] of Object.entries(section))
if (! name.startsWith("_"))
newData[name] = value
return newData
}
}

View File

@@ -22,7 +22,6 @@ Rectangle {
id: addAccountButton
icon.name: "add-account"
toolTip.text: qsTr("Add another account")
backgroundColor: theme.mainPane.bottomBar.settingsButtonBackground
onClicked: {
pageLoader.show("Pages/AddAccount/AddAccount.qml")
roomList.startCorrectItemSearch()

View File

@@ -8,6 +8,13 @@ import "../../../Base"
import "../AutoCompletion"
Rectangle {
id: composer
property Theme ntheme: Theme {
target: composer
classes: Class { name: "Composer" }
}
property UserAutoCompletion userCompletion
property alias eventList: messageArea.eventList

View File

@@ -8,9 +8,10 @@ import "../../../Base"
import "../../../Dialogs"
HButton {
ntheme.classes: Class { name: "UploadButton" }
enabled: chat.roomInfo.can_send_messages
icon.name: "upload-file"
backgroundColor: theme.chat.composer.uploadButton.background
toolTip.text:
chat.userInfo.max_upload_size ?
qsTr("Send files (%1 max)").arg(

View File

@@ -149,8 +149,6 @@ HColumnLayout {
HButton {
id: inviteButton
icon.name: "room-send-invite"
backgroundColor:
theme.chat.roomPane.bottomBar.inviteButton.background
enabled:
chat.userInfo.presence !== "offline" &&
chat.roomInfo.can_invite

View File

@@ -73,6 +73,7 @@ QtObject {
}
type === "Settings" ? window.settings = newData :
type === "NewTheme" ? window.themeRules = newData :
type === "UIState" ? window.uiState = newData :
type === "History" ? window.history = newData :
null

View File

@@ -21,12 +21,13 @@ PythonBridge {
addImportPath("qrc:/src")
importNames("backend.qml_bridge", ["BRIDGE"], () => {
callCoro("get_settings", [], ([settings, state, hist, theme]) => {
window.settings = settings
window.uiState = state
window.history = hist
window.theme = Qt.createQmlObject(theme, window, "theme")
utils.theme = window.theme
callCoro("get_settings", [], ([settings, state, hist, theme, themeRules]) => {
window.settings = settings
window.uiState = state
window.history = hist
window.theme = Qt.createQmlObject(theme, window, "theme")
utils.theme = window.theme
window.themeRules = themeRules
callCoro("saved_accounts.any_saved", [], any => {
if (any) { callCoro("load_saved_accounts", []) }

View File

@@ -519,4 +519,27 @@ QtObject {
return {word, start, end: seen}
}
function getClassPathRegex(obj) {
const regexParts = []
let parent = obj
while (parent) {
if (! parent.ntheme || ! parent.ntheme.classes.length) {
parent = parent.parent
continue
}
const names = []
const end = regexParts.length ? "\\.)?" : ")"
for (let i = 0; i < parent.ntheme.classes.length; i++)
names.push(parent.ntheme.classes[i].name)
regexParts.push("(" + names.join("|") + end)
parent = parent.parent
}
return new RegExp("^" + regexParts.reverse().join("") + "$")
}
}

View File

@@ -28,6 +28,7 @@ ApplicationWindow {
property var uiState: ({})
property var history: ({})
property var theme: null
property var themeRules: null
property string settingsFolder
readonly property var visibleMenus: ({})