-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBarWidget.qml
More file actions
149 lines (118 loc) · 4.34 KB
/
Copy pathBarWidget.qml
File metadata and controls
149 lines (118 loc) · 4.34 KB
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
import QtQuick
import Quickshell
import qs.Commons
import qs.Widgets
import qs.Modules.Bar.Extras
import qs.Services.UI
Item {
id: root
property QtObject pluginApi: null
readonly property QtObject pluginCore: pluginApi?.mainInstance
property ShellScreen screen
property string widgetId: ""
property string section: ""
property int sectionWidgetIndex: -1
property int sectionWidgetsCount: 0
property string tooltipContent: ""
Timer {
id: updateTimer
interval: 1000
running: true
repeat: true
onTriggered: updateTooltip()
}
function updateTooltip() {
if (!pluginCore || !pluginCore.eventsModel) {
tooltipContent = "";
return;
}
var events = pluginCore.eventsModel;
var now = new Date();
// Get start and end of today
var todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var todayEnd = new Date(todayStart);
todayEnd.setDate(todayEnd.getDate() + 1);
var currentEv = null;
var nextEv = null;
var hasEventsToday = false;
for (var i = 0; i < events.count; i++) {
var event = events.get(i);
var eventStart = event.startTime;
var eventEnd = event.endTime;
// Only consider events that occur today
var occursToday = (eventStart >= todayStart && eventStart < todayEnd) ||
(eventEnd > todayStart && eventEnd <= todayEnd) ||
(eventStart < todayStart && eventEnd > todayEnd);
if (!occursToday) {
continue;
}
hasEventsToday = true;
// Check if event is currently happening
if (now >= eventStart && now <= eventEnd) {
currentEv = event;
}
// Check for next event (starting later today)
if (!nextEv && eventStart > now && eventStart < todayEnd) {
nextEv = event;
}
if (currentEv && nextEv) break;
}
var tip = "";
if (currentEv) {
tip = pluginApi.tr("bar_widget.now") + ": " + currentEv.title + "\n" +
pluginCore.formatTimeRangeForDisplay(currentEv);
// If there's a current event and a next event
if (nextEv) {
tip += "\n\n" + pluginApi.tr("bar_widget.next") + ": " + nextEv.title + "\n" +
pluginCore.formatTimeRangeForDisplay(nextEv);
}
}
if (nextEv && !currentEv) {
// If no current event but there's a next event today
tip = pluginApi.tr("bar_widget.next") + ": " + nextEv.title + "\n" +
pluginCore.formatTimeRangeForDisplay(nextEv);
}
// If all events have passed today
if (!tip && hasEventsToday) {
tip = pluginApi.tr("bar_widget.no_more_events_today");
}
tooltipContent = tip;
}
Connections {
target: pluginCore
function onEventsModelChanged() { updateTooltip(); }
function onCurrentDateChanged() { updateTooltip(); }
}
implicitWidth: pill.width
implicitHeight: pill.height
BarPill {
id: pill
screen: root.screen
oppositeDirection: BarService.getPillDirection(root)
forceClose: true
icon: "calendar-week"
tooltipText: tooltipContent
onClicked: root.pluginApi?.openPanel(root.screen)
onRightClicked: {
PanelService.showContextMenu(contextMenu, pill, root.screen);
}
}
NPopupContextMenu {
id: contextMenu
model: [
{
"label": pluginApi.tr("bar_widget.settings"),
"action": "widget-settings",
"icon": "settings",
"enabled": true
}
]
onTriggered: action => {
contextMenu.close();
PanelService.closeContextMenu(root.screen);
if (action === "widget-settings") {
BarService.openPluginSettings(screen, pluginApi.manifest);
}
}
}
}