import QtQuick import "." // Reusable right-click menu. `model` is a plain JS array of // { label, icon, destructive, separator, action } entries. Rectangle { id: menu property var model: [] visible: false z: 1000 width: 180 radius: Theme.geometry.radiusMedium color: Theme.colors.background border.color: Theme.colors.border border.width: Theme.geometry.borderWidth height: column.implicitHeight + Theme.geometry.spacing function openAt(px, py) { x = px; y = py; visible = true; } function close() { visible = false; } // Absorb clicks inside the menu so they don't fall through to the backdrop. MouseArea { anchors.fill: parent } Column { id: column anchors.fill: parent anchors.margins: Theme.geometry.spacing / 2 Repeater { model: menu.model delegate: Rectangle { width: column.width height: modelData.separator ? 1 : 28 radius: modelData.separator ? 0 : Theme.geometry.radiusTiny color: modelData.separator ? Theme.colors.border : (itemMouse.containsMouse ? Theme.colors.surfaceHover : "transparent") Row { visible: !modelData.separator anchors.left: parent.left anchors.leftMargin: Theme.geometry.spacing anchors.verticalCenter: parent.verticalCenter spacing: Theme.geometry.spacing Text { text: modelData.icon || "" width: Theme.iconSize.small font.family: Theme.font.family font.pixelSize: Theme.type.caption color: modelData.destructive ? Theme.colors.alert : Theme.colors.text } Text { text: modelData.label || "" font.family: Theme.font.family font.pixelSize: Theme.type.caption color: modelData.destructive ? Theme.colors.alert : Theme.colors.text } } MouseArea { id: itemMouse anchors.fill: parent enabled: !modelData.separator hoverEnabled: true cursorShape: Qt.PointingHandCursor onClicked: { menu.close(); if (modelData.action) modelData.action(); } } } } } }