58 import org.kde.qtextracomponents 0.1
59 import
"AppManager.js" as Utils
64 Component.onCompleted: priv.layoutChildren()
65 onChildrenChanged: priv.layoutChildren()
66 onWidthChanged: priv.layoutChildren()
67 onHeightChanged: priv.layoutChildren()
71 if (event.key == Qt.Key_Right || event.key == Qt.Key_Left) {
73 if (event.key == Qt.Key_Right || priv.mirrored) {
76 }
else if (event.key == Qt.Key_Left || priv.mirrored) {
88 if (wheel.delta < 0) {
96 property Item firstButton: root.children.length > 1 ? root.children[1] : null
97 property Item firstTab: firstButton ? (firstButton.tab != null ? firstButton.tab : null) : null
98 property
Item tabGroup: firstTab ? Utils.findParent(firstTab,
"currentTab") : null
99 property bool mirrored: root.LayoutMirroring.enabled
100 property Item tabBar: Utils.findParent(root,
"currentTab")
102 onMirroredChanged: layoutChildren()
104 function goNextTab() {
105 var oldIndex = priv.currentButtonIndex();
106 while (oldIndex < root.children.length) {
109 if (oldIndex > root.children.length - 1) {
114 if (root.children[oldIndex].checked === undefined) {
119 if (root.children[oldIndex].visible) {
120 priv.setCurrentButtonIndex(oldIndex)
126 function goPreviousTab() {
127 var oldIndex = priv.currentButtonIndex();
128 while (oldIndex > 0) {
132 oldIndex = root.children.length - 1
136 if (root.children[oldIndex].checked === undefined) {
140 if (root.children[oldIndex].visible) {
141 priv.setCurrentButtonIndex(oldIndex)
147 function currentButtonIndex() {
148 for (var i = 0; i < root.children.length; ++i) {
149 if (root.children[i] == priv.tabBar.currentTab)
155 function setCurrentButtonIndex(index) {
157 tabGroup.currentTab = root.children[index].tab
160 priv.tabBar.currentTab = root.children[index]
163 function layoutChildren() {
164 priv.tabBar = Utils.findParent(root,
"currentTab")
165 var childCount = root.children.length
166 var visibleChildCount = childCount
168 var contentHeight = 0
169 var maxChildWidth = 0
170 if (childCount != 0) {
172 for (var i = 0; i < childCount; ++i) {
173 if (!root.children[i].visible || root.children[i].text === undefined) {
178 var maxAllowedWidth = theme.defaultFont.mSize.width * 14
179 var itemWidth = (root.width - (visibleChildCount-1)*10) / visibleChildCount
181 var itemIndex = mirrored ? childCount - 1 : 0
182 var increment = mirrored ? - 1 : 1
185 for (var i = 0; i < childCount; ++i, itemIndex += increment) {
186 var child = root.children[itemIndex]
187 if (!child.visible || root.children[i].text === undefined) {
191 child.x = visibleIndex * itemWidth + visibleIndex*10
194 child.width = itemWidth
195 child.height = root.height
197 if (child.implicitWidth != undefined) {
198 maxChildWidth = Math.max(maxChildWidth, Math.min(maxAllowedWidth, child.implicitWidth))
199 contentWidth = Math.max(contentWidth, (maxChildWidth + buttonFrame.margins.left + buttonFrame.margins.right) * childCount)
200 contentHeight = Math.max(contentHeight, (child.implicitHeight + buttonFrame.margins.top + buttonFrame.margins.bottom))
204 root.implicitWidth = contentWidth
205 root.implicitHeight = contentHeight
206 if ( priv.tabBar.currentTab === null) {
208 for (var i = 0; i < tabBarLayout.children.length; ++i) {
210 if (tabBarLayout.children[i].checked !== undefined) {
211 priv.tabBar.currentTab = tabBarLayout.children[i]