From fb58c5a8cc721a3fd6449f297fba71c1273df6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Mon, 19 Aug 2024 16:47:50 +0200 Subject: [PATCH 1/3] [Controls] Prevent the filter text field from being out of the window The filter text field is now always placed at the position of the attribute, meaning it is always in sight. The list of values is then either dropped downwards or opened upwards depending on its size and where there is the most free space. --- meshroom/ui/qml/Controls/FilterComboBox.qml | 36 +++++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/meshroom/ui/qml/Controls/FilterComboBox.qml b/meshroom/ui/qml/Controls/FilterComboBox.qml index c51d9314d4..2463b35489 100644 --- a/meshroom/ui/qml/Controls/FilterComboBox.qml +++ b/meshroom/ui/qml/Controls/FilterComboBox.qml @@ -66,15 +66,34 @@ ComboBox { popup: Popup { width: combo.width - implicitHeight: contentItem.implicitHeight + implicitHeight: contentItem.implicitHeight + + x: 0 + y: 0 onAboutToShow: { filterTextArea.forceActiveFocus() - if (mapToGlobal(popup.x, popup.y).y + root.implicitHeight * (model.length + 1) > _window.contentItem.height) { - y = -((combo.height * (combo.model.length + 1) > _window.contentItem.height) ? _window.contentItem.height*2/3 : combo.height * (combo.model.length + 1)) + var dropDown = true + var posY = mapToGlobal(popup.x, popup.y).y + + /* If the list will go out of the screen by dropping down AND if there is more space up than down, + * then open it upwards. + * Having both conditions allows to naturally drop down short lists that are visually located close + * to the lower border of the window, while opening upwards long lists that are in that same location + * AND opening these same lists downwards if they are located closer to the upper border. + */ + if (posY + root.implicitHeight * (model.length * 1) > _window.contentItem.height + && posY > _window.contentItem.height / 2) { + dropDown = false + } + + if (dropDown) { + listView.anchors.bottom = undefined + listView.anchors.top = filterTextArea.bottom } else { - y = 0 + listView.anchors.bottom = filterTextArea.top + listView.anchors.top = undefined } } @@ -141,9 +160,14 @@ ComboBox { clip: true anchors.left: parent.left anchors.right: parent.right - anchors.top: filterTextArea.bottom - implicitHeight: (combo.height * (combo.model.length + 1) > _window.contentItem.height) ? _window.contentItem.height*2/3 : contentHeight + implicitHeight: { + if (combo.height * (combo.model.length + 1) > _window.contentItem.height) { + return _window.contentItem.height * 2 / 3 + } else { + return contentHeight + } + } model: combo.popup.visible ? combo.delegateModel : null ScrollBar.vertical: ScrollBar { From e445d7daf6cc19eba053159bc9843b98c2112b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Mon, 26 Aug 2024 08:40:18 +0100 Subject: [PATCH 2/3] [Controls] FilterComboBox: Correctly cancel selection or edition Up until this commit, any action causing the filtering text field to lose the focus was considered to be a valid edition, thus propagating the value in the text field or the one highlighted to be propagated, even if the user was clicking anywhere else in the application, or pressing the `esc` key. The distinction is now made between cases where the edition is finished because it was validated (value clicked on, or selected with the `return`/ `enter` key), and not because it was cancelled (clicks outside of the combobox or `esc` key pressed). --- meshroom/ui/qml/Controls/FilterComboBox.qml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/meshroom/ui/qml/Controls/FilterComboBox.qml b/meshroom/ui/qml/Controls/FilterComboBox.qml index 2463b35489..4e672c8476 100644 --- a/meshroom/ui/qml/Controls/FilterComboBox.qml +++ b/meshroom/ui/qml/Controls/FilterComboBox.qml @@ -18,6 +18,7 @@ ComboBox { property alias filterText: filterTextArea property bool validValue: true + property string previousText: "" // Used to restore displayText if the edition is cancelled enabled: root.editable model: { @@ -73,6 +74,9 @@ ComboBox { onAboutToShow: { filterTextArea.forceActiveFocus() + filterTextArea.editingCancelled = true + + previousText = displayText var dropDown = true var posY = mapToGlobal(popup.x, popup.y).y @@ -101,6 +105,8 @@ ComboBox { anchors.fill: parent TextArea { id: filterTextArea + + property bool editingCancelled: false leftPadding: 12 anchors.left: parent.left anchors.right: parent.right @@ -114,7 +120,12 @@ ComboBox { onEditingFinished: { combo.popup.close() - combo.editingFinished(displayText) + if (editingCancelled) { + displayText = previousText + filterTextArea.clear() + } else { + combo.editingFinished(displayText) + } } Keys.onEnterPressed: { @@ -123,6 +134,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -132,6 +144,7 @@ ComboBox { } else { displayText = currentText } + editingCancelled = false editingFinished() } @@ -200,4 +213,9 @@ ComboBox { onCurrentTextChanged: { displayText = currentText } + + onActivated: { + // This slot is entered when one of the element of the combo is clicked on, causing the popup to close + filterTextArea.editingCancelled = false + } } From 5eaec8ebb50d8e47e496ac30d8b24af34e66b75a Mon Sep 17 00:00:00 2001 From: Fabien Castan Date: Fri, 30 Aug 2024 21:40:48 +0200 Subject: [PATCH 3/3] [ui] FilterComboBox: better ordering --- meshroom/ui/qml/Controls/FilterComboBox.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/meshroom/ui/qml/Controls/FilterComboBox.qml b/meshroom/ui/qml/Controls/FilterComboBox.qml index 4e672c8476..348f538fb9 100644 --- a/meshroom/ui/qml/Controls/FilterComboBox.qml +++ b/meshroom/ui/qml/Controls/FilterComboBox.qml @@ -39,6 +39,10 @@ ComboBox { return -1 if (!nameA.startsWith(filterText) && nameB.startsWith(filterText)) return 1 + if (nameB > nameA) + return -1 + if (nameA > nameB) + return 1 return 0 }) } else {