icons, width and centering
This commit is contained in:
@@ -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
|
||||||
|
|||||||
+54
-14
@@ -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 ) {
|
||||||
menuItem.modelData.triggered();
|
if ( menuItem.modelData.enabled ) {
|
||||||
root.visible = false;
|
menuItem.modelData.triggered();
|
||||||
|
root.visible = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
subMenuComponent.createObject( null, {
|
subMenuComponent.createObject( null, {
|
||||||
menu: menuItem.modelData,
|
menu: menuItem.modelData,
|
||||||
@@ -75,12 +97,30 @@ PopupWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
RowLayout {
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.fill: parent
|
||||||
anchors.left: parent.left
|
Text {
|
||||||
anchors.leftMargin: 10
|
id: menuText
|
||||||
text: menuItem.modelData.text
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
|
||||||
color: "white"
|
Layout.leftMargin: 10
|
||||||
|
text: menuItem.modelData.text
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user