• 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
TabGroup.qml
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Components project.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
24 ** permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 import QtQuick 1.1
42 import "private/TabGroup.js" as Engine
43 
44 import "." 0.1
45 
62 Item {
63  id: root
64 
72  property Item currentTab
73 
74  property list<Item> privateContents
75  // Qt defect: cannot have list as default property
76  default property alias privateContentsDefault: root.privateContents
77 
78  onChildrenChanged: {
79  // [0] is containerHost
80  if (children.length > 1)
81  Engine.addTab(children[1])
82  }
83 
84  onPrivateContentsChanged: {
85  Engine.ensureContainers()
86  }
87 
88  Component.onCompleted: {
89  // Set first tabs as current if currentTab is not set by application
90  if (currentTab == null && containerHost.children[0] && containerHost.children[0].children[0])
91  currentTab = containerHost.children[0].children[0]
92  priv.complete = true;
93  }
94 
95  Item {
96  id: containerHost
97  objectName: "containerHost"
98  anchors.fill: parent
99  }
100 
101  Component {
102  id: tabContainerComponent
103  Item {
104  id: tabContainerItem
105 
106  onChildrenChanged: {
107  if (children.length == 0)
108  Engine.removeContainer(tabContainerItem)
109 
110  else if (children.length == 1) {
111  children[0].width = width
112  children[0].height = height
113  // tab content created. set the first tab as current (if not set before, and if
114  // child is added after TabGroup has completed)
115  if (priv.complete && root.currentTab == null)
116  root.currentTab = children[0]
117  }
118  }
119 
120  onWidthChanged: {
121  if (children.length > 0)
122  children[0].width = width
123  }
124 
125  onHeightChanged: {
126  if (children.length > 0)
127  children[0].height = height
128  }
129 
130  Component.onDestruction: {
131  if (typeof(root) != "undefined" && !root.currentTab) {
132  // selected one deleted. try to activate the neighbour
133  var removedIndex = -1
134  for (var i = 0; i < containerHost.children.length; i++) {
135  if (containerHost.children[i] == tabContainerItem) {
136  removedIndex = i
137  break
138  }
139  }
140  var newIndex = -1
141  if (removedIndex != -1) {
142  if (removedIndex != containerHost.children.length - 1)
143  newIndex = removedIndex + 1
144  else if (removedIndex != 0)
145  newIndex = removedIndex - 1
146  }
147 
148  if (newIndex != -1)
149  root.currentTab = containerHost.children[newIndex].children[0]
150  else
151  root.currentTab = null
152  }
153  }
154 
155  function incomingDone() {
156  state = ""
157  if (priv.incomingPage) {
158  if (priv.incomingPage.status != undefined) {
159  priv.incomingPage.status = PageStatus.Active
160  }
161  priv.incomingPage = null
162  }
163  }
164 
165  function outgoingDone() {
166  if (priv.outgoingPage) {
167  if (priv.outgoingPage.status != undefined) {
168  priv.outgoingPage.status = PageStatus.Active
169  }
170  priv.outgoingPage.visible = false
171  priv.outgoingPage = null
172  }
173  state = "HiddenLeft"
174  }
175 
176  width: parent ? parent.width : 0
177  height: parent ? parent.height : 0
178  state: "HiddenLeft"
179 
180  states: [
181  State { name: ""; PropertyChanges { target: tabContainerItem; opacity: 1.0; x: 0 } },
182  State { name: "Incoming"; PropertyChanges { target: tabContainerItem; opacity: 1.0; x: 0 } },
183 
184  State {
185  name: "OutgoingLeft"
186  PropertyChanges {
187  target: tabContainerItem
188  opacity: 0.0
189  x: -root.width
190  }
191  },
192  State {
193  name: "OutgoingRight"
194  PropertyChanges {
195  target: tabContainerItem
196  opacity: 0.0
197  x: root.width
198  }
199  },
200 
201  State { name: "HiddenLeft"; PropertyChanges { target: tabContainerItem; opacity: 0.0; x: root.width } },
202  State { name: "HiddenRight"; PropertyChanges { target: tabContainerItem; opacity: 0.0; x: -root.width } }
203  ]
204 
205  transitions: [
206  Transition {
207  to: "Incoming"
208  SequentialAnimation {
209  ScriptAction { script: root.clip = true }
210  PropertyAnimation { properties: "opacity,x"; easing.type: Easing.InQuad; duration: 250 }
211  ScriptAction { script: {incomingDone(); root.clip = false} }
212  }
213  },
214  Transition {
215  to: "OutgoingLeft,OutgoingRight"
216  SequentialAnimation {
217  PropertyAnimation { properties: "opacity,x"; easing.type: Easing.InQuad; duration: 250 }
218  ScriptAction { script: outgoingDone() }
219  }
220  }
221  ]
222  }
223  }
224 
225  QtObject {
226  id: priv
227  property bool reparenting: false
228  property bool complete: false
229  property Item currentTabContainer: root.currentTab ? root.currentTab.parent : null
230  property int currentIndex: 0
231  property Item incomingPage
232  property Item outgoingPage
233  property bool animate: true
234 
235  onCurrentTabContainerChanged: {
236  var newCurrentIndex = 0
237  for (var i = 0; i < containerHost.children.length; i++) {
238  if (containerHost.children[i] == currentTabContainer) {
239  newCurrentIndex = i
240  break
241  }
242  }
243 
244  currentTabContainer.visible = true
245  incomingPage = currentTabContainer.children[0]
246  incomingPage.visible = true
247  if (incomingPage.status != undefined) {
248  incomingPage.status = PageStatus.Activating
249  }
250  if (currentIndex < newCurrentIndex) {
251  currentTabContainer.state = "HiddenLeft"
252  } else {
253  currentTabContainer.state = "HiddenRight"
254  }
255  if (animate) {
256  currentTabContainer.state = "Incoming"
257  } else {
258  currentTabContainer.incomingDone()
259  }
260 
261  if (newCurrentIndex == currentIndex) {
262  return
263  }
264 
265  var oldPage = containerHost.children[currentIndex]
266  outgoingPage = oldPage.children[0]
267  if (animate) {
268  if (currentIndex < newCurrentIndex) {
269  oldPage.state = "OutgoingLeft"
270  } else {
271  oldPage.state = "OutgoingRight"
272  }
273  } else {
274  oldPage.outgoingDone()
275  }
276  currentIndex = newCurrentIndex
277  }
278  }
279 }
PageStatus::Activating
Definition: enums.h:64
PageStatus::Active
Definition: enums.h:65
PageStatus
Definition: enums.h:56
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