Fix keyboard navigation in TabBar

This commit is contained in:
Aurélien Gâteau 2012-05-15 17:24:30 +02:00
parent ea9cf23038
commit cdba0a2222
3 changed files with 13 additions and 9 deletions

View File

@ -68,7 +68,7 @@ import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.core 0.1 as PlasmaCore
import "private" as Private import "private" as Private
Item { FocusScope {
id: root id: root
default property alias content: tabBarLayout.data default property alias content: tabBarLayout.data
property alias layout: tabBarLayout property alias layout: tabBarLayout

View File

@ -99,6 +99,7 @@ Item {
onPressedChanged: { onPressedChanged: {
//TabBar is the granparent //TabBar is the granparent
root.parent.parent.currentTab = root root.parent.parent.currentTab = root
root.parent.parent.forceActiveFocus()
} }
onVisibleChanged: root.parent.childrenChanged() onVisibleChanged: root.parent.childrenChanged()
} }

View File

@ -66,19 +66,15 @@ Item {
Keys.onPressed: { Keys.onPressed: {
if (event.key == Qt.Key_Right || event.key == Qt.Key_Left) { if (event.key == Qt.Key_Right || event.key == Qt.Key_Left) {
var oldIndex = priv.currentButtonIndex();
if (event.key == Qt.Key_Right || priv.mirrored) { if (event.key == Qt.Key_Right || priv.mirrored) {
var oldIndex = priv.currentButtonIndex();
if (oldIndex != root.children.length - 1) { if (oldIndex != root.children.length - 1) {
priv.tabGroup.currentTab = root.children[oldIndex + 1].tab priv.setCurrentButtonIndex(oldIndex + 1)
root.parent.currentTab = root.children[oldIndex + 1]
event.accepted = true event.accepted = true
} }
} else if (event.key == Qt.Key_Left || priv.mirrored) { } else if (event.key == Qt.Key_Left || priv.mirrored) {
var oldIndex = priv.currentButtonIndex()
if (oldIndex != 0) { if (oldIndex != 0) {
priv.tabGroup.currentTab = root.children[oldIndex - 1].tab priv.setCurrentButtonIndex(oldIndex -1)
root.parent.currentTab = root.children[oldIndex - 1]
event.accepted = true event.accepted = true
} }
} }
@ -98,12 +94,19 @@ Item {
function currentButtonIndex() { function currentButtonIndex() {
for (var i = 0; i < root.children.length; ++i) { for (var i = 0; i < root.children.length; ++i) {
if (root.children[i].tab == tabGroup.currentTab) if (root.children[i] == root.parent.currentTab)
return i return i
} }
return -1 return -1
} }
function setCurrentButtonIndex(index) {
if (tabGroup) {
tabGroup.currentTab = root.children[index].tab
}
root.parent.currentTab = root.children[index]
}
function layoutChildren() { function layoutChildren() {
var childCount = root.children.length var childCount = root.children.length
var visibleChildCount = childCount var visibleChildCount = childCount