Fix keyboard navigation in TabBar
This commit is contained in:
parent
ea9cf23038
commit
cdba0a2222
@ -68,7 +68,7 @@ import QtQuick 1.1
|
||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||
import "private" as Private
|
||||
|
||||
Item {
|
||||
FocusScope {
|
||||
id: root
|
||||
default property alias content: tabBarLayout.data
|
||||
property alias layout: tabBarLayout
|
||||
|
@ -99,6 +99,7 @@ Item {
|
||||
onPressedChanged: {
|
||||
//TabBar is the granparent
|
||||
root.parent.parent.currentTab = root
|
||||
root.parent.parent.forceActiveFocus()
|
||||
}
|
||||
onVisibleChanged: root.parent.childrenChanged()
|
||||
}
|
||||
|
@ -66,19 +66,15 @@ Item {
|
||||
|
||||
Keys.onPressed: {
|
||||
if (event.key == Qt.Key_Right || event.key == Qt.Key_Left) {
|
||||
if (event.key == Qt.Key_Right || priv.mirrored) {
|
||||
var oldIndex = priv.currentButtonIndex();
|
||||
|
||||
if (event.key == Qt.Key_Right || priv.mirrored) {
|
||||
if (oldIndex != root.children.length - 1) {
|
||||
priv.tabGroup.currentTab = root.children[oldIndex + 1].tab
|
||||
root.parent.currentTab = root.children[oldIndex + 1]
|
||||
priv.setCurrentButtonIndex(oldIndex + 1)
|
||||
event.accepted = true
|
||||
}
|
||||
} else if (event.key == Qt.Key_Left || priv.mirrored) {
|
||||
var oldIndex = priv.currentButtonIndex()
|
||||
if (oldIndex != 0) {
|
||||
priv.tabGroup.currentTab = root.children[oldIndex - 1].tab
|
||||
root.parent.currentTab = root.children[oldIndex - 1]
|
||||
priv.setCurrentButtonIndex(oldIndex -1)
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
@ -98,12 +94,19 @@ Item {
|
||||
|
||||
function currentButtonIndex() {
|
||||
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 -1
|
||||
}
|
||||
|
||||
function setCurrentButtonIndex(index) {
|
||||
if (tabGroup) {
|
||||
tabGroup.currentTab = root.children[index].tab
|
||||
}
|
||||
root.parent.currentTab = root.children[index]
|
||||
}
|
||||
|
||||
function layoutChildren() {
|
||||
var childCount = root.children.length
|
||||
var visibleChildCount = childCount
|
||||
|
Loading…
Reference in New Issue
Block a user