Skip to content

Commit

Permalink
feat: unified background areas
Browse files Browse the repository at this point in the history
Removed the default layout spacing and added our own, to the left of each widget (or top for vertival panel)
Uses a MiltiEffect mask and paddingRect to hide border/shadow when needed

refs: #39
  • Loading branch information
luisbocanegra committed Sep 29, 2024
1 parent 431b3ac commit ba5ed59
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 41 deletions.
16 changes: 11 additions & 5 deletions package/contents/config/config.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ ConfigModel {
source: "configGeneral.qml"
}

ConfigCategory {
name: i18n("Presets autoloading")
icon: "system-run"
source: "configPresetAutoload.qml"
}

ConfigCategory {
name: i18n("Appearance")
icon: "preferences"
source: "configUnified.qml"
}

ConfigCategory {
name: i18n("Overrides")
name: i18n("Unified backgrounds")
icon: "preferences"
source: "configPerWidget.qml"
source: "configUnifiedBackground.qml"
}

ConfigCategory {
name: i18n("Presets autoloading")
icon: "system-run"
source: "configPresetAutoload.qml"
name: i18n("Overrides")
icon: "preferences"
source: "configPerWidget.qml"
}

ConfigCategory {
Expand Down
16 changes: 14 additions & 2 deletions package/contents/ui/code/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ const basePadding = {
},
}

const baseUnfiedBackground = {
"org.kde.plasma.digitalclock": 0
}

const basePanelConfig = {
"enabled": false,
"blurBehind": false,
Expand All @@ -164,6 +168,7 @@ const basePanelConfig = {
"padding": basePadding,
"border": baseBorder,
"shadow": baseShadowConfig,
"unfiedBackground": baseUnfiedBackground
}

const baseWidgetConfig = {
Expand All @@ -176,6 +181,7 @@ const baseWidgetConfig = {
"spacing": 3,
"border": baseBorder,
"shadow": baseShadowConfig,
"unfiedBackground": baseUnfiedBackground
}

const baseTrayConfig = {
Expand All @@ -187,6 +193,7 @@ const baseTrayConfig = {
"margin": baseMargin,
"border": baseBorder,
"shadow": baseShadowConfig,
"unfiedBackground": baseUnfiedBackground
}

const baseOverrideConfig = {
Expand Down Expand Up @@ -238,7 +245,12 @@ const defaultConfig = {
"floating": false
},
"configurationOverrides": {},
"overrideAssociations": {}
"overrideAssociations": {},
"unifiedBackground": {
"org.kde.netspeedWidget": 1,
"org.kde.plasma.systemtray": 2,
"org.kde.plasma.digitalclock": 3
}
}

const ignoredConfigs = [
Expand All @@ -247,5 +259,5 @@ const ignoredConfigs = [
"panelWidgets",
"objectName",
"lastPreset",
"presetAutoloading"
"presetAutoloading",
]
106 changes: 106 additions & 0 deletions package/contents/ui/components/WidgetCardUnifiedBg.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.kde.kirigami as Kirigami

Kirigami.AbstractCard {
id: root
property var widget
signal updateWidget(unifyBgType: int)
checked: widget.unifyBgType !== 0

contentItem: RowLayout {
Kirigami.Icon {
width: Kirigami.Units.gridUnit
height: width
source: widget.icon
}
ColumnLayout {
RowLayout {
Label {
text: widget.title
}
Rectangle {
visible: widget.inTray
color: Kirigami.Theme.highlightColor
Kirigami.Theme.colorSet: root.Kirigami.Theme["Selection"]
radius: parent.height / 2
width: label.width + 12
height: label.height + 2
Kirigami.Theme.inherit: false
Label {
anchors.centerIn: parent
id: label
text: i18n("System Tray")
color: Kirigami.Theme.textColor
Kirigami.Theme.colorSet: root.Kirigami.Theme["Selection"]
Kirigami.Theme.inherit: false
}
}
}
TextEdit {
text: widget.name
opacity: 0.6
readOnly: true
color: Kirigami.Theme.textColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectionColor: Kirigami.Theme.highlightColor
}
}
Item {
Layout.fillWidth: true
}
Button {
text: i18n("D")
checkable: true
checked: widget?.unifyBgType === index
icon.name: checked ? "checkmark-symbolic" : "dialog-close-symbolic"
Layout.preferredWidth: 50
property int index: 0
ButtonGroup.group: unifyButtonGroup
}
Button {
text: i18n("S")
checkable: true
checked: widget?.unifyBgType === index
icon.name: checked ? "checkmark-symbolic" : "dialog-close-symbolic"
Layout.preferredWidth: 50
property int index: 1
ButtonGroup.group: unifyButtonGroup
}
Button {
text: i18n("M")
checkable: true
checked: widget?.unifyBgType === index
icon.name: checked ? "checkmark-symbolic" : "dialog-close-symbolic"
Layout.preferredWidth: 50
property int index: 2
ButtonGroup.group: unifyButtonGroup
}
Button {
text: i18n("E")
checkable: true
checked: widget?.unifyBgType === index
icon.name: checked ? "checkmark-symbolic" : "dialog-close-symbolic"
property int index: 3
Layout.preferredWidth: 50
ButtonGroup.group: unifyButtonGroup
}
ButtonGroup {
id: unifyButtonGroup
onCheckedButtonChanged: {
if (checkedButton) {
widget.unifyBgType = checkedButton.index
updateWidget(widget.unifyBgType)
}
}
}
// ComboBox {
// model: ["Disabled", "Start", "Middle", "End"]
// currentIndex: widget?.unifyBgType ?? 0
// onCurrentIndexChanged: {
// updateWidget(currentIndex)
// }
// }
}
}
124 changes: 124 additions & 0 deletions package/contents/ui/configUnifiedBackground.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.kde.kcmutils as KCM
import org.kde.kirigami as Kirigami
import org.kde.plasma.plasmoid
import "components" as Components
import "code/utils.js" as Utils

KCM.SimpleKCM {
id:root
property alias cfg_isEnabled: headerComponent.isEnabled
property string cfg_panelWidgets
property bool clearing: false
property string cfg_allSettings
property var config: JSON.parse(cfg_allSettings)
property var unifiedBackgroundSettings
property bool loaded: false
property string configDir: StandardPaths.writableLocation(
StandardPaths.HomeLocation).toString().substring(7) + "/.config/panel-colorizer/"
property string importCmd: "cat '" + configDir + "forceForegroundColor.json'"
property string crateConfigDirCmd: "mkdir -p " + configDir

Component.onCompleted: {
unifiedBackgroundSettings = config.unifiedBackground
console.error(JSON.stringify(unifiedBackgroundSettings, null, null))
initWidgets()
updateWidgetsModel()
}

function updateConfig() {
for (let i = 0; i < widgetsModel.count; i++) {
const widget = widgetsModel.get(i)
const widgetName = widget.name
const unifyBgType = widget.unifyBgType
console.error(widgetName, unifyBgType)
unifiedBackgroundSettings[widgetName] = unifyBgType
}
config.unifiedBackground = unifiedBackgroundSettings
cfg_allSettings = JSON.stringify(config, null, null)
}

ListModel {
id: widgetsModel
}

RunCommand {
id: runCommand
}

function initWidgets(){
widgetsModel.clear()
const object = JSON.parse(cfg_panelWidgets)
for (const widget of object) {
const name = widget.name
const title = widget.title
const icon = widget.icon
const inTray = widget.inTray
if (inTray) continue
widgetsModel.append({
"name": name, "title": title, "icon": icon, "inTray":inTray,
"unifyBgType": 0
})
}
}

function updateWidgetsModel(){
for (let i = 0; i < widgetsModel.count; i++) {
const widget = widgetsModel.get(i)
const name = widget.name
if (name in unifiedBackgroundSettings) {
let unifyBgType = unifiedBackgroundSettings[name]
widgetsModel.set(i, {"unifyBgType": unifyBgType})
} else {
widgetsModel.set(i, {"unifyBgType": 0})
}
}
loaded = true
}

header: ColumnLayout {
Components.Header {
id: headerComponent
Layout.leftMargin: Kirigami.Units.mediumSpacing
Layout.rightMargin: Kirigami.Units.mediumSpacing
}
}

ColumnLayout {

Kirigami.FormLayout {
Kirigami.Separator {
Kirigami.FormData.isSection: true
Kirigami.FormData.label: i18n("Unify widget backgrounds")
}
}
Kirigami.FormLayout {

Label {
text: i18n("<strong>[D]isabled</strong><br><strong>[S]tart</strong> unified background<br><strong>[M]iddle</strong>: unified background<br><strong>[E]nd</strong> unified background")
opacity: 0.7
Layout.maximumWidth: widgetCards.width
wrapMode: Text.Wrap
}

ColumnLayout {
id: widgetCards
Repeater {
model: widgetsModel
delegate: Components.WidgetCardUnifiedBg {
widget: model
onUpdateWidget: (unifyBgType) => {
if (!loaded) return
console.log(model.name, unifyBgType)
widgetsModel.set(index, {"unifyBgType": unifyBgType})
root.updateConfig()
}
}
}
}
}
}
}
Loading

0 comments on commit ba5ed59

Please sign in to comment.