added android components
[mardrone] / mardrone / imports / com / nokia / android.1.1 / PageStackWindow.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the Qt Components project.
8 **
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
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
20 **     distribution.
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
24 **     permission.
25 **
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."
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 import QtQuick 1.1
42 import "." 1.1
43
44 Window {
45     id: root
46
47     property bool showStatusBar: true
48     property bool showToolBar: true
49     property variant initialPage
50     property alias pageStack: stack
51
52     property bool platformSoftwareInputPanelEnabled: false
53
54     Component.onCompleted: {
55         contentArea.initialized = true
56         if (initialPage && stack.depth == 0)
57             stack.push(initialPage, null, true)
58     }
59
60     onInitialPageChanged: {
61         if (initialPage && contentArea.initialized) {
62             if (stack.depth == 0)
63                 stack.push(initialPage, null, true)
64             else if (stack.depth == 1)
65                 stack.replace(initialPage, null, true)
66         }
67     }
68
69     onOrientationChangeStarted: {
70         statusBar.orientation = screen.currentOrientation
71     }
72
73     Item {
74         id: contentArea
75
76         property bool initialized: false
77
78         anchors {
79             top: sbar.bottom; bottom: sip.top;
80             left: parent.left; right: parent.right;
81         }
82
83         PageStack {
84             id: stack
85             anchors.fill: parent
86             toolBar: tbar
87         }
88     }
89
90     StatusBar {
91         id: sbar
92
93         width: parent.width
94         state: root.showStatusBar ? "Visible" : "Hidden"
95         platformInverted: root.platformInverted
96
97         states: [
98             State {
99                 name: "Visible"
100                 PropertyChanges { target: sbar; y: 0; opacity: 1 }
101             },
102             State {
103                 name: "Hidden"
104                 PropertyChanges { target: sbar; y: -height; opacity: 0 }
105             }
106         ]
107
108         transitions: [
109             Transition {
110                 from: "Hidden"; to: "Visible"
111                 ParallelAnimation {
112                     NumberAnimation { target: sbar; properties: "y"; duration: 200; easing.type: Easing.OutQuad }
113                     NumberAnimation { target: sbar; properties: "opacity"; duration: 200; easing.type: Easing.Linear }
114                 }
115             },
116             Transition {
117                 from: "Visible"; to: "Hidden"
118                 ParallelAnimation {
119                     NumberAnimation { target: sbar; properties: "y"; duration: 200; easing.type: Easing.Linear }
120                     NumberAnimation { target: sbar; properties: "opacity"; duration: 200; easing.type: Easing.Linear }
121                 }
122             }
123         ]
124     }
125
126     Item {
127         id: sip
128
129         anchors { bottom: parent.bottom; left: parent.left; right: parent.right }
130
131         Behavior on height { PropertyAnimation { duration: 200 } }
132
133         states: [
134             State {
135                 name: "Visible"; when: inputContext.visible && root.platformSoftwareInputPanelEnabled
136                 PropertyChanges { target: sip; height: inputContext.height }
137             },
138
139             State {
140                 name: "Hidden"; when: root.showToolBar
141                 PropertyChanges { target: sip; height: tbar.height }
142             },
143
144             State {
145                 name: "HiddenInFullScreen"; when: !root.showToolBar
146                 PropertyChanges { target: sip; height: 0 }
147             }
148         ]
149     }
150
151     ToolBar {
152         id: tbar
153
154         width: parent.width
155         state: root.showToolBar ? "Visible" : "Hidden"
156         platformInverted: root.platformInverted
157
158         states: [
159             State {
160                 name: "Visible"
161                 PropertyChanges { target: tbar; y: parent.height - height; opacity: 1 }
162             },
163             State {
164                 name: "Hidden"
165                 PropertyChanges { target: tbar; y: parent.height; opacity: 0 }
166             }
167         ]
168
169         transitions: [
170             Transition {
171                 from: "Hidden"; to: "Visible"
172                 ParallelAnimation {
173                     NumberAnimation { target: tbar; properties: "y"; duration: 200; easing.type: Easing.OutQuad }
174                     NumberAnimation { target: tbar; properties: "opacity"; duration: 200; easing.type: Easing.Linear }
175                 }
176             },
177             Transition {
178                 from: "Visible"; to: "Hidden"
179                 ParallelAnimation {
180                     NumberAnimation { target: tbar; properties: "y"; duration: 200; easing.type: Easing.Linear }
181                     NumberAnimation { target: tbar; properties: "opacity"; duration: 200; easing.type: Easing.Linear }
182                 }
183             }
184         ]
185     }
186
187     // event preventer when page transition is active
188     MouseArea {
189         anchors.fill: parent
190         enabled: pageStack.busy
191     }
192 }