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 ****************************************************************************/
47 property Item tools: null
49 // The transition type. One of the following:
50 // set an instantaneous change (default)
51 // push follows page stack push animation
52 // pop follows page stack pop animation
53 // replace follows page stack replace animation
54 property string transition: "set"
56 // Symbian specific API
57 property bool platformInverted: false
59 // Sets the tools with a transition.
60 function setTools(tools, transition) {
61 stateGroup.state = tools ? "" : "Hidden"
63 tools.height = root.height
64 priv.transition = transition
68 LayoutMirroring.enabled: false
69 LayoutMirroring.childrenInherit: true
71 implicitWidth: Math.max(50, screen.width)
72 implicitHeight: (screen.width < screen.height)
73 ? privateStyle.toolBarHeightPortrait
74 : privateStyle.toolBarHeightLandscape
79 source: privateStyle.imagePath("qtg_fr_toolbar", root.platformInverted)
80 border { left: 20; top: 20; right: 20; bottom: 20 }
83 //Prevents mouse events from propagating to elements below the ToolBar
94 priv.performTransition(priv.transition || transition)
95 priv.transition = undefined
99 id: containerComponent
106 // The states correspond to the different possible positions of the item.
109 // The tools held by this item.
110 property Item tools: null
111 // The owner of the tools.
112 property Item owner: null
119 PropertyChanges { target: item; visible: true; opacity: 1 }
122 // Start state for pop entry, end state for push exit.
125 PropertyChanges { target: item; opacity: 0.0 }
127 // Start state for push entry, end state for pop exit.
130 PropertyChanges { target: item; opacity: 0.0 }
132 // Start state for replace entry.
135 PropertyChanges { target: item; opacity: 0.0 }
137 // End state for replace exit.
140 PropertyChanges { target: item; opacity: 0.0 }
145 PropertyChanges { target: item; visible: false }
149 // re-parent back to original owner
150 tools.visible = false
154 item.tools = item.owner = null
162 // Pop entry and push exit transition.
164 from: ""; to: "Prev"; reversible: true
165 SequentialAnimation {
166 PropertyAnimation { properties: "opacity"; easing.type: Easing.InCubic; duration: priv.transitionDuration / 2 }
167 PauseAnimation { duration: priv.transitionDuration / 2 }
168 ScriptAction { script: if (state == "Prev") state = "Hidden" }
171 // Push entry and pop exit transition.
173 from: ""; to: "Next"; reversible: true
174 SequentialAnimation {
175 PropertyAnimation { properties: "opacity"; easing.type: Easing.InCubic; duration: priv.transitionDuration / 2 }
176 PauseAnimation { duration: priv.transitionDuration / 2 }
177 ScriptAction { script: if (state == "Next") state = "Hidden" }
181 // Replace entry transition.
182 from: "Front"; to: ""
183 SequentialAnimation {
184 PropertyAnimation { properties: "opacity"; easing.type: Easing.InOutExpo; duration: priv.transitionDuration }
188 // Replace exit transition.
190 SequentialAnimation {
191 PropertyAnimation { properties: "opacity"; easing.type: Easing.InOutExpo; duration: priv.transitionDuration }
192 ScriptAction { script: if (state == "Back") state = "Hidden" }
202 property Item currentComponent: null
204 // Alternating components used for transitions.
205 property Item compA: null
206 property Item compB: null
208 // The transition to perform next.
209 property variant transition
211 // Duration of transition animation (in ms)
212 property int transitionDuration: 500
214 // Performs a transition between tools in the toolbar.
215 function performTransition(transition) {
216 // lazily create components if they have not been created
217 if (!priv.currentComponent) {
218 priv.compA = containerComponent.createObject(container)
219 priv.compB = containerComponent.createObject(container)
220 priv.currentComponent = priv.compB
223 // no transition if the tools are unchanged
224 if (priv.currentComponent.tools == tools)
227 // select component states based on the transition animation
229 "set": { "new": "", "old": "Hidden" },
230 "push": { "new": "Next", "old": "Prev" },
231 "pop": { "new": "Prev", "old": "Next" },
232 "replace": { "new": "Front", "old": "Back" }
235 var animation = transitions[transition]
236 // initialize the free component
237 var component = priv.currentComponent == priv.compA ? priv.compB : priv.compA
238 component.state = "Hidden"
240 component.tools = tools
241 component.owner = tools.parent
242 tools.parent = component
244 if (tools.layoutChildren != undefined && typeof tools.layoutChildren == 'function' )
245 tools.layoutChildren()
248 // perform transition
249 priv.currentComponent.state = animation["old"]
251 component.state = animation["new"]
254 priv.currentComponent = component
264 PropertyChanges { target: root; height: 0; opacity: 0.0 }
269 // Transition between active and inactive states.
271 from: ""; to: "Hidden"; reversible: true
272 SequentialAnimation {
273 PropertyAnimation { properties: "opacity"; easing.type: Easing.InOutExpo; duration: priv.transitionDuration }
274 PropertyAnimation { properties: "height"; duration: 10 }