diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml')
| -rw-r--r-- | accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml | 209 |
1 files changed, 209 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml b/accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml new file mode 100644 index 00000000..0e07ff59 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml | |||
| @@ -0,0 +1,209 @@ | |||
| 1 | import QtQml | ||
| 2 | import Quickshell | ||
| 3 | import QtQuick | ||
| 4 | import Quickshell.Widgets | ||
| 5 | import qs.Services | ||
| 6 | |||
| 7 | Item { | ||
| 8 | id: root | ||
| 9 | |||
| 10 | height: parent.height | ||
| 11 | width: (timeWidget.visible ? timeWidget.label.contentWidth + 8 : 0) + (todayWidget.visible ? todayWidget.label.contentWidth + 8 : 0) + (icon.visible ? icon.implicitWidth + 8 : 0) | ||
| 12 | anchors.verticalCenter: parent.verticalCenter | ||
| 13 | |||
| 14 | component TextWidget : Item { | ||
| 15 | id: textWidget | ||
| 16 | |||
| 17 | visible: textWidget.state.state?.text ?? false | ||
| 18 | |||
| 19 | required property var state | ||
| 20 | property alias label: label | ||
| 21 | property alias mouseArea: mouseArea | ||
| 22 | |||
| 23 | anchors.verticalCenter: parent.verticalCenter | ||
| 24 | implicitWidth: label.contentWidth + 8 | ||
| 25 | height: parent.height | ||
| 26 | |||
| 27 | WrapperMouseArea { | ||
| 28 | id: mouseArea | ||
| 29 | |||
| 30 | anchors.fill: parent | ||
| 31 | |||
| 32 | enabled: true | ||
| 33 | hoverEnabled: true | ||
| 34 | acceptedButtons: Qt.NoButton | ||
| 35 | cursorShape: Qt.PointingHandCursor | ||
| 36 | |||
| 37 | Item { | ||
| 38 | anchors.fill: parent | ||
| 39 | |||
| 40 | Text { | ||
| 41 | id: label | ||
| 42 | |||
| 43 | anchors.centerIn: parent | ||
| 44 | |||
| 45 | text: textWidget.state.state?.text ?? "" | ||
| 46 | |||
| 47 | font.pointSize: 10 | ||
| 48 | font.family: "Fira Sans" | ||
| 49 | font.strikeout: textWidget.state.strikeout | ||
| 50 | color: { | ||
| 51 | if (textWidget.state.state?.class == "running") | ||
| 52 | return "white"; | ||
| 53 | if (textWidget.state.state?.class == "over") | ||
| 54 | return "#f28a21"; | ||
| 55 | return "#555"; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | WrapperMouseArea { | ||
| 63 | id: mouseArea | ||
| 64 | |||
| 65 | anchors.fill: parent | ||
| 66 | hoverEnabled: true | ||
| 67 | |||
| 68 | cursorShape: Qt.PointingHandCursor | ||
| 69 | onClicked: { | ||
| 70 | Worktime.time.running = true; | ||
| 71 | Worktime.today.running = true; | ||
| 72 | } | ||
| 73 | |||
| 74 | Rectangle { | ||
| 75 | anchors.fill: parent | ||
| 76 | color: { | ||
| 77 | if (mouseArea.containsMouse) | ||
| 78 | return "#33808080"; | ||
| 79 | return "transparent"; | ||
| 80 | } | ||
| 81 | |||
| 82 | Row { | ||
| 83 | height: parent.height | ||
| 84 | anchors.centerIn: parent | ||
| 85 | spacing: 0 | ||
| 86 | |||
| 87 | TextWidget { | ||
| 88 | id: timeWidget | ||
| 89 | state: Worktime.time | ||
| 90 | } | ||
| 91 | |||
| 92 | TextWidget { | ||
| 93 | id: todayWidget | ||
| 94 | state: Worktime.today | ||
| 95 | } | ||
| 96 | |||
| 97 | MaterialDesignIcon { | ||
| 98 | id: icon | ||
| 99 | |||
| 100 | anchors.verticalCenter: parent.verticalCenter | ||
| 101 | |||
| 102 | implicitSize: 14 | ||
| 103 | |||
| 104 | visible: !timeWidget.visible && !todayWidget.visible | ||
| 105 | |||
| 106 | icon: (Worktime.time.running || Worktime.today.running) ? "update" : "timer-off" | ||
| 107 | color: "#555" | ||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | component WorktimePopup : PopupWindow { | ||
| 114 | id: tooltip | ||
| 115 | |||
| 116 | required property var state | ||
| 117 | required property var mouseArea | ||
| 118 | |||
| 119 | property bool nextVisible: (tooltipText.visible || tooltipIcon.visible) && (tooltip.mouseArea.containsMouse || tooltipMouseArea.containsMouse) | ||
| 120 | |||
| 121 | anchor { | ||
| 122 | item: tooltip.mouseArea | ||
| 123 | edges: Edges.Bottom | Edges.Left | ||
| 124 | } | ||
| 125 | visible: false | ||
| 126 | |||
| 127 | onNextVisibleChanged: hangTimer.restart() | ||
| 128 | |||
| 129 | Timer { | ||
| 130 | id: hangTimer | ||
| 131 | interval: 100 | ||
| 132 | onTriggered: tooltip.visible = tooltip.nextVisible | ||
| 133 | } | ||
| 134 | |||
| 135 | implicitWidth: (tooltipIcon.visible ? tooltipIcon.implicitWidth : 0) + (tooltipIcon.visible && tooltipText.visible ? 8 : 0) + (tooltipText.visible ? tooltipText.implicitWidth : 0) + 16 | ||
| 136 | implicitHeight: tooltipText.implicitHeight + 16 | ||
| 137 | color: "black" | ||
| 138 | |||
| 139 | WrapperMouseArea { | ||
| 140 | id: tooltipMouseArea | ||
| 141 | |||
| 142 | enabled: true | ||
| 143 | hoverEnabled: true | ||
| 144 | |||
| 145 | anchors.fill: parent | ||
| 146 | |||
| 147 | Item { | ||
| 148 | anchors.fill: parent | ||
| 149 | |||
| 150 | Row { | ||
| 151 | id: tooltipLayout | ||
| 152 | |||
| 153 | anchors { | ||
| 154 | left: parent.left | ||
| 155 | top: parent.top | ||
| 156 | leftMargin: 8 | ||
| 157 | topMargin: 8 | ||
| 158 | verticalCenter: parent.verticalCenter | ||
| 159 | } | ||
| 160 | |||
| 161 | height: parent.height | ||
| 162 | width: childrenRect.width | ||
| 163 | |||
| 164 | spacing: 0 | ||
| 165 | |||
| 166 | MaterialDesignIcon { | ||
| 167 | id: tooltipIcon | ||
| 168 | |||
| 169 | implicitSize: 14 | ||
| 170 | anchors.verticalCenter: parent.verticalCenter | ||
| 171 | |||
| 172 | visible: tooltip.state.running || !tooltip.state.updating | ||
| 173 | |||
| 174 | icon: tooltip.state.running ? "update" : "timer-off" | ||
| 175 | } | ||
| 176 | |||
| 177 | Item { | ||
| 178 | visible: tooltipIcon.visible && tooltipText.visible | ||
| 179 | height: parent.height | ||
| 180 | width: 8 | ||
| 181 | } | ||
| 182 | |||
| 183 | Text { | ||
| 184 | id: tooltipText | ||
| 185 | |||
| 186 | visible: tooltip.state.state?.tooltip ?? false | ||
| 187 | |||
| 188 | anchors.verticalCenter: parent.verticalCenter | ||
| 189 | |||
| 190 | font.pointSize: 10 | ||
| 191 | font.family: "Fira Sans" | ||
| 192 | color: "white" | ||
| 193 | |||
| 194 | text: tooltip.state.state?.tooltip ?? "" | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | WorktimePopup { | ||
| 202 | state: Worktime.time | ||
| 203 | mouseArea: timeWidget.mouseArea | ||
| 204 | } | ||
| 205 | WorktimePopup { | ||
| 206 | state: Worktime.today | ||
| 207 | mouseArea: todayWidget.mouseArea | ||
| 208 | } | ||
| 209 | } | ||
