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 width: parent ? parent.width : 0
48 height: parent ? parent.height : 0
50 property alias title: titleBar.children
51 property alias content: contentField.children
52 property alias buttons: buttonRow.children
53 property Item visualParent
54 property int status: DialogStatus.Closed
56 property alias acceptButtonText: acceptButton.text
57 property alias rejectButtonText: rejectButton.text
59 property alias acceptButton: acceptButton
60 property alias rejectButton: rejectButton
65 property QtObject platformStyle: SheetStyle {}
67 //Deprecated, TODO Remove this on w13
68 property alias style: root.platformStyle
80 visible: status != DialogStatus.Closed;
83 parent = visualParent || __findParent();
88 sheet.state = "closed";
91 function __findParent() {
93 while (next && next.parent
94 && next.objectName != "appWindowContent"
95 && next.objectName != "windowContent") {
101 function getButton(name) {
102 for (var i=0; i<buttons.length; ++i) {
103 if (buttons[i].objectName == name)
117 //when the sheet is part of a page do nothing
118 //when the sheet is a direct child of a PageStackWindow, consider the status bar
119 property int statusBarOffset: (typeof __isPage != "undefined") ? 0
120 : (typeof __statusBarHeight == "undefined") ? 0
124 height: parent.height - statusBarOffset
130 property int transitionDurationIn: 300
131 property int transitionDurationOut: 450
135 function transitionStarted() {
136 status = (state == "closed") ? DialogStatus.Closing : DialogStatus.Opening;
139 function transitionEnded() {
140 status = (state == "closed") ? DialogStatus.Closed : DialogStatus.Open;
147 PropertyChanges { target: sheet; y: height; }
152 // Transition between open and closed states.
154 from: ""; to: "closed"; reversible: false
155 SequentialAnimation {
156 ScriptAction { script: if (sheet.state == "closed") { sheet.transitionStarted(); } else { sheet.transitionEnded(); } }
157 PropertyAnimation { properties: "y"; easing.type: Easing.InOutQuint; duration: sheet.transitionDurationOut }
158 ScriptAction { script: if (sheet.state == "closed") { sheet.transitionEnded(); } else { sheet.transitionStarted(); } }
162 from: "closed"; to: ""; reversible: false
163 SequentialAnimation {
164 ScriptAction { script: if (sheet.state == "") { sheet.transitionStarted(); } else { sheet.transitionEnded(); } }
165 PropertyAnimation { properties: "y"; easing.type: Easing.OutQuint; duration: sheet.transitionDurationIn }
166 ScriptAction { script: if (sheet.state == "") { sheet.transitionEnded(); } else { sheet.transitionStarted(); } }
172 source: platformStyle.background
174 anchors.top: header.bottom
175 anchors.bottom: parent.bottom
185 height: headerBackground.height
189 left: platformStyle.headerBackgroundMarginLeft
190 right: platformStyle.headerBackgroundMarginRight
191 top: platformStyle.headerBackgroundMarginTop
192 bottom: platformStyle.headerBackgroundMarginBottom
194 source: platformStyle.headerBackground
202 objectName: "rejectButton"
203 anchors.left: parent.left
204 anchors.leftMargin: root.platformStyle.rejectButtonLeftMargin
205 anchors.verticalCenter: parent.verticalCenter
211 objectName: "acceptButton"
212 anchors.right: parent.right
213 anchors.rightMargin: root.platformStyle.acceptButtonRightMargin
214 anchors.verticalCenter: parent.verticalCenter
215 platformStyle: SheetButtonAccentStyle { }
219 Component.onCompleted: {
220 acceptButton.clicked.connect(accepted)
221 rejectButton.clicked.connect(rejected)