on xenial help sign in
Make Greeter still be a Showable
commita258c2deb7f5d1cf26c4aade023e153152c408aa authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 8 Dec 2014, 10:21 (12 years ago) parent430910d
2 files changed+41−53
qml/Components/Showable.qml+13 qml/Greeter/Greeter.qml+28−53
qml/Components/Showable.qml+13
@@ -99,10 +99,23 @@ Item {
9999 return true;
100100 }
101101
102+ /*
103+ Will be called right before starting the hideAnimation.
104+ */
105+ property var prepareToHide: function(){}
106+
102107 function hide() {
103108 if (showAnimation != undefined && showAnimation.running) {
104109 showAnimation.stop()
105110 }
111+
112+ if (typeof prepareToHide === "function") {
113+ prepareToHide();
114+ } else {
115+ console.warn("Showable.prepareToHide should be a function, but it's a " +
116+ (typeof prepareToHide) + " instead");
117+ }
118+
106119 if (hideAnimation != undefined) {
107120 if (!hideAnimation.running) {
108121 hideAnimation.restart()
qml/Greeter/Greeter.qml+28−53
@@ -20,7 +20,7 @@ import Ubuntu.Gestures 0.1
2020import LightDM 0.1 as LightDM
2121import "../Components"
2222
23−Item {
23+Showable {
2424 id: greeter
2525 enabled: visible
2626
@@ -28,39 +28,19 @@ Item {
2828
2929 property url background
3030
31− property bool shown: true
32− function showNow() {
33− shown = true;
34− positionLock.disable();
35− greeter.x = 0;
36− greeter.visible = true;
37− }
38− function show() {
39− shown = true;
40− hideAnimation.stop();
41− showAnimation.start();
42− }
43− function hideNow() {
44− shown = false;
45− greeter.x = -greeter.width;
46− greeter.visible = false;
47− positionLock.enable();
31+ function hideRight() {
32+ d.forceRightOnNextHideAnimation = true;
33+ hide();
4834 }
49− function hide() {
50− shown = false;
51− showAnimation.stop();
52− if (!hideAnimation.running) {
53− hideTranslation.to = greeter.x > 0 ? greeter.width : -greeter.width;
54− hideAnimation.start();
55− }
35+
36+ prepareToHide: function () {
37+ hideTranslation.to = greeter.x > 0 || d.forceRightOnNextHideAnimation ? greeter.width : -greeter.width;
38+ d.forceRightOnNextHideAnimation = false;
5639 }
57− function hideRight() {
58− shown = false;
59− showAnimation.stop();
60− if (!hideAnimation.running) {
61− hideTranslation.to = greeter.width;
62− hideAnimation.start();
63− }
40+
41+ QtObject {
42+ id: d
43+ property bool forceRightOnNextHideAnimation: false
6444 }
6545
6646 // <dandrader> Is this really necessary?
@@ -190,22 +170,21 @@ Item {
190170 Binding {
191171 id: positionLock
192172
193− function enable() {
194− if (__enabled) {
173+ property bool enabled: false
174+ onEnabledChanged: {
175+ if (enabled === __enabled) {
195176 return;
196177 }
197178
198− if (greeter.x > 0) {
199− value = Qt.binding(function() { return greeter.width; })
200− } else {
201− value = Qt.binding(function() { return -greeter.width; })
179+ if (enabled) {
180+ if (greeter.x > 0) {
181+ value = Qt.binding(function() { return greeter.width; })
182+ } else {
183+ value = Qt.binding(function() { return -greeter.width; })
184+ }
202185 }
203186
204− __enabled = true;
205− }
206−
207− function disable() {
208− __enabled = false;
187+ __enabled = enabled;
209188 }
210189
211190 property bool __enabled: false
@@ -215,7 +194,7 @@ Item {
215194 property: "x"
216195 }
217196
218− SequentialAnimation {
197+ hideAnimation: SequentialAnimation {
219198 id: hideAnimation
220199 objectName: "hideAnimation"
221200 StandardAnimation {
@@ -224,19 +203,15 @@ Item {
224203 target: greeter
225204 duration: UbuntuAnimation.FastDuration
226205 }
227− ScriptAction { script: {
228− greeter.visible = false;
229− positionLock.enable();
230− } }
206+ PropertyAction { target: greeter; property: "visible"; value: false }
207+ PropertyAction { target: positionLock; property: "enabled"; value: true }
231208 }
232209
233− SequentialAnimation {
210+ showAnimation: SequentialAnimation {
234211 id: showAnimation
235212 objectName: "showAnimation"
236− ScriptAction { script: {
237− greeter.visible = true;
238− positionLock.disable();
239− } }
213+ PropertyAction { target: greeter; property: "visible"; value: true }
214+ PropertyAction { target: positionLock; property: "enabled"; value: false }
240215 StandardAnimation {
241216 property: "x"
242217 target: greeter