Add compact clock again

This commit is contained in:
Ly-sec 2025-09-13 17:46:38 +02:00
parent 2a1e7832d6
commit b443c9f492

View file

@ -39,6 +39,17 @@ Rectangle {
implicitWidth: useCompactMode ? Math.round(Style.capsuleHeight * scaling) : Math.round(layout.implicitWidth + Style.marginM * 2 * scaling) implicitWidth: useCompactMode ? Math.round(Style.capsuleHeight * scaling) : Math.round(layout.implicitWidth + Style.marginM * 2 * scaling)
implicitHeight: useCompactMode ? Math.round(Style.capsuleHeight * 2.5 * scaling) : Math.round(Style.capsuleHeight * scaling) implicitHeight: useCompactMode ? Math.round(Style.capsuleHeight * 2.5 * scaling) : Math.round(Style.capsuleHeight * scaling)
// React to bar position changes
Connections {
target: BarService
function onBarPositionChanged(newPosition) {
root.barPosition = newPosition
// Force re-evaluation of implicitWidth and implicitHeight
root.implicitWidth = Qt.binding(() => useCompactMode ? Math.round(Style.capsuleHeight * scaling) : Math.round(layout.implicitWidth + Style.marginM * 2 * scaling))
root.implicitHeight = Qt.binding(() => useCompactMode ? Math.round(Style.capsuleHeight * 2.5 * scaling) : Math.round(Style.capsuleHeight * scaling))
}
}
radius: Math.round(Style.radiusS * scaling) radius: Math.round(Style.radiusS * scaling)
color: Color.mSurfaceVariant color: Color.mSurfaceVariant
@ -64,18 +75,20 @@ Rectangle {
if (useCompactMode) { if (useCompactMode) {
// Compact mode: time section (first 2 lines) // Compact mode: time section (first 2 lines)
switch (index) { switch (index) {
case 0: // Hours case 0:
if (use12h) { // Hours
const hours = now.getHours() if (use12h) {
const displayHours = hours === 0 ? 12 : (hours > 12 ? hours - 12 : hours) const hours = now.getHours()
return displayHours.toString().padStart(2, '0') const displayHours = hours === 0 ? 12 : (hours > 12 ? hours - 12 : hours)
} else { return displayHours.toString().padStart(2, '0')
return now.getHours().toString().padStart(2, '0') } else {
} return now.getHours().toString().padStart(2, '0')
case 1: // Minutes }
return now.getMinutes().toString().padStart(2, '0') case 1:
default: // Minutes
return "" return now.getMinutes().toString().padStart(2, '0')
default:
return ""
} }
} else { } else {
// Normal mode: single line with time // Normal mode: single line with time
@ -152,12 +165,14 @@ Rectangle {
if (useCompactMode) { if (useCompactMode) {
// Compact mode: date section (last 2 lines) // Compact mode: date section (last 2 lines)
switch (index) { switch (index) {
case 0: // Day case 0:
return now.getDate().toString().padStart(2, '0') // Day
case 1: // Month return now.getDate().toString().padStart(2, '0')
return (now.getMonth() + 1).toString().padStart(2, '0') case 1:
default: // Month
return "" return (now.getMonth() + 1).toString().padStart(2, '0')
default:
return ""
} }
} }
return "" return ""