• 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
TabButton.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 
43 import QtQuick 1.1
44 import "private/AppManager.js" as Utils
45 import org.kde.plasma.core 0.1 as PlasmaCore
46 
50 Item {
51  id: root
52 
53  // Common Public API
58  property Item tab
59 
63  property bool checked: (internal.tabGroup == null) ? (internal.tabBar.currentTab == root) : (internal.tabGroup.currentTab == tab)
64 
68  property bool pressed: mouseArea.pressed == true && mouseArea.containsMouse
69 
74  property alias text: label.text
75 
82  property alias iconSource: imageLoader.source
83 
87  signal clicked
88 
89  implicitWidth: label.implicitWidth + (internal.portrait ? 0 : (iconSource != null ? 16 : 0))
90  implicitHeight: label.implicitHeight + (internal.portrait ? (iconSource != null ? 16 : 0) : 0)
91 
92  opacity: enabled ? 1 : 0.6
93  //long notation to not make it overwritten by implementations
94  Connections {
95  target: root
96  onPressedChanged: {
97  //TabBar is the granparent
98  internal.tabBar.currentTab = root
99  internal.tabBar.forceActiveFocus()
100  }
101  onClicked: {
102  if (internal.tabGroup) {
103  internal.tabGroup.currentTab = tab
104  }
105  //TabBar is the granparent, done here too in case of no tabgroup
106  internal.tabBar.currentTab = root
107  }
108  onVisibleChanged: root.parent.childrenChanged()
109  }
110 
111  QtObject {
112  id: internal
113 
114  property Item tabBar: Utils.findParent(root, "currentTab")
115  property Item tabGroup: Utils.findParent(tab, "currentTab")
116  property bool portrait: root.height >= label.paintedHeight + 16
117 
118  function click() {
119  root.clicked()
120  if (internal.tabGroup) {
121  internal.tabGroup.currentTab = tab
122  }
123  }
124 
125  Component.onCompleted: {
126  if (internal.tabGroup && internal.tabGroup.currentTab == tab) {
127  internal.tabGroup.currentTab = tab
128  }
129  }
130  }
131 
132  Label {
133  id: label
134 
135  objectName: "label"
136 
137  anchors {
138  top: internal.portrait && iconSource != null ? imageLoader.bottom : parent.top
139  left: internal.portrait || iconSource == null ? parent.left : imageLoader.right
140  leftMargin: iconSource == null ? 0 : theme.defaultFont.mSize.width
141  right: parent.right
142  bottom: parent.bottom
143  }
144 
145  elide: Text.ElideRight
146  horizontalAlignment: !internal.portrait && iconSource != null ? Text.AlignLeft : Text.AlignHCenter
147  verticalAlignment: Text.AlignVCenter
148 
149  color: root.checked ? theme.buttonTextColor : theme.textColor
150  }
151 
152  PlasmaCore.IconItem {
153  id: imageLoader
154 
155  implicitWidth: internal.portrait ? Math.max(theme.smallIconSize, root.height - (label.text ? label.height : 0)) : Math.max(theme.smallIconSize, root.height)
156  implicitHeight: implicitWidth
157 
158  anchors {
159  left: internal.portrait ? undefined : parent.left
160  horizontalCenter: internal.portrait ? parent.horizontalCenter : undefined
161  verticalCenter: internal.portrait ? undefined : parent.verticalCenter
162  }
163  }
164 
165  MouseArea {
166  id: mouseArea
167 
168  onClicked: root.clicked()
169 
170  anchors.fill: parent
171  }
172 }
Label
This is a label which uses the plasma theme.
Definition: Label.qml:32
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