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 "UIConstants.js" as UI
47 objectName: "queryDialog"
49 property string titleText
50 property string message
53 property alias acceptButtonText: acceptButton.text
54 property alias rejectButtonText: rejectButton.text
57 property alias icon: iconImage.source
59 property Style platformStyle: QueryDialogStyle {}
61 //__centerContentField: true
63 __dim: platformStyle.dim
64 __fadeInDuration: platformStyle.fadeInDuration
65 __fadeOutDuration: platformStyle.fadeOutDuration
66 __fadeInDelay: platformStyle.fadeInDelay
67 __fadeOutDelay: platformStyle.fadeOutDelay
69 __animationChief: "queryDialog"
71 //Deprecated, TODO Remove this on w13
72 property alias style: root.platformStyle
74 // the title field consists of the following parts: title string and
75 // a close button (which is in fact an image)
76 // it can additionally have an icon
80 height: titleText == "" ? titleBarIconField.height :
81 titleBarIconField.height + titleLabel.height + root.platformStyle.titleColumnSpacing
84 spacing: root.platformStyle.titleColumnSpacing
86 anchors.left: parent.left
87 anchors.right: parent.right
88 anchors.top: parent.top
94 height: iconImage.height
98 anchors.horizontalCenter: titleBarIconField.horizontalCenter
106 id: titleBarTextField
107 height: titleLabel.height
114 horizontalAlignment: Text.AlignHCenter
115 verticalAlignment: Text.AlignVCenter
117 font.family: root.platformStyle.titleFontFamily
118 font.pixelSize: root.platformStyle.titleFontPixelSize
119 font.bold: root.platformStyle.titleFontBold
120 font.capitalization: root.platformStyle.titleFontCapitalization
121 elide: root.platformStyle.titleElideMode
122 wrapMode: elide == Text.ElideNone ? Text.Wrap : Text.NoWrap
123 color: root.platformStyle.titleTextColor
129 // needed for animation
132 xScale: 1.0; yScale: 1.0
133 origin.x: mapFromItem(queryContent, queryContent.width / 2, queryContent.height / 2).x
134 origin.y: mapFromItem(queryContent, queryContent.width / 2, queryContent.height / 2).y
140 // the content field which contains the message text
142 id: queryContentWrapper
144 property int upperBound: visualParent ? visualParent.height - titleField.height - buttonColFiller.height - 64
145 : root.parent.height - titleField.height - buttonColFiller.height - 64
146 property int __sizeHint: Math.min(Math.max(root.platformStyle.contentFieldMinSize, queryText.height), upperBound)
148 height: __sizeHint + root.platformStyle.contentTopMargin
155 y: root.platformStyle.contentTopMargin
159 anchors.left: parent.left
160 anchors.right: parent.right
161 anchors.top: parent.top
162 //anchors.bottom: parent.bottom
163 height: queryContentWrapper.__sizeHint
165 contentHeight: queryText.height
166 flickableDirection: Flickable.VerticalFlick
169 interactive: queryText.height > queryContentWrapper.__sizeHint
173 width: queryFlickable.width
174 horizontalAlignment: Text.AlignHCenter
175 font.family: root.platformStyle.messageFontFamily
176 font.pixelSize: root.platformStyle.messageFontPixelSize
177 color: root.platformStyle.messageTextColor
178 wrapMode: Text.WordWrap
187 flickableItem: queryFlickable
188 anchors.rightMargin: - UI.SCROLLDECORATOR_LONG_MARGIN - 10 //ToDo: Don't use a hard-coded gap
198 height: childrenRect.height
200 anchors.top: parent.top
202 //ugly hack to assure, that we're always evaluating the correct height
203 //otherwise the topMargin wouldn't be considered
204 Item {id: dummy; anchors.fill: parent}
208 anchors.top: parent.top
209 anchors.topMargin: root.platformStyle.buttonTopMargin
210 spacing: root.platformStyle.buttonsColumnSpacing
212 height: (acceptButton.text == "" ? 0 : acceptButton.height)
213 + (rejectButton.text == "" ? 0 : rejectButton.height)
214 + anchors.buttonTopMargin + spacing
216 anchors.horizontalCenter: parent.horizontalCenter
224 platformStyle: ButtonStyle {inverted: true}
232 platformStyle: ButtonStyle {inverted: true}
240 state: "__query__hidden"
242 // needed for button animation
243 // without resetting the button row's coordinate system would be translated
244 property int __buttonSaver: buttonColFiller.y
248 name: "__query__visible"
249 when: root.__animationChief == "queryDialog" && (root.status == DialogStatus.Opening || root.status == DialogStatus.Open)
256 name: "__query__hidden"
257 when: root.__animationChief == "queryDialog" && (root.status == DialogStatus.Closing || root.status == DialogStatus.Closed)
267 from: "__query__visible"; to: "__query__hidden"
268 SequentialAnimation {
269 ScriptAction {script: {
270 __fader().state = "hidden";
272 statesWrapper.__buttonSaver = buttonColFiller.y
273 root.status = DialogStatus.Closing;
278 NumberAnimation { target: root; properties: "opacity"; from: 0.0; to: 1.0; duration: 0 }
280 // With a 100ms delay the background
281 // fades to alpha 0% (500ms, quint ease out).
282 // ---> done in the fader
285 // The closing transition starts with the message dimming to alpha 0% and
286 // scaling to 80% (anchorpoint in the middle of the message, 100ms, quint
289 // With no delay the buttons fade to alpha 0% and translate 30
290 // pixels upwards (100ms, quint ease in).
291 NumberAnimation {target: queryContent; properties: "opacity"; from: 1.0; to: 0.0; duration: 100}
292 NumberAnimation {target: titleField; properties: "opacity"; from: 1.0; to: 0.0; duration: 100}
293 NumberAnimation {target: titleScale; properties: "xScale,yScale"; from: 1.0 ; to: 0.8; duration: 100; easing.type: Easing.InQuint}
294 NumberAnimation {target: queryContent; property: "scale"; from: 1.0 ; to: 0.8; duration: 100; easing.type: Easing.InQuint}
295 NumberAnimation {target: buttonColFiller; properties: "opacity"; from: 1.0; to: 0.0; duration: 100}
296 NumberAnimation {target: buttonColFiller
298 from: buttonColFiller.y
299 to: buttonColFiller.y-30
301 easing.type: Easing.InQuint
305 ScriptAction {script: {
308 buttonColFiller.y = statesWrapper.__buttonSaver
310 // make sure, root isn't visible:
312 status = DialogStatus.Closed;
320 from: "__query__hidden"; to: "__query__visible"
321 SequentialAnimation {
322 ScriptAction {script: {
323 __fader().state = "visible";
325 statesWrapper.__buttonSaver = buttonColFiller.y
327 root.status = DialogStatus.Opening;
328 // UPPERCASE-UGLY, but necessary to avoid flicker
330 titleField.opacity = 0.0
331 queryContent.opacity = 0.0
332 buttonColFiller.opacity = 0.0
336 // The opening transition starts by dimming the background to 90% (250ms,
338 // ---> done in the fader
340 SequentialAnimation {
342 // With a 200ms delay from the beginning the message fades
343 // from alpha 0% to 100% and scales from 80% to 100% (anchorpoint in the
344 // middle of the message, 550ms, custom ease).
345 PauseAnimation { duration: 200 }
347 NumberAnimation {target: queryContent; properties: "opacity"; from: 0.0; to: 1.0; duration: 550}
348 NumberAnimation {target: titleField; properties: "opacity"; from: 0.0; to: 1.0; duration: 550}
349 NumberAnimation {target: titleScale; properties: "xScale,yScale"; from: 0.8 ; to: 1.0; duration: 550; easing.type: Easing.OutBack}
350 NumberAnimation {target: queryContent; property: "scale"; from: 0.8 ; to: 1.0; duration: 550; easing.type: Easing.OutBack}
353 SequentialAnimation {
354 // With a 250ms delay from the
355 // beginning the buttons fade from alpha 0% to 100% and translate 25 pixels
356 // in Y axis away from their final destination (400ms, custom ease).
357 PauseAnimation { duration: 250 }
359 NumberAnimation {target: buttonColFiller; properties: "opacity"; from: 0.0; to: 1.0; duration: 400; }
360 NumberAnimation {target: buttonColFiller
362 from: buttonColFiller.y-25
363 to: buttonColFiller.y
365 easing.type: Easing.OutBack
371 ScriptAction {script: {
374 buttonColFiller.y = statesWrapper.__buttonSaver
376 root.status = DialogStatus.Open;