Commit f793c3e2 authored by ivan tkachenko's avatar ivan tkachenko Committed by Nate Graham
Browse files

[applets/appmenu] Flatten MouseArea's functionality into MenuDelegate

MenuDelegate is a QQC2.Control's subclass, which is perfectly capable of
handling hover and press events on its own. Besides, few extra
properties and a custom signal make it feel like a dedicated component
which it really is.
parent fe005203
......@@ -13,8 +13,27 @@ import org.kde.kirigami 2.12 as Kirigami
AbstractButton {
id: controlRoot
property bool menuIsOpen: false
signal activated()
// QMenu opens on press, so we'll replicate that here
hoverEnabled: true
// This will trigger even if hoverEnabled has just became true and the
// mouse cursor is already hovering.
//
// In practice, this never works, at least on X11: when menuIsOpen the
// hover event would not be delivered. Instead we rely on
// plasmoid.nativeInterface.requestActivateIndex signal to filter
// QEvent::MouseMove events and tell us when to change the index.
onHoveredChanged: if (hovered && menuIsOpen) { activated(); }
// You don't actually have to "close" the menu via click/pressed handlers.
// Instead, the menu will be closed automatically, as by any
// other "outside of the menu" click event.
onPressed: activated()
enum State {
Rest,
Hover,
......
......@@ -77,14 +77,14 @@ Item {
const idx = Math.max(0, Math.min(buttonRepeater.count - 1, index));
const button = buttonRepeater.itemAt(index);
if (button) {
button.clicked();
button.activated();
}
});
Plasmoid.activated.connect(() => {
const button = buttonRepeater.itemAt(0);
if (button) {
button.clicked();
button.activated();
}
});
}
......@@ -118,20 +118,12 @@ Item {
Kirigami.MnemonicData.active: keystateSource.data.Alt !== undefined && keystateSource.data.Alt.Pressed
down: pressed || Plasmoid.nativeInterface.currentIndex === index
visible: text !== "" && model.activeActions.visible
onClicked: {
Plasmoid.nativeInterface.trigger(this, index);
checked = Qt.binding(() => plasmoid.nativeInterface.currentIndex === index);
}
// QMenu opens on press, so we'll replicate that here
MouseArea {
anchors.fill: parent
hoverEnabled: Plasmoid.nativeInterface.currentIndex !== -1
onPressed: parent.clicked()
onEntered: parent.clicked()
menuIsOpen: Plasmoid.nativeInterface.currentIndex !== -1
onActivated: {
Plasmoid.nativeInterface.trigger(this, index);
checked = Qt.binding(() => Plasmoid.nativeInterface.currentIndex === index);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment