ComboBox: fix closing popup. Started to implement keyboard support

This commit is contained in:
vladest 2017-11-30 10:39:01 +01:00
parent 8c9e530adf
commit ac7a5ebc94

View file

@ -46,16 +46,18 @@ FocusScope {
visible: true visible: true
height: hifi.fontSizes.textFieldInput + 13 // Match height of TextField control. height: hifi.fontSizes.textFieldInput + 13 // Match height of TextField control.
onPressedChanged: { function previousItem() { listView.currentIndex = (listView.currentIndex + listView.count - 1) % listView.count; }
console.warn("on pressed", pressed, popup.visible) function nextItem() { listView.currentIndex = (listView.currentIndex + listView.count + 1) % listView.count; }
if (!pressed && popup.visible) { function selectCurrentItem() { root.currentIndex = listView.currentIndex; close(); /*hideList();*/ }
popup.visible = false function selectSpecificItem(index) { root.currentIndex = index; close();/*hideList();*/ }
down = undefined
} Keys.onUpPressed: previousItem();
} Keys.onDownPressed: nextItem();
Keys.onSpacePressed: selectCurrentItem();
Keys.onRightPressed: selectCurrentItem();
Keys.onReturnPressed: selectCurrentItem();
background: Rectangle { background: Rectangle {
id: background
gradient: Gradient { gradient: Gradient {
GradientStop { GradientStop {
position: 0.2 position: 0.2
@ -75,7 +77,7 @@ FocusScope {
indicator: Item { indicator: Item {
id: dropIcon id: dropIcon
anchors { right: parent.right; verticalCenter: parent.verticalCenter } anchors { right: parent.right; verticalCenter: parent.verticalCenter }
height: background.height height: root.height
width: height width: height
Rectangle { Rectangle {
width: 1 width: 1
@ -140,8 +142,10 @@ FocusScope {
: listView.contentHeight : listView.contentHeight
padding: 0 padding: 0
topPadding: 1 topPadding: 1
closePolicy: Popup.NoAutoClose
onVisibleChanged: console.warn("popup", visible) onClosed: {
root.accepted()
}
contentItem: ListView { contentItem: ListView {
id: listView id: listView
@ -303,6 +307,6 @@ FocusScope {
Component.onCompleted: { Component.onCompleted: {
isDesktop = (typeof desktop !== "undefined"); isDesktop = (typeof desktop !== "undefined");
//TODO: do we need this? //TODO: do we need this?
comboBox.popup.z = isDesktop ? desktop.zLevels.menu : 12 //comboBox.popup.z = isDesktop ? desktop.zLevels.menu : 12
} }
} }