Commit 2d8d8773 authored by Zren (Chris Holland)'s avatar Zren (Chris Holland)

ComboBox.contentItem must be a QQuickTextInput to fix autocomplete

See QQuickComboBoxPrivate::updateEditText()
https://github.com/qt/qtquickcontrols2/blob/dev/src/quicktemplates2/qquickcombobox.cpp#L426

By removing the MouseArea previously in the contentItem, we lose the
ability to press+hold+drag to select a drop down item.

A MouseArea has been added to the background component to capture
wheel events in a similar pattern to PlasmaComponents3.ComboBox.

The ComboBox previously closed the popup when releasing the click to
open the dropdown when editable=true.

BUG: 425865
parent 364ab2a6
......@@ -34,7 +34,7 @@ T.ComboBox {
delegate: ItemDelegate {
width: listView.width
text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
highlighted: mouseArea.pressed ? listView.currentIndex == index : controlRoot.highlightedIndex == index
highlighted: controlRoot.highlightedIndex == index
property bool separatorVisible: false
Kirigami.Theme.colorSet: controlRoot.Kirigami.Theme.inherit ? controlRoot.Kirigami.Theme.colorSet : Kirigami.Theme.View
Kirigami.Theme.inherit: controlRoot.Kirigami.Theme.inherit
......@@ -42,117 +42,50 @@ T.ComboBox {
indicator: Item {}
StylePrivate.PropertyWriter {
id: controlRootWriter
target: controlRoot
propertyName: 'currentIndex'
}
contentItem: MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton
preventStealing: true
property int indexUnderMouse: -1
onWheel: {
if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) {
controlRoot.incrementCurrentIndex();
} else {
controlRoot.decrementCurrentIndex();
}
}
onPressed: {
if (controlRoot.focusPolicy & Qt.ClickFocus) {
controlRoot.forceActiveFocus();
contentItem: T.TextField {
id: textField
padding: 0
text: controlRoot.editable ? controlRoot.editText : controlRoot.displayText
enabled: controlRoot.editable
autoScroll: controlRoot.editable
readOnly: controlRoot.down
visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable
inputMethodHints: controlRoot.inputMethodHints
validator: controlRoot.validator
// Work around Qt bug where NativeRendering breaks for non-integer scale factors
// https://bugreports.qt.io/browse/QTBUG-67007
renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
selectionColor: Kirigami.Theme.highlightColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectByMouse: !Kirigami.Settings.tabletMode
cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : null
font: controlRoot.font
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
opacity: controlRoot.enabled ? 1 : 0.3
onFocusChanged: {
if (focus) {
Private.MobileTextActionsToolBar.controlRoot = textField;
}
indexUnderMouse = -1;
listView.currentIndex = controlRoot.highlightedIndex
controlRoot.down = true;
controlRoot.pressed = true;
controlRoot.popup.visible = !controlRoot.popup.visible;
}
onReleased: {
if (!containsMouse) {
controlRoot.down = false;
controlRoot.pressed = false;
controlRoot.popup.visible = false;
}
if (indexUnderMouse > -1) {
controlRootWriter.writeProperty(indexUnderMouse);
controlRoot.activated(indexUnderMouse);
}
}
onCanceled: {
controlRoot.down = false;
controlRoot.pressed = false;
}
onPositionChanged: {
var pos = listView.mapFromItem(this, mouse.x, mouse.y);
indexUnderMouse = listView.indexAt(pos.x, pos.y);
listView.currentIndex = indexUnderMouse;
}
Connections {
target: popup
@DISABLE_AT_QT_5_14@ onClosed: {
@DISABLE_UNDER_QT_5_14@ function onClosed() {
controlRoot.down = false;
controlRoot.pressed = false;
}
}
T.TextField {
id: textField
padding: 0
anchors {
fill:parent
leftMargin: controlRoot.leftPadding
rightMargin: controlRoot.rightPadding
topMargin: controlRoot.topPadding
bottomMargin: controlRoot.bottomPadding
}
text: controlRoot.editable ? controlRoot.editText : controlRoot.displayText
enabled: controlRoot.editable
autoScroll: controlRoot.editable
readOnly: controlRoot.down
visible: typeof(controlRoot.editable) != "undefined" && controlRoot.editable
inputMethodHints: controlRoot.inputMethodHints
validator: controlRoot.validator
// Work around Qt bug where NativeRendering breaks for non-integer scale factors
// https://bugreports.qt.io/browse/QTBUG-67007
renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
selectionColor: Kirigami.Theme.highlightColor
selectedTextColor: Kirigami.Theme.highlightedTextColor
selectByMouse: !Kirigami.Settings.tabletMode
cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : null
font: controlRoot.font
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
opacity: controlRoot.enabled ? 1 : 0.3
onFocusChanged: {
if (focus) {
Private.MobileTextActionsToolBar.controlRoot = textField;
}
}
onTextChanged: Private.MobileTextActionsToolBar.shouldBeVisible = false;
onPressed: Private.MobileTextActionsToolBar.shouldBeVisible = true;
onTextChanged: Private.MobileTextActionsToolBar.shouldBeVisible = false;
onPressed: Private.MobileTextActionsToolBar.shouldBeVisible = true;
onPressAndHold: {
if (!Kirigami.Settings.tabletMode) {
return;
}
forceActiveFocus();
cursorPosition = positionAt(event.x, event.y);
selectWord();
onPressAndHold: {
if (!Kirigami.Settings.tabletMode) {
return;
}
forceActiveFocus();
cursorPosition = positionAt(event.x, event.y);
selectWord();
}
}
......@@ -186,6 +119,22 @@ T.ComboBox {
properties: {
"editable" : control.editable
}
MouseArea {
anchors {
fill: parent
leftMargin: controlRoot.leftPadding
rightMargin: controlRoot.rightPadding
}
acceptedButtons: Qt.NoButton
onWheel: {
if (wheel.pixelDelta.y < 0 || wheel.angleDelta.y < 0) {
controlRoot.incrementCurrentIndex();
} else {
controlRoot.decrementCurrentIndex();
}
}
}
}
popup: T.Popup {
......
......@@ -19,6 +19,13 @@ ApplicationWindow
}
}
ComboBox {
Layout.fillWidth: true
textRole: "key"
model: comboModel
editable: true
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
......
Markdown is supported
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