1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
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
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
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."
39 ****************************************************************************/
43 import "AppManager.js" as Utils
50 property bool checked: internal.tabGroup != null && internal.tabGroup.currentTab == tab
51 property bool pressed: stateGroup.state == "Pressed" && mouseArea.containsMouse
52 property alias text: label.text
53 property alias iconSource: imageLoader.source
57 // Symbian specific API
58 property bool platformInverted: false
60 implicitWidth: Math.max(2 * imageLoader.width, 2 * platformStyle.paddingMedium + privateStyle.textWidth(label.text, label.font))
61 implicitHeight: internal.portrait ? privateStyle.tabBarHeightPortrait : privateStyle.tabBarHeightLandscape
66 property Item tabGroup: Utils.findParent(tab, "currentTab")
67 property bool portrait: screen.currentOrientation == Screen.Portrait || screen.currentOrientation == Screen.PortraitInverted
70 privateStyle.play(Android.BasicButton)
74 privateStyle.play(Android.BasicButton)
75 if (internal.tabGroup)
76 internal.tabGroup.currentTab = tab
79 function isButtonRow(item) {
81 item.hasOwnProperty("checkedButton") &&
82 item.hasOwnProperty("privateDirection") &&
83 item.privateDirection == Qt.Horizontal)
86 function imageName() {
87 // If the parent of a TabButton is ButtonRow, segmented-style graphics
88 // are used to create a seamless row of buttons. Otherwise normal
89 // TabButton graphics are utilized.
90 var mirror = root.LayoutMirroring.enabled // To create binding
91 if (isButtonRow(parent))
92 return parent.privateGraphicsName(root, 1)
98 if (isButtonRow(parent)) {
99 return parent.privateModeName(root, 1)
101 return root.checked ? "active" : "passive_normal"
105 function modeNamePressed() {
106 if (isButtonRow(parent)) {
109 return "passive_pressed"
120 PropertyChanges { target: pressedGraphics; opacity: 1 }
122 State { name: "Canceled" }
127 ScriptAction { script: internal.press() }
133 target: pressedGraphics
137 easing.type: Easing.Linear
139 ScriptAction { script: internal.click() }
147 source: privateStyle.imagePath(internal.imageName() + internal.modeName(), root.platformInverted)
150 left: platformStyle.borderSizeMedium
151 top: platformStyle.borderSizeMedium
152 right: platformStyle.borderSizeMedium
153 bottom: platformStyle.borderSizeMedium
160 source: privateStyle.imagePath(internal.imageName() + internal.modeNamePressed(), root.platformInverted)
165 left: platformStyle.borderSizeMedium
166 top: platformStyle.borderSizeMedium
167 right: platformStyle.borderSizeMedium
168 bottom: platformStyle.borderSizeMedium
176 // hide in landscape if icon is present
177 visible: !(iconSource.toString() && !internal.portrait)
181 bottom: parent.bottom
182 leftMargin: platformStyle.paddingMedium
183 rightMargin: platformStyle.paddingMedium
184 bottomMargin: iconSource.toString()
185 ? platformStyle.paddingSmall
186 : Math.ceil((parent.height - label.height) / 2.0)
188 elide: Text.ElideRight
189 horizontalAlignment: Text.AlignHCenter
191 family: platformStyle.fontFamilyRegular;
192 pixelSize: platformStyle.fontSizeSmall
197 root.platformInverted ? platformStyle.colorPressedInverted
198 : platformStyle.colorPressed
199 else if (root.checked)
200 root.platformInverted ? platformStyle.colorNormalLightInverted
201 : platformStyle.colorNormalLight
203 root.platformInverted ? platformStyle.colorNormalMidInverted
204 : platformStyle.colorNormalMid
209 // imageLoader acts as wrapper for Image and Icon items. The Image item is
210 // shown when the source points to a image (jpg, png). Icon item is used for
211 // locigal theme icons which are colorised.
215 property string iconId: privateStyle.isTabBarIcon(source) ? source.toString() : ""
217 width : platformStyle.graphicSizeSmall
218 height : platformStyle.graphicSizeSmall
222 if (source.toString())
223 return imageComponent
228 topMargin : !parent.text || !internal.portrait
229 ? Math.floor((parent.height - imageLoader.height) / 2.0)
230 : platformStyle.paddingSmall
231 horizontalCenter: parent.horizontalCenter
241 source: imageLoader.iconId ? "" : imageLoader.source
242 sourceSize.width: width
243 sourceSize.height: height
244 fillMode: Image.PreserveAspectFit
258 iconColor: label.color
259 iconName: imageLoader.iconId
267 onPressed: stateGroup.state = "Pressed"
268 onReleased: stateGroup.state = ""
271 stateGroup.state = "Canceled"
273 stateGroup.state = ""
277 stateGroup.state = "Canceled"