BarWidgets: All the right click contextual menus. Fix #541

This commit is contained in:
ItsLemmy
2025-11-17 22:47:17 -05:00
parent f3207b526f
commit c407edb4e9
27 changed files with 951 additions and 68 deletions
+46 -4
View File
@@ -1,7 +1,9 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import qs.Commons
import qs.Modules.Bar.Extras
import qs.Services.UI
import qs.Widgets
@@ -115,11 +117,42 @@ Rectangle {
}
}
NPopupContextMenu {
id: contextMenu
model: [
{
"label": I18n.tr("context-menu.open-calendar"),
"action": "open-calendar",
"icon": "calendar"
},
{
"label": I18n.tr("context-menu.widget-settings"),
"action": "widget-settings",
"icon": "settings"
},
]
onTriggered: action => {
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
popupMenuWindow.close();
}
if (action === "open-calendar") {
PanelService.getPanel("calendarPanel", screen)?.toggle(root);
} else if (action === "widget-settings") {
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
}
}
}
MouseArea {
id: clockMouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onEntered: {
if (!PanelService.getPanel("calendarPanel", screen)?.active) {
TooltipService.show(root, I18n.tr("clock.tooltip"), BarService.getTooltipDirection());
@@ -128,9 +161,18 @@ Rectangle {
onExited: {
TooltipService.hide();
}
onClicked: {
TooltipService.hide();
PanelService.getPanel("calendarPanel", screen)?.toggle(this);
}
onClicked: mouse => {
TooltipService.hide();
if (mouse.button === Qt.RightButton) {
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
if (popupMenuWindow) {
const pos = BarService.getContextMenuPosition(root, contextMenu.implicitWidth, contextMenu.implicitHeight);
contextMenu.openAtItem(root, pos.x, pos.y);
popupMenuWindow.showContextMenu(contextMenu);
}
} else {
PanelService.getPanel("calendarPanel", screen)?.toggle(this);
}
}
}
}