|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 demonstration applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 import Qt 4.7 |
|
43 |
|
44 Item { |
|
45 id: main |
|
46 //height and width set by program to fill window |
|
47 //below properties are sometimes set from C++ |
|
48 property url qmlFile: '' |
|
49 property bool show: false |
|
50 |
|
51 Item{ id:embeddedViewer |
|
52 width: parent.width |
|
53 height: parent.height |
|
54 opacity: 0; |
|
55 z: 10 |
|
56 Loader{ |
|
57 id: loader |
|
58 z: 10 |
|
59 focus: true //Automatic FocusScope |
|
60 clip: true |
|
61 source: qmlFile |
|
62 anchors.centerIn: parent |
|
63 onStatusChanged:{ |
|
64 if(status == Loader.Null) { |
|
65 loader.focus = false;//fixes QTBUG11411, probably because the focusScope needs to gain focus to focus the right child |
|
66 }else if(status == Loader.Ready) { |
|
67 if(loader.item.width > 640) |
|
68 loader.item.width = 640; |
|
69 if(loader.item.height > 480) |
|
70 loader.item.height = 480; |
|
71 if(loader.item.inAnotherDemo != undefined) |
|
72 loader.item.inAnotherDemo = true; |
|
73 }} |
|
74 |
|
75 } |
|
76 Rectangle{ id: frame |
|
77 z: 9 |
|
78 anchors.fill: loader.status == Loader.Ready ? loader : errorTxt |
|
79 anchors.margins: -8 |
|
80 radius: 4 |
|
81 smooth: true |
|
82 border.color: "#88aaaaaa" |
|
83 gradient: Gradient{ |
|
84 GradientStop{ position: 0.0; color: "#14FFFFFF" } |
|
85 GradientStop{ position: 1.0; color: "#5AFFFFFF" } |
|
86 } |
|
87 MouseArea{ |
|
88 anchors.fill: parent |
|
89 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton |
|
90 onClicked: loader.focus=true;/* and don't propogate to the 'exit' area*/ |
|
91 } |
|
92 |
|
93 Rectangle{ id: innerFrame |
|
94 anchors.margins: 7 |
|
95 anchors.bottomMargin: 8 |
|
96 anchors.rightMargin: 8 |
|
97 color: "black" |
|
98 border.color: "#44000000" |
|
99 anchors.fill:parent |
|
100 } |
|
101 |
|
102 } |
|
103 |
|
104 Text{ |
|
105 id: errorTxt |
|
106 z: 10 |
|
107 anchors.centerIn: parent |
|
108 color: 'white' |
|
109 smooth: true |
|
110 visible: loader.status == Loader.Error |
|
111 textFormat: Text.RichText |
|
112 //Note that if loader is Error, it is because the file was found but there was an error creating the component |
|
113 //This means either we have a bug in our demos, or the required modules (which ship with Qt) did not deploy correctly |
|
114 text: "The example has failed to load.<br />If you installed all Qt's C++ and QML modules then this is a bug!<br />" |
|
115 + 'Report it at <a href="http://bugreports.qt.nokia.com">http://bugreports.qt.nokia.com</a>'; |
|
116 onLinkActivated: Qt.openUrlExternally(link); |
|
117 } |
|
118 } |
|
119 Rectangle{ |
|
120 id: helpLabel |
|
121 property bool timedOut: false |
|
122 z: 9 |
|
123 //Positioned in the top left corner |
|
124 x: 8 |
|
125 y: 8 |
|
126 color: "white" |
|
127 border.color: "black" |
|
128 border.width: 1 |
|
129 width: helpText.width + 16 |
|
130 height: helpText.height + 8 |
|
131 Text{ |
|
132 id: helpText |
|
133 color: "black" |
|
134 anchors.centerIn: parent |
|
135 text: "Click outside the example to exit it." |
|
136 } |
|
137 opacity: 0 |
|
138 Behavior on opacity{ NumberAnimation{duration:500} } |
|
139 Timer{ |
|
140 id: helpTimer |
|
141 interval: 5000 |
|
142 onTriggered: {helpLabel.timedOut=true} |
|
143 } |
|
144 } |
|
145 Rectangle{ id: blackout //Maybe use a colorize effect instead? |
|
146 z: 8 |
|
147 anchors.fill: parent |
|
148 color: "#000000" |
|
149 opacity: 0 |
|
150 } |
|
151 MouseArea{ |
|
152 z: 8 |
|
153 enabled: main.show |
|
154 hoverEnabled: main.show //To steal focus from the buttons |
|
155 acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton |
|
156 anchors.fill: parent |
|
157 onClicked: main.show=false; |
|
158 } |
|
159 |
|
160 states: [ |
|
161 State { |
|
162 name: "show" |
|
163 when: show == true |
|
164 PropertyChanges { |
|
165 target: embeddedViewer |
|
166 opacity: 1 |
|
167 } |
|
168 PropertyChanges { |
|
169 target: helpLabel |
|
170 opacity: helpLabel.timedOut?0:1 |
|
171 } |
|
172 PropertyChanges { |
|
173 target: blackout |
|
174 opacity: 0.5 |
|
175 } |
|
176 } |
|
177 ] |
|
178 transitions: [//Should not be too long, because the component has already started running |
|
179 Transition { from: ''; to: "show"; reversible: true |
|
180 ParallelAnimation{ |
|
181 ScriptAction{ script: {helpLabel.timedOut = false; helpTimer.restart();} } |
|
182 NumberAnimation{ exclude: helpLabel; properties: "opacity"; easing.type: Easing.InQuad; duration: 500} |
|
183 PropertyAction { target: loader; property: "focus"; value: true}//Might be needed to ensure the focus stays with us |
|
184 } |
|
185 } |
|
186 ] |
|
187 } |