Files
quickshell/modules/bar/widgets/Clock.qml
T
2026-06-10 21:16:24 +02:00

88 lines
2.8 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Hyprland
import "../../../colors"
import "../../../config"
Rectangle { //workspace
id: timeAnchore
width: dateTimer.running ? Math.max(dateDisplay.width + timeDisplay.width + Config.spacing*3, bar.height) : Math.max(dateDisplay.width + timeDisplay.width + Config.spacing*2, bar.height)
height: bar.height
radius: Config.radius
color: timeAnchoreMouseArea.containsMouse ? Colors.tertiaryContainer : Colors.primaryContainer
border.color: (
timeAnchoreMouseArea.containsMouse ? Colors.tertiaryContainer_fg :
Colors.primaryContainer_fg
)
border.width: Config.border_width
MouseArea {
id: timeAnchoreMouseArea
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
Row {
id: row
spacing: Config.spacing
anchors.centerIn: parent
Text {
id: dateDisplay
property string currentDate: ""
text: currentDate
color: (
timeAnchoreMouseArea.containsMouse ? Colors.tertiary :
Colors.primary
)
font.pixelSize: Math.floor(bar.height/2)
font.family: "Inter, sans-serif"
Timer {
id: dateTimer
interval: 60000
running: false
repeat: true
triggeredOnStart: true
onTriggered: {
var now = new Date()
dateDisplay.currentDate = Qt.formatDate(now, "ddd, dd.MM.yyyy -")
}
}
}
Text {
id: timeDisplay
property string currentTime: ""
text: currentTime
color: (
timeAnchoreMouseArea.containsMouse ? Colors.tertiary :
Colors.primary
)
font.pixelSize: Math.floor(bar.height/2)
font.family: "Inter, sans-serif"
Component.onCompleted: {
var now = new Date()
currentTime = Qt.formatTime(now, "hh:mm:ss")
}
Timer {
interval: 1000
running: true
repeat: true
onTriggered: {
var now = new Date()
timeDisplay.currentTime = Qt.formatTime(now, "hh:mm:ss")
}
}
}
}
onClicked: {
dateDisplay.currentDate = "";
dateTimer.running = !dateTimer.running;
}
}
}