mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-06-05 03:30:03 +00:00
NComboBox: fix clicking issue
This commit is contained in:
+35
-10
@@ -115,11 +115,31 @@ RowLayout {
|
||||
verticalPolicy: ScrollBar.AsNeeded
|
||||
|
||||
delegate: ItemDelegate {
|
||||
property var parentComboBox: combo // Reference to the ComboBox
|
||||
property int itemIndex: index // Explicitly capture index
|
||||
width: parentComboBox ? parentComboBox.width : 0
|
||||
property var parentComboBox: combo
|
||||
property int itemIndex: index
|
||||
width: ListView.view ? ListView.view.width : (parentComboBox ? parentComboBox.width - Style.marginM * 3 : 0)
|
||||
hoverEnabled: true
|
||||
highlighted: ListView.view.currentIndex === itemIndex
|
||||
|
||||
property bool pendingClick: false
|
||||
Timer {
|
||||
id: clickRetryTimer
|
||||
interval: 50
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
if (parent.pendingClick && parent.ListView.view && !parent.ListView.view.flicking && !parent.ListView.view.moving) {
|
||||
parent.pendingClick = false;
|
||||
var item = root.getItem(parent.itemIndex);
|
||||
if (item && item.key !== undefined && parent.parentComboBox) {
|
||||
root.selected(item.key);
|
||||
parent.parentComboBox.currentIndex = parent.itemIndex;
|
||||
parent.parentComboBox.popup.close();
|
||||
}
|
||||
} else if (parent.pendingClick) {
|
||||
restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onHoveredChanged: {
|
||||
if (hovered) {
|
||||
@@ -128,16 +148,22 @@ RowLayout {
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
var item = root.getItem(itemIndex);
|
||||
if (item && item.key !== undefined && parentComboBox) {
|
||||
root.selected(item.key);
|
||||
parentComboBox.currentIndex = itemIndex;
|
||||
parentComboBox.popup.close();
|
||||
if (ListView.view && (ListView.view.flicking || ListView.view.moving)) {
|
||||
ListView.view.cancelFlick();
|
||||
pendingClick = true;
|
||||
clickRetryTimer.start();
|
||||
} else {
|
||||
var item = root.getItem(itemIndex);
|
||||
if (item && item.key !== undefined && parentComboBox) {
|
||||
root.selected(item.key);
|
||||
parentComboBox.currentIndex = itemIndex;
|
||||
parentComboBox.popup.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
width: parentComboBox ? parentComboBox.width - Style.marginM * 3 : 0
|
||||
anchors.fill: parent
|
||||
color: highlighted ? Color.mHover : Color.transparent
|
||||
radius: Style.radiusS
|
||||
Behavior on color {
|
||||
@@ -173,7 +199,6 @@ RowLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// Update the currentIndex if the currentKey is changed externalyu
|
||||
Connections {
|
||||
target: root
|
||||
function onCurrentKeyChanged() {
|
||||
|
||||
Reference in New Issue
Block a user