TRAY
This commit is contained in:
@@ -3,28 +3,13 @@ pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import QtQuick.Window // for Window, flags
|
||||
import qs.Modules
|
||||
|
||||
PopupWindow {
|
||||
id: popup
|
||||
color: "#FF202020"
|
||||
|
||||
property QsMenuHandle menuHandle
|
||||
property alias entries: menuModel
|
||||
|
||||
QsMenuOpener {
|
||||
id: menu
|
||||
menu: popup.menuHandle
|
||||
}
|
||||
|
||||
ListModel { id: menuModel }
|
||||
|
||||
implicitWidth: contentColumn.implicitWidth + 16
|
||||
implicitHeight: contentColumn.implicitHeight + 16
|
||||
|
||||
Rectangle {
|
||||
color: "#202020CC"
|
||||
radius: 4
|
||||
anchors.fill: parent
|
||||
}
|
||||
required property QsMenuOpener trayMenu
|
||||
|
||||
Column {
|
||||
id: contentColumn
|
||||
@@ -32,11 +17,10 @@ PopupWindow {
|
||||
spacing: 4
|
||||
Repeater {
|
||||
id: repeater
|
||||
model: menuModel
|
||||
model: popup.trayMenu.children
|
||||
Row {
|
||||
id: entryRow
|
||||
height: 30
|
||||
width: parent.implicitWidth
|
||||
anchors.fill: parent
|
||||
property var entry: modelData
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
@@ -54,33 +38,10 @@ PopupWindow {
|
||||
}
|
||||
Text {
|
||||
text: entryRow.entry.text
|
||||
color: "white"
|
||||
color: "black"
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rebuild() {
|
||||
menuModel.clear()
|
||||
console.log(menu.children.count)
|
||||
if (!menu) return
|
||||
for (let i = 0; i < menu.children.count; ++i) {
|
||||
let e = menu.children.get(i)
|
||||
menuModel.append({
|
||||
text: e.text,
|
||||
icon: e.icon,
|
||||
triggered: e.triggered,
|
||||
entryObject: e
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onMenuHandleChanged: rebuild
|
||||
Connections {
|
||||
target: menu
|
||||
function onCountChanged() {
|
||||
popup.rebuild
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-25
@@ -2,12 +2,10 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Widgets
|
||||
import Quickshell.Services.SystemTray
|
||||
import qs.Modules
|
||||
|
||||
IconImage {
|
||||
id: root
|
||||
required property SystemTrayItem item
|
||||
property var customMenu
|
||||
|
||||
source: root.item.icon
|
||||
implicitSize: 15
|
||||
@@ -19,34 +17,19 @@ IconImage {
|
||||
case Qt.LeftButton: root.item.activate(); break;
|
||||
case Qt.RightButton:
|
||||
if (root.item.hasMenu) {
|
||||
|
||||
root.customMenu = menuComponent.createObject(root);
|
||||
root.customMenu.menuHandle = root.item.menu;
|
||||
|
||||
const window = QsWindow.window;
|
||||
const widgetRect = window.contentItem.mapFromItem(root, 0, root.height + 4, root.width, root.height);
|
||||
root.customMenu.anchor.rect = widgetRect
|
||||
root.customMenu.anchor.window = window
|
||||
root.customMenu.anchor.adjustment = PopupAdjustment.Flip
|
||||
root.customMenu.visible = true;
|
||||
root.customMenu.rebuild();
|
||||
// menuAnchor.anchor.rect = widgetRect;
|
||||
// menuAnchor.open();
|
||||
const widgetRect = window.contentItem.mapFromItem(root, 0, root.height + 10 , root.width, root.height);
|
||||
menuAnchor.anchor.rect = widgetRect;
|
||||
menuAnchor.open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: menuComponent
|
||||
CustomTrayMenu {}
|
||||
QsMenuAnchor {
|
||||
id: menuAnchor
|
||||
menu: root.item.menu
|
||||
anchor.window: root.QsWindow.window?? null
|
||||
anchor.adjustment: PopupAdjustment.Flip
|
||||
}
|
||||
|
||||
// QsMenuAnchor {
|
||||
// id: menuAnchor
|
||||
// menu: root.item.menu
|
||||
// anchor.window: root.QsWindow.window?? null
|
||||
// anchor.adjustment: PopupAdjustment.Flip
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user