Customtray #3

Merged
Zacharias-Brohn merged 6 commits from customtray into main 2025-11-02 22:26:25 +01:00
3 changed files with 60 additions and 17 deletions
Showing only changes of commit 7fd2e8d1df - Show all commits
+5 -2
View File
@@ -44,6 +44,7 @@ MouseArea {
ImageAnalyser { ImageAnalyser {
id: analyser id: analyser
sourceItem: icon sourceItem: icon
rescaleSize: 20
} }
TrayMenu { TrayMenu {
@@ -51,8 +52,10 @@ MouseArea {
menu: root.item.menu menu: root.item.menu
anchor.item: root anchor.item: root
anchor.edges: Edges.Bottom anchor.edges: Edges.Bottom
anchor.margins { onVisibleChanged: {
left: -270 if ( grab.active && !visible ) {
grab.active = false;
}
} }
HyprlandFocusGrab { HyprlandFocusGrab {
id: grab id: grab
+50 -10
View File
@@ -3,17 +3,27 @@ pragma ComponentBehavior: Bound
import Quickshell import Quickshell
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import Quickshell.Hyprland import Quickshell.Hyprland
PopupWindow { PopupWindow {
id: root id: root
required property QsMenuHandle menu required property QsMenuHandle menu
property int height: entryCount * ( entryHeight + 3 ) property int height: {
let count = 0;
for (let i = 0; i < repeater.count; i++) {
if (!repeater.itemAt(i).modelData.isSeparator) count++;
}
return count * (entryHeight + 3);
}
property int entryHeight: 30 property int entryHeight: 30
property int entryCount: 0 property int maxWidth
implicitWidth: 300 implicitWidth: maxWidth + 20
implicitHeight: height implicitHeight: height
color: "transparent" color: "transparent"
anchor.margins {
left: -implicitWidth
}
QsMenuOpener { QsMenuOpener {
id: menuOpener id: menuOpener
@@ -36,18 +46,28 @@ PopupWindow {
model: menuOpener.children model: menuOpener.children
Rectangle { Rectangle {
id: menuItem id: menuItem
property bool containsMouseAndEnabled: mouseArea.containsMouse && menuItem.modelData.enabled
property bool containsMouseAndNotEnabled: mouseArea.containsMouse && !menuItem.modelData.enabled
width: root.implicitWidth width: root.implicitWidth
Layout.maximumWidth: parent.width Layout.maximumWidth: parent.width
Layout.fillHeight: true Layout.fillHeight: true
height: root.entryHeight height: root.entryHeight
color: mouseArea.containsMouse && !modelData.isSeparator ? "#15FFFFFF" : "transparent" color: modelData.isSeparator ? "transparent" : containsMouseAndEnabled ? "#15FFFFFF" : containsMouseAndNotEnabled ? "#08FFFFFF" : "transparent"
radius: 4 radius: 4
visible: modelData.isSeparator ? false : true visible: modelData.isSeparator ? false : true
required property QsMenuEntry modelData required property QsMenuEntry modelData
TextMetrics {
id: textMetrics
font: menuText.font
text: menuItem.modelData.text
}
Component.onCompleted: { Component.onCompleted: {
if ( !modelData.isSeparator ) { // Measure text width to determine maximumWidth
root.entryCount += 1; var textWidth = textMetrics.width + 20 + (iconImage.width > 0 ? iconImage.width + 10 : 0);
if ( textWidth > root.maxWidth ) {
root.maxWidth = textWidth
} }
} }
@@ -60,8 +80,10 @@ PopupWindow {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onClicked: { onClicked: {
if ( !menuItem.modelData.hasChildren ) { if ( !menuItem.modelData.hasChildren ) {
if ( menuItem.modelData.enabled ) {
menuItem.modelData.triggered(); menuItem.modelData.triggered();
root.visible = false; root.visible = false;
}
} else { } else {
subMenuComponent.createObject( null, { subMenuComponent.createObject( null, {
menu: menuItem.modelData, menu: menuItem.modelData,
@@ -75,12 +97,30 @@ PopupWindow {
} }
} }
RowLayout {
anchors.fill: parent
Text { Text {
anchors.verticalCenter: parent.verticalCenter id: menuText
anchors.left: parent.left Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
anchors.leftMargin: 10 Layout.leftMargin: 10
text: menuItem.modelData.text text: menuItem.modelData.text
color: "white" color: menuItem.modelData.enabled ? "white" : "gray"
}
Image {
id: iconImage
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
Layout.rightMargin: 10
Layout.maximumWidth: 20
Layout.maximumHeight: 20
source: menuItem.modelData.icon
sourceSize.width: width
sourceSize.height: height
fillMode: Image.PreserveAspectFit
layer.enabled: true
layer.effect: ColorOverlay {
color: menuItem.modelData.enabled ? "white" : "gray"
}
}
} }
} }
} }
+1 -1
View File
@@ -3,5 +3,5 @@ import Quickshell
Scope { Scope {
Bar {} Bar {}
Wallpaper {} // Wallpaper {}
} }