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 ****************************************************************************/
46 objectName: "baseDialog"
49 property alias title: titleBar.children
50 property alias content: contentField.children
51 property alias buttons: buttonRow.children
56 property Style platformStyle: DialogStyle {}
58 //Deprecated, TODO Remove this on w13
59 property alias style: root.platformStyle
62 property string __animationChief: "baseDialog"
63 __dim: platformStyle.dim
64 __fadeInDuration: platformStyle.fadeInDuration
65 __fadeOutDuration: platformStyle.fadeOutDuration
66 __fadeInDelay: platformStyle.fadeInDelay
67 __fadeOutDelay: platformStyle.fadeOutDelay
69 // true: center of the content field is center of the background rect
70 // false: the whole dialog is centered
71 property bool __centerContentField: false
73 width: parent.width - platformStyle.leftMargin - platformStyle.rightMargin // ToDo: better width heuristic
74 height: titleBar.height + contentField.height + buttonRow.height
76 anchors.centerIn: parent
88 // this item contains the whole dialog (title bar + content rectangle, button row)
95 anchors.centerIn: root
97 // center the whole dialog, not just the content field
98 transform: Translate {
99 id: contentTranslation
100 y: root.__centerContentField ? 0 : (titleBar.height - buttonRow.height) / 2
109 height: childrenRect.height
111 anchors.left: parent.left
112 anchors.right: parent.right
113 anchors.bottom: contentField.top
115 // animate over bottomMargin (i.e. the distance between the content field)
116 anchors.bottomMargin: 0
124 anchors.left: parent.left
125 //anchors.right: parent.right
127 anchors.horizontalCenter: backgroundRect.horizontalCenter
128 anchors.verticalCenter: backgroundRect.verticalCenter
130 height: childrenRect.height
134 xScale: 1.0; yScale: 1.0
135 origin.x: mapFromItem(root, root.width / 2, root.height / 2).x
136 origin.y: mapFromItem(root, root.width / 2, root.height / 2).y
146 anchors.left: parent.left
147 anchors.right: parent.right
149 anchors.top: contentField.bottom
151 // animate over topMargin (i.e. the distance between the content field)
154 height: childrenRect.height
159 onPrivateClicked: reject()
166 // needed for button and title bar animation
167 // without resetting the button row's/title bar's coordinate system would be translated
168 property int __buttonSaver: buttonRow.y
169 property int __titleSaver: titleBar.y
175 when: root.__animationChief == "baseDialog" && (status == DialogStatus.Opening || status == DialogStatus.Open)
177 target: backgroundRect
183 when: root.__animationChief == "baseDialog" && (status == DialogStatus.Closing || status == DialogStatus.Closed)
185 target: backgroundRect
193 from: "visible"; to: "hidden"
194 SequentialAnimation {
195 ScriptAction {script: {
196 __fader().state = "hidden";
198 backgroundRect.opacity = 1.0;
201 statesWrapper.__buttonSaver = buttonRow.y
202 statesWrapper.__titleSaver = titleBar.y
203 root.status = DialogStatus.Closing;
207 // With a 100ms delay the background fades to alpha 0% (500ms, quint ease out).
208 // --> done in the fader
210 PropertyAnimation { target: root; properties: "opacity"; from: 0.0; to: 1.0; duration: 0 }
211 PropertyAnimation { target: backgroundRect; properties: "opacity"; from: 0.0; to: 1.0; duration: 0 }
213 // The closing transition starts with the title and both lines dimming to
214 // alpha 0% and moving 100 pixels in Y axis towards the center (125ms,
215 // quint ease in). With no delay the list fades to alpha 0% and scales to
216 // 80% (anchorpoint in the middle of the list, 100ms, quint ease in).
218 PropertyAnimation {target: contentField; properties: "opacity"; from: 1.0; to: 0.0; duration: 100}
219 PropertyAnimation {target: titleBar; properties: "opacity"; from: 1.0; to: 0.0; duration: 125}
220 PropertyAnimation {target: contentScale; properties: "xScale,yScale"; from: 1.0 ; to: 0.8; duration: 100; easing.type: Easing.InQuint }
221 PropertyAnimation {target: buttonRow; properties: "opacity"; from: 1.0; to: 0.0; duration: 125}
222 PropertyAnimation {target: buttonRow
223 properties: "anchors.topMargin"
227 easing.type: Easing.InQuint
229 PropertyAnimation {target: titleBar
230 properties: "anchors.topMargin"
234 easing.type: Easing.InQuint
238 ScriptAction {script: {
239 // reset button and title bar
240 buttonRow.y = statesWrapper.__buttonSaver
241 titleBar.y = statesWrapper.__titleSaver
242 // make sure, root isn't visible:
243 backgroundRect = 0.0;
245 status = DialogStatus.Closed;
252 from: "hidden"; to: "visible"
253 SequentialAnimation {
254 ScriptAction {script: {
255 __fader().state = "visible";
257 statesWrapper.__buttonSaver = buttonRow.y
258 statesWrapper.__titleSaver = titleBar.y
260 root.status = DialogStatus.Opening;
261 // UPPERCASE-UGLY, but necessary to avoid flicker
263 titleBar.opacity = 0.0;
264 contentField.opacity = 0.0;
265 buttonRow.opacity = 0.0;
269 // The opening transition starts by dimming the background to 90% (250ms,
270 // quint ease in). --> Done inside the fader
273 SequentialAnimation {
274 // a 250ms delay from the beginning
275 PauseAnimation { duration: 250 }
276 // the list scales from 80% to 100% and alpha 0%
277 // to 100% (anchorpoint in the middle of the list, 250ms, expo ease out)
279 PropertyAnimation {target: contentField; properties: "opacity"; from: 0.0; to: 1.0; duration: 250}
280 PropertyAnimation {target: contentScale; properties: "xScale,yScale"; from: 0.8 ; to: 1.0; duration: 250; easing.type: Easing.OutExpo}
283 SequentialAnimation {
284 // a 200ms delay from the beginning
285 PauseAnimation { duration: 200 }
287 //the title and both lines come from alpha 0%
288 PropertyAnimation {target: buttonRow; properties: "opacity"; from: 0.0; to: 1.0; duration: 450; }
289 PropertyAnimation {target: titleBar; properties: "opacity"; from: 0.0; to: 1.0; duration: 450; }
290 // and move towards the edges (40 pixels in Y axis
291 // away from their final destination, 450ms, custom ease).
292 PropertyAnimation {target: buttonRow; properties: "anchors.topMargin"
296 easing.type: Easing.OutBack
298 PropertyAnimation {target: titleBar; properties: "anchors.bottomMargin"
302 easing.type: Easing.OutBack
309 ScriptAction {script: {
311 // reset button and title bar
312 buttonRow.y = statesWrapper.__buttonSaver
313 titleBar.y = statesWrapper.__titleSaver
315 root.status = DialogStatus.Open;