• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
  • qml
  • private
TabBarLayout.qml
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright 2011 Marco Martin <mart@kde.org>
4 **
5 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 ** All rights reserved.
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** This file is part of the Qt Components project.
10 **
11 ** $QT_BEGIN_LICENSE:BSD$
12 ** You may use this file under the terms of the BSD license as follows:
13 **
14 ** "Redistribution and use in source and binary forms, with or without
15 ** modification, are permitted provided that the following conditions are
16 ** met:
17 ** * Redistributions of source code must retain the above copyright
18 ** notice, this list of conditions and the following disclaimer.
19 ** * Redistributions in binary form must reproduce the above copyright
20 ** notice, this list of conditions and the following disclaimer in
21 ** the documentation and/or other materials provided with the
22 ** distribution.
23 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
24 ** the names of its contributors may be used to endorse or promote
25 ** products derived from this software without specific prior written
26 ** permission.
27 **
28 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42 
57 import QtQuick 1.1
58 import org.kde.qtextracomponents 0.1
59 import "AppManager.js" as Utils
60 
61 Item {
62  id: root
63 
64  Component.onCompleted: priv.layoutChildren()
65  onChildrenChanged: priv.layoutChildren()
66  onWidthChanged: priv.layoutChildren()
67  onHeightChanged: priv.layoutChildren()
68 
69 
70  Keys.onPressed: {
71  if (event.key == Qt.Key_Right || event.key == Qt.Key_Left) {
72 
73  if (event.key == Qt.Key_Right || priv.mirrored) {
74  priv.goNextTab()
75  event.accepted = true
76  } else if (event.key == Qt.Key_Left || priv.mirrored) {
77  priv.goPreviousTab()
78  event.accepted = true
79  }
80  }
81  }
82 
83  focus: true
84 
85  MouseEventListener {
86  anchors.fill: parent
87  onWheelMoved: {
88  if (wheel.delta < 0) {
89  goNextTab()
90  } else {
91  goPreviousTab()
92  }
93  }
94 
95  id: priv
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")
101 
102  onMirroredChanged: layoutChildren()
103 
104  function goNextTab() {
105  var oldIndex = priv.currentButtonIndex();
106  while (oldIndex < root.children.length) {
107  ++oldIndex
108 
109  if (oldIndex > root.children.length - 1) {
110  oldIndex = 1
111  }
112 
113  //anything with a checked property may act as tabbutton
114  if (root.children[oldIndex].checked === undefined) {
115  continue
116  }
117 
118 
119  if (root.children[oldIndex].visible) {
120  priv.setCurrentButtonIndex(oldIndex)
121  break
122  }
123  }
124  }
125 
126  function goPreviousTab() {
127  var oldIndex = priv.currentButtonIndex();
128  while (oldIndex > 0) {
129  --oldIndex
130 
131  if (oldIndex <= 0) {
132  oldIndex = root.children.length - 1
133  }
134 
135  //anything with a checked property may act as tabbutton
136  if (root.children[oldIndex].checked === undefined) {
137  continue
138  }
139 
140  if (root.children[oldIndex].visible) {
141  priv.setCurrentButtonIndex(oldIndex)
142  break
143  }
144  }
145  }
146 
147  function currentButtonIndex() {
148  for (var i = 0; i < root.children.length; ++i) {
149  if (root.children[i] == priv.tabBar.currentTab)
150  return i
151  }
152  return -1
153  }
154 
155  function setCurrentButtonIndex(index) {
156  if (tabGroup) {
157  tabGroup.currentTab = root.children[index].tab
158  }
159 
160  priv.tabBar.currentTab = root.children[index]
161  }
162 
163  function layoutChildren() {
164  priv.tabBar = Utils.findParent(root, "currentTab")
165  var childCount = root.children.length
166  var visibleChildCount = childCount
167  var contentWidth = 0
168  var contentHeight = 0
169  var maxChildWidth = 0
170  if (childCount != 0) {
171  //not too much efficient but the loop over children needs to be done two times to get the proper child width
172  for (var i = 0; i < childCount; ++i) {
173  if (!root.children[i].visible || root.children[i].text === undefined) {
174  --visibleChildCount
175  }
176  }
177 
178  var maxAllowedWidth = theme.defaultFont.mSize.width * 14
179  var itemWidth = (root.width - (visibleChildCount-1)*10) / visibleChildCount
180 
181  var itemIndex = mirrored ? childCount - 1 : 0
182  var increment = mirrored ? - 1 : 1
183  var visibleIndex = 0
184 
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) {
188  continue
189  }
190 
191  child.x = visibleIndex * itemWidth + visibleIndex*10
192  ++visibleIndex
193  child.y = 0
194  child.width = itemWidth
195  child.height = root.height
196 
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))
201  }
202  }
203  }
204  root.implicitWidth = contentWidth
205  root.implicitHeight = contentHeight
206  if ( priv.tabBar.currentTab === null) {
207  //99% of the cases this loop will be length 1 but a tabbar can also have other children, such as Repeater
208  for (var i = 0; i < tabBarLayout.children.length; ++i) {
209  //anything with a checked property may act as tabbutton
210  if (tabBarLayout.children[i].checked !== undefined) {
211  priv.tabBar.currentTab = tabBarLayout.children[i]
212  break;
213  }
214  }
215  }
216  }
217  }
218 }
Item
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

Skip menu "PlasmaComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal