Fix tab order after expanding categories or using search

This reimplements the behavior of pressing tab/backtab to force the correct order of items in the listview.
This commit is contained in:
fieldOfView 2017-06-26 14:35:37 +02:00
parent 8917762ed5
commit 0f9cfa0304
8 changed files with 93 additions and 2 deletions

View file

@ -19,6 +19,9 @@ Button {
signal contextMenuRequested() signal contextMenuRequested()
signal showAllHiddenInheritedSettings(string category_id) signal showAllHiddenInheritedSettings(string category_id)
signal focusReceived() signal focusReceived()
signal setActiveFocusToNextSetting(bool forward)
property var focusItem: base
text: definition.label text: definition.label
iconSource: UM.Theme.getIcon(definition.icon) iconSource: UM.Theme.getIcon(definition.icon)
@ -44,6 +47,15 @@ Button {
} }
} }
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
UM.SimpleButton UM.SimpleButton
{ {
id: settingsButton id: settingsButton

View file

@ -11,13 +11,13 @@ import UM 1.2 as UM
SettingItem SettingItem
{ {
id: base id: base
property var focusItem: control
contents: MouseArea contents: MouseArea
{ {
id: control id: control
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
activeFocusOnTab: true
property bool checked: property bool checked:
{ {
@ -62,6 +62,15 @@ SettingItem
propertyProvider.setPropertyValue("value", !checked); propertyProvider.setPropertyValue("value", !checked);
} }
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
onActiveFocusChanged: onActiveFocusChanged:
{ {
if(activeFocus) if(activeFocus)

View file

@ -10,6 +10,7 @@ import UM 1.1 as UM
SettingItem SettingItem
{ {
id: base id: base
property var focusItem: control
contents: ComboBox contents: ComboBox
{ {
@ -108,6 +109,15 @@ SettingItem
} }
} }
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
Binding Binding
{ {
target: control target: control

View file

@ -11,6 +11,7 @@ import Cura 1.0 as Cura
SettingItem SettingItem
{ {
id: base id: base
property var focusItem: control
contents: ComboBox contents: ComboBox
{ {
@ -35,6 +36,15 @@ SettingItem
} }
} }
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
currentIndex: propertyProvider.properties.value currentIndex: propertyProvider.properties.value
MouseArea MouseArea

View file

@ -33,6 +33,7 @@ Item {
property var stackLevel: stackLevels[0] property var stackLevel: stackLevels[0]
signal focusReceived() signal focusReceived()
signal setActiveFocusToNextSetting(bool forward)
signal contextMenuRequested() signal contextMenuRequested()
signal showTooltip(string text) signal showTooltip(string text)
signal hideTooltip() signal hideTooltip()

View file

@ -11,6 +11,7 @@ import Cura 1.0 as Cura
SettingItem SettingItem
{ {
id: base id: base
property var focusItem: control
contents: ComboBox contents: ComboBox
{ {
@ -39,6 +40,15 @@ SettingItem
} }
} }
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
Binding Binding
{ {
target: control target: control

View file

@ -9,6 +9,7 @@ import UM 1.1 as UM
SettingItem SettingItem
{ {
id: base id: base
property var focusItem: input
contents: Rectangle contents: Rectangle
{ {
@ -93,7 +94,15 @@ SettingItem
right: parent.right right: parent.right
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
activeFocusOnTab: true
Keys.onTabPressed:
{
base.setActiveFocusToNextSetting(true)
}
Keys.onBacktabPressed:
{
base.setActiveFocusToNextSetting(false)
}
Keys.onReleased: Keys.onReleased:
{ {

View file

@ -168,6 +168,8 @@ Item
onVisibilityChanged: Cura.SettingInheritanceManager.forceUpdate() onVisibilityChanged: Cura.SettingInheritanceManager.forceUpdate()
} }
property var indexWithFocus: -1
delegate: Loader delegate: Loader
{ {
id: delegate id: delegate
@ -300,11 +302,39 @@ Item
} }
onFocusReceived: onFocusReceived:
{ {
contents.indexWithFocus = index;
animateContentY.from = contents.contentY; animateContentY.from = contents.contentY;
contents.positionViewAtIndex(index, ListView.Contain); contents.positionViewAtIndex(index, ListView.Contain);
animateContentY.to = contents.contentY; animateContentY.to = contents.contentY;
animateContentY.running = true; animateContentY.running = true;
} }
onSetActiveFocusToNextSetting:
{
if(forward == undefined || forward)
{
contents.currentIndex = contents.indexWithFocus + 1;
while(contents.currentItem && contents.currentItem.height <= 0)
{
contents.currentIndex++;
}
if(contents.currentItem)
{
contents.currentItem.item.focusItem.forceActiveFocus();
}
}
else
{
contents.currentIndex = contents.indexWithFocus - 1;
while(contents.currentItem && contents.currentItem.height <= 0)
{
contents.currentIndex--;
}
if(contents.currentItem)
{
contents.currentItem.item.focusItem.forceActiveFocus();
}
}
}
} }
} }