summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/WorktimeWidget.qml
blob: 0e07ff590462a36703234147684b74ff9fb3ac86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import QtQml
import Quickshell
import QtQuick
import Quickshell.Widgets
import qs.Services

Item {
  id: root

  height: parent.height
  width: (timeWidget.visible ? timeWidget.label.contentWidth + 8 : 0) + (todayWidget.visible ? todayWidget.label.contentWidth + 8 : 0) + (icon.visible ? icon.implicitWidth + 8 : 0)
  anchors.verticalCenter: parent.verticalCenter

  component TextWidget : Item {
    id: textWidget

    visible: textWidget.state.state?.text ?? false

    required property var state
    property alias label: label
    property alias mouseArea: mouseArea

    anchors.verticalCenter: parent.verticalCenter
    implicitWidth: label.contentWidth + 8
    height: parent.height

    WrapperMouseArea {
      id: mouseArea

      anchors.fill: parent

      enabled: true
      hoverEnabled: true
      acceptedButtons: Qt.NoButton
      cursorShape: Qt.PointingHandCursor

      Item {
	anchors.fill: parent

	Text {
	  id: label

	  anchors.centerIn: parent

	  text: textWidget.state.state?.text ?? ""

	  font.pointSize: 10
	  font.family: "Fira Sans"
	  font.strikeout: textWidget.state.strikeout
	  color: {
	    if (textWidget.state.state?.class == "running")
	      return "white";
	    if (textWidget.state.state?.class == "over")
	      return "#f28a21";
	    return "#555";
	  }
	}
      }
    }
  }

  WrapperMouseArea {
    id: mouseArea

    anchors.fill: parent
    hoverEnabled: true

    cursorShape: Qt.PointingHandCursor
    onClicked: {
      Worktime.time.running = true;
      Worktime.today.running = true;
    }

    Rectangle {
      anchors.fill: parent
      color: {
	if (mouseArea.containsMouse)
	  return "#33808080";
	return "transparent";
      }

      Row {
	height: parent.height
	anchors.centerIn: parent
	spacing: 0

	TextWidget {
	  id: timeWidget
	  state: Worktime.time
	}

	TextWidget {
	  id: todayWidget
	  state: Worktime.today
	}

	MaterialDesignIcon {
	  id: icon

	  anchors.verticalCenter: parent.verticalCenter

	  implicitSize: 14

	  visible: !timeWidget.visible && !todayWidget.visible

	  icon: (Worktime.time.running || Worktime.today.running) ? "update" : "timer-off"
	  color: "#555"
	}
      }
    }
  }

  component WorktimePopup : PopupWindow {
    id: tooltip

    required property var state
    required property var mouseArea

    property bool nextVisible: (tooltipText.visible || tooltipIcon.visible) && (tooltip.mouseArea.containsMouse || tooltipMouseArea.containsMouse)

    anchor {
      item: tooltip.mouseArea
      edges: Edges.Bottom | Edges.Left
    }
    visible: false

    onNextVisibleChanged: hangTimer.restart()

    Timer {
      id: hangTimer
      interval: 100
      onTriggered: tooltip.visible = tooltip.nextVisible
    }

    implicitWidth: (tooltipIcon.visible ? tooltipIcon.implicitWidth : 0) + (tooltipIcon.visible && tooltipText.visible ? 8 : 0) + (tooltipText.visible ? tooltipText.implicitWidth : 0) + 16
    implicitHeight: tooltipText.implicitHeight + 16
    color: "black"

    WrapperMouseArea {
      id: tooltipMouseArea

      enabled: true
      hoverEnabled: true

      anchors.fill: parent

      Item {
        anchors.fill: parent

	Row {
	  id: tooltipLayout

	  anchors {
	    left: parent.left
	    top: parent.top
	    leftMargin: 8
	    topMargin: 8
	    verticalCenter: parent.verticalCenter
	  }

	  height: parent.height
	  width: childrenRect.width

	  spacing: 0

	  MaterialDesignIcon {
	    id: tooltipIcon

	    implicitSize: 14
  	    anchors.verticalCenter: parent.verticalCenter

	    visible: tooltip.state.running || !tooltip.state.updating

	    icon: tooltip.state.running ? "update" : "timer-off"
	  }

	  Item {
	    visible: tooltipIcon.visible && tooltipText.visible
	    height: parent.height
	    width: 8
	  }

	  Text {
	    id: tooltipText

	    visible: tooltip.state.state?.tooltip ?? false

  	    anchors.verticalCenter: parent.verticalCenter

	    font.pointSize: 10
	    font.family: "Fira Sans"
	    color: "white"

	    text: tooltip.state.state?.tooltip ?? ""
	  }
	}
      }
    }
  }

  WorktimePopup {
    state: Worktime.time
    mouseArea: timeWidget.mouseArea
  }
  WorktimePopup {
    state: Worktime.today
    mouseArea: todayWidget.mouseArea
  }
}