bar: add date and background option for clock (#1198)

* bar: add date and background option for clock

* fix height binding loop qs WARN
This commit is contained in:
Ezekiel Gonzales 2026-03-19 19:39:35 +08:00 committed by GitHub
parent ffe90bd077
commit 7fbcf17899
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 80 additions and 21 deletions

View file

@ -337,6 +337,8 @@ default, you must create it manually.
"showOnHover": true "showOnHover": true
}, },
"clock": { "clock": {
"background": false,
"showDate": false,
"showIcon": true "showIcon": true
}, },
"dragThreshold": 20, "dragThreshold": 20,

View file

@ -113,6 +113,8 @@ JsonObject {
} }
component Clock: JsonObject { component Clock: JsonObject {
property bool background: false
property bool showDate: true
property bool showIcon: true property bool showIcon: true
} }

View file

@ -202,6 +202,8 @@ Singleton {
showLockStatus: bar.status.showLockStatus showLockStatus: bar.status.showLockStatus
}, },
clock: { clock: {
background: bar.clock.background,
showDate: bar.clock.showDate,
showIcon: bar.clock.showIcon showIcon: bar.clock.showIcon
}, },
entries: bar.entries, entries: bar.entries,

View file

@ -5,34 +5,65 @@ import qs.services
import qs.config import qs.config
import QtQuick import QtQuick
Column { StyledRect {
id: root id: root
property color colour: Colours.palette.m3tertiary readonly property color colour: Colours.palette.m3tertiary
readonly property int padding: Config.bar.clock.background ? Appearance.padding.normal : Appearance.padding.small
spacing: Appearance.spacing.small implicitWidth: Config.bar.sizes.innerWidth
implicitHeight: layout.implicitHeight + root.padding * 2
Loader { color: Qt.alpha(Colours.tPalette.m3surfaceContainer, Config.bar.clock.background ? Colours.tPalette.m3surfaceContainer.a : 0)
anchors.horizontalCenter: parent.horizontalCenter radius: Appearance.rounding.full
active: Config.bar.clock.showIcon Column {
visible: active id: layout
anchors.centerIn: parent
spacing: Appearance.spacing.small
sourceComponent: MaterialIcon { Loader {
text: "calendar_month" anchors.horizontalCenter: parent.horizontalCenter
active: Config.bar.clock.showIcon
visible: active
sourceComponent: MaterialIcon {
text: "calendar_month"
color: root.colour
}
}
StyledText {
anchors.horizontalCenter: parent.horizontalCenter
visible: Config.bar.clock.showDate
horizontalAlignment: StyledText.AlignHCenter
text: Time.format("ddd\nd")
font.pointSize: Appearance.font.size.smaller
font.family: Appearance.font.family.sans
color: root.colour
}
Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
visible: Config.bar.clock.showDate
height: visible ? 1 : 0
width: parent.width * 0.8
color: root.colour
opacity: 0.2
}
StyledText {
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: StyledText.AlignHCenter
text: Time.format(Config.services.useTwelveHourClock ? "hh\nmm\nA" : "hh\nmm")
font.pointSize: Appearance.font.size.smaller
font.family: Appearance.font.family.mono
color: root.colour color: root.colour
} }
} }
StyledText {
id: text
anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: StyledText.AlignHCenter
text: Time.format(Config.services.useTwelveHourClock ? "hh\nmm\nA" : "hh\nmm")
font.pointSize: Appearance.font.size.smaller
font.family: Appearance.font.family.mono
color: root.colour
}
} }

View file

@ -22,6 +22,8 @@ Item {
property bool activeWindowCompact: Config.bar.activeWindow.compact ?? false property bool activeWindowCompact: Config.bar.activeWindow.compact ?? false
property bool activeWindowInverted: Config.bar.activeWindow.inverted ?? false property bool activeWindowInverted: Config.bar.activeWindow.inverted ?? false
property bool clockShowIcon: Config.bar.clock.showIcon ?? true property bool clockShowIcon: Config.bar.clock.showIcon ?? true
property bool clockBackground: Config.bar.clock.background ?? false
property bool clockShowDate: Config.bar.clock.showDate ?? false
property bool persistent: Config.bar.persistent ?? true property bool persistent: Config.bar.persistent ?? true
property bool showOnHover: Config.bar.showOnHover ?? true property bool showOnHover: Config.bar.showOnHover ?? true
property int dragThreshold: Config.bar.dragThreshold ?? 20 property int dragThreshold: Config.bar.dragThreshold ?? 20
@ -69,6 +71,8 @@ Item {
function saveConfig(entryIndex, entryEnabled) { function saveConfig(entryIndex, entryEnabled) {
Config.bar.activeWindow.compact = root.activeWindowCompact; Config.bar.activeWindow.compact = root.activeWindowCompact;
Config.bar.activeWindow.inverted = root.activeWindowInverted; Config.bar.activeWindow.inverted = root.activeWindowInverted;
Config.bar.clock.background = root.clockBackground;
Config.bar.clock.showDate = root.clockShowDate;
Config.bar.clock.showIcon = root.clockShowIcon; Config.bar.clock.showIcon = root.clockShowIcon;
Config.bar.persistent = root.persistent; Config.bar.persistent = root.persistent;
Config.bar.showOnHover = root.showOnHover; Config.bar.showOnHover = root.showOnHover;
@ -537,6 +541,24 @@ Item {
font.pointSize: Appearance.font.size.normal font.pointSize: Appearance.font.size.normal
} }
SwitchRow {
label: qsTr("Background")
checked: root.clockBackground
onToggled: checked => {
root.clockBackground = checked;
root.saveConfig();
}
}
SwitchRow {
label: qsTr("Show date")
checked: root.clockShowDate
onToggled: checked => {
root.clockShowDate = checked;
root.saveConfig();
}
}
SwitchRow { SwitchRow {
label: qsTr("Show clock icon") label: qsTr("Show clock icon")
checked: root.clockShowIcon checked: root.clockShowIcon