quickshell: fix menu delegate, use inline repeater
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e02e1f41c1
commit
5f1618e49c
1 changed files with 51 additions and 64 deletions
|
|
@ -750,82 +750,69 @@ in
|
||||||
Repeater {
|
Repeater {
|
||||||
model: menuOpener.children
|
model: menuOpener.children
|
||||||
|
|
||||||
Loader {
|
Rectangle {
|
||||||
required property var modelData
|
required property var modelData
|
||||||
width: 200
|
width: 200
|
||||||
sourceComponent: modelData.isSeparator ? separatorComp : menuItemComp
|
height: modelData.isSeparator ? 9 : 28
|
||||||
|
color: !modelData.isSeparator && itemMouse.containsMouse && modelData.enabled
|
||||||
|
? "#${c.base02}" : "transparent"
|
||||||
|
radius: modelData.isSeparator ? 0 : 4
|
||||||
|
|
||||||
|
// Separator line
|
||||||
|
Rectangle {
|
||||||
|
visible: modelData.isSeparator
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: parent.width - 20
|
||||||
|
height: 1
|
||||||
|
color: "#${c.base03}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Menu item content
|
||||||
|
RowLayout {
|
||||||
|
visible: !modelData.isSeparator
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.leftMargin: 10
|
||||||
|
anchors.rightMargin: 10
|
||||||
|
spacing: 8
|
||||||
|
|
||||||
|
Text {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
text: modelData.text ?? ""
|
||||||
|
color: modelData.enabled ? "#${c.base05}" : "#${c.base03}"
|
||||||
|
font.family: "FiraMono Nerd Font"
|
||||||
|
font.pixelSize: 12
|
||||||
|
elide: Text.ElideRight
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
visible: modelData.buttonType !== QsMenuButtonType.None
|
||||||
|
text: modelData.checkState === Qt.Checked ? "\u2713" : ""
|
||||||
|
color: "#${c.base0D}"
|
||||||
|
font.family: "FiraMono Nerd Font"
|
||||||
|
font.pixelSize: 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: itemMouse
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
enabled: !modelData.isSeparator && modelData.enabled
|
||||||
|
onClicked: {
|
||||||
|
modelData.triggered();
|
||||||
|
contextMenu.visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close when clicking outside
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
menuOpener.menu = null;
|
menuOpener.menu = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Menu item delegate
|
|
||||||
component MenuItemDelegate: Rectangle {
|
|
||||||
required property var modelData
|
|
||||||
width: 200
|
|
||||||
height: modelData.isSeparator ? 1 : 28
|
|
||||||
color: itemMouse.containsMouse && modelData.enabled ? "#${c.base02}" : "transparent"
|
|
||||||
radius: 4
|
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
anchors.fill: parent
|
|
||||||
anchors.leftMargin: 10
|
|
||||||
anchors.rightMargin: 10
|
|
||||||
spacing: 8
|
|
||||||
|
|
||||||
Text {
|
|
||||||
Layout.fillWidth: true
|
|
||||||
text: modelData.text ?? ""
|
|
||||||
color: modelData.enabled ? "#${c.base05}" : "#${c.base03}"
|
|
||||||
font.family: "FiraMono Nerd Font"
|
|
||||||
font.pixelSize: 12
|
|
||||||
elide: Text.ElideRight
|
|
||||||
}
|
|
||||||
|
|
||||||
Text {
|
|
||||||
visible: modelData.buttonType !== QsMenuButtonType.None
|
|
||||||
text: modelData.checkState === Qt.Checked ? "\u2713" : ""
|
|
||||||
color: "#${c.base0D}"
|
|
||||||
font.family: "FiraMono Nerd Font"
|
|
||||||
font.pixelSize: 12
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseArea {
|
|
||||||
id: itemMouse
|
|
||||||
anchors.fill: parent
|
|
||||||
hoverEnabled: true
|
|
||||||
enabled: modelData.enabled
|
|
||||||
onClicked: {
|
|
||||||
modelData.triggered();
|
|
||||||
contextMenu.visible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Separator delegate
|
|
||||||
component SeparatorDelegate: Rectangle {
|
|
||||||
width: 200
|
|
||||||
height: 9
|
|
||||||
color: "transparent"
|
|
||||||
Rectangle {
|
|
||||||
anchors.centerIn: parent
|
|
||||||
width: parent.width - 20
|
|
||||||
height: 1
|
|
||||||
color: "#${c.base03}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component { id: menuItemComp; MenuItemDelegate {} }
|
|
||||||
Component { id: separatorComp; SeparatorDelegate {} }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue