blob: b58467b358b688837e90eb3472a9cb0ca9a8f10d (
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
 | import Quickshell
import QtQuick
import Quickshell.Widgets
import qs.Services
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Shapes
Item {
  id: root
  width: icon.width + 8
  height: parent.height
  anchors.verticalCenter: parent.verticalCenter
  WrapperMouseArea {
    id: widgetMouseArea
    anchors.fill: parent
    hoverEnabled: true
    cursorShape: Qt.PointingHandCursor
    onClicked: NotificationManager.displayInhibited = !NotificationManager.displayInhibited
    Rectangle {
      anchors.fill: parent
      color: {
	if (widgetMouseArea.containsMouse) {
	  return "#33808080";
	}
	return "transparent";
      }
      Item {
	anchors.fill: parent
	MaterialDesignIcon {
	  id: icon
	  implicitSize: 14
	  anchors.centerIn: parent
	  icon: NotificationManager.active ? "message" : "message-off"
	  color: {
	    if (!NotificationManager.active && !NotificationManager.displayInhibited)
	      return "#f28a21";
	    if (NotificationManager.displayInhibited)
	      return "white";
	    return "#555";
	  }
	}
      }
    }
  }
  Loader {
    id: tooltipLoader
    active: false
    Connections {
      target: widgetMouseArea
      function onContainsMouseChanged() {
       if (widgetMouseArea.containsMouse)
         tooltipLoader.active = true;
      }
    }
    sourceComponent: PopupWindow {
      id: tooltip
      property bool nextVisible: NotificationManager.active && (widgetMouseArea.containsMouse || tooltipMouseArea.containsMouse)
      anchor {
	item: widgetMouseArea
	edges: Edges.Bottom | Edges.Left
      }
      visible: false
      onNextVisibleChanged: hangTimer.restart()
      Timer {
	id: hangTimer
	interval: tooltip.visible ? 100 : 500
	onTriggered: {
	  tooltip.visible = tooltip.nextVisible;
	  if (!tooltip.visible)
	    tooltipLoader.active = false;
	}
      }
      implicitWidth: 400
      implicitHeight: Math.min(tooltip.screen.height * 0.66, Math.max(100, scroll.contentHeight + 16))
      color: "black"
      WrapperMouseArea {
	id: tooltipMouseArea
	hoverEnabled: true
	enabled: true
	anchors.fill: parent
	WrapperItem {
	  margin: 8
	  ScrollView {
	    id: scroll
	    contentWidth: availableWidth
	    // ScrollBar.vertical.policy: ScrollBar.AlwaysOn
	    ColumnLayout {
	      id: historyLayout
	      anchors {
	        left: parent.left
		right: parent.right
	      }
	      spacing: 8
	      Repeater {
		model: ScriptModel {
		  values: [...NotificationManager.history].reverse().map(o => o.notification)
		}
		delegate: GridLayout {
		  id: notif
		  Layout.fillWidth: true
		  Layout.preferredHeight: notifSummary.contentHeight + (notifBody.visible ? notifBody.contentHeight + 8 : 0) + (notifSep.visible ? notifSep.height + 8 : 0) + notifTime.contentHeight + 8
		  required property var modelData
		  required property int index
		  columnSpacing: 8
		  rowSpacing: 8
		  columns: notifImage.visible ? 2 : 1
		  rows: {
		    var res = 2;
		    if (notifBody.visible)
		      res += 1;
		    if (notifSep.visible)
		      res += 1;
		    return res;
		  }
		  Shape {
		    id: notifSep
		    visible: notif.index != 0
		    height: 2
		    width: 400 - 32
		    ShapePath {
		      strokeWidth: 2
		      strokeColor: "#20ffffff"
		      startX: 0; startY: 0;
		      PathLine { x: 400 - 32; y: 0; }
		    }
		    Layout.row: 0
		    Layout.column: 0
		    Layout.columnSpan: notifImage.visible ? 2 : 1
		    Layout.alignment: Qt.AlignHCenter
		  }
		  Text {
		    id: notifSummary
		    text: notif.modelData?.summary ?? ""
		    font.pointSize: 10
		    font.family: "Fira Sans"
		    font.italic: true
		    color: "white"
		    maximumLineCount: 1
		    elide: Text.ElideRight
		    Layout.fillWidth: true
		    Layout.row: notifSep.visible ? 1 : 0
		    Layout.column: notifImage.visible ? 1 : 0
		  }
		  Image {
		    id: notifImage
		    visible: (notif.modelData?.image || notif.modelData?.appIcon) ?? false
		    onStatusChanged: {
		      if (notifImage.status == Image.Error)
			notifImage.visible = false;
		    }
		    source: (notif.modelData?.image || notif.modelData?.appIcon) ?? ""
		    fillMode: Image.PreserveAspectFit
		    asynchronous: true
		    smooth: true
		    mipmap: true
		    Layout.maximumWidth: 50
		    Layout.column: 0
		    Layout.row: notifSep.visible ? 1 : 0
		    Layout.fillHeight: true
		    Layout.rowSpan: notifBody.visible ? 3 : 2
		  }
		  Text {
		    id: notifBody
		    visible: notif.modelData?.body ?? false
		    text: notif.modelData?.body ?? ""
		    textFormat: Text.RichText
		    wrapMode: Text.Wrap
		    font.pointSize: 10
		    font.family: "Fira Sans"
		    color: "white"
		    Layout.fillWidth: true
		    Layout.row: notifSep.visible ? 2 : 1
		    Layout.column: notifImage.visible ? 1 : 0
		  }
		  Text {
		    id: notifTime
		    Connections {
		      target: NotificationManager.clock
		      function onDateChanged() {
		        notifTime.text = NotificationManager.formatTime(notif.modelData?.receivedTime);
		      }
		    }
		    text: NotificationManager.formatTime(notif.modelData?.receivedTime)
		    font.pointSize: 8
		    font.family: "Fira Sans"
		    font.italic: true
		    color: "#555"
		    maximumLineCount: 1
		    horizontalAlignment: Text.AlignRight
		    Layout.fillWidth: true
		    Layout.row: {
		      var res = 1;
		      if (notifSep.visible)
		        res += 1;
		      if (notifBody.visible)
		        res += 1;
		      return res;
		    }
		    Layout.column: notifImage.visible ? 1 : 0
		  }
		}
	      }
	    }
	  }
	}
      }
    }
  }
}
 |