18 import Ubuntu.Components 0.1
19 import Ubuntu.Gestures 0.1
20 import Unity.Application 0.1
21 import LightDM 0.1 as LightDM
23 import
"../Components"
29 property bool shown:
false
30 property bool moving:
false
31 property int dragAreaWidth
34 readonly
property bool painting: mainScreenshotImage.visible || fadeInScreenshotImage.visible || appSplash.visible || spreadView.visible
35 property bool fullscreen: priv.focusedApplication ? priv.focusedApplication.fullscreen :
false
36 property bool locked: spreadView.visible
37 property bool spreadEnabled:
true
40 property bool overlayMode:
false
41 property int overlayWidth: 0
43 function select(appId) {
44 spreadView.snapTo(priv.indexOf(appId))
49 if (ApplicationManager.focusedApplicationId) {
50 priv.requestNewScreenshot();
52 mainScreenshotImage.anchors.leftMargin = 0;
53 mainScreenshotImage.source = ApplicationManager.get(0).screenshot;
54 mainScreenshotImage.visible =
true;
57 mainScreenshotImage.visible =
false;
62 target: ApplicationManager
65 if (spreadView.visible) {
66 spreadView.snapTo(priv.indexOf(appId));
68 priv.switchToApp(appId);
72 onFocusedApplicationIdChanged: {
73 if (ApplicationManager.focusedApplicationId.length > 0) {
74 if (priv.secondApplicationStarting || priv.applicationStarting) {
75 appSplashTimer.restart();
77 var application = priv.focusedApplication;
78 root.fullscreen = application.fullscreen;
79 mainScreenshotImage.source = application.screenshot;
82 spreadView.selectedIndex = -1;
84 spreadView.contentX = -spreadView.shift;
89 if (!priv.focusedApplication) {
90 mainScreenshotImage.source =
"";
91 mainScreenshotImage.visible =
false;
92 priv.applicationStarting =
true;
94 mainScreenshotImage.source =
"";
95 priv.newFocusedAppId = appId;
96 priv.secondApplicationStarting =
true;
97 priv.requestNewScreenshot();
100 if (spreadView.visible) {
101 spreadView.snapTo(0);
105 onApplicationRemoved: {
106 if (ApplicationManager.count == 0) {
107 mainScreenshotImage.source =
""
108 mainScreenshotImage.visible =
false;
110 mainScreenshotImage.source = ApplicationManager.get(0).screenshot;
118 property string focusedAppId: ApplicationManager.focusedApplicationId
119 property var focusedApplication: ApplicationManager.findApplication(focusedAppId)
120 property url focusedScreenshot: focusedApplication ? focusedApplication.screenshot :
""
122 property bool waitingForScreenshot:
false
124 property bool applicationStarting:
false
125 property bool secondApplicationStarting:
false
127 property string newFocusedAppId
129 onFocusedScreenshotChanged: {
130 if (root.moving && priv.waitingForScreenshot) {
131 mainScreenshotImage.anchors.leftMargin = 0;
132 mainScreenshotImage.source = priv.focusedScreenshot
133 mainScreenshotImage.visible =
true;
134 }
else if (priv.secondApplicationStarting && priv.waitingForScreenshot) {
135 applicationSwitchingAnimation.start();
136 if (LightDM.Greeter.active && !LightDM.Greeter.promptless) {
139 applicationSwitchingAnimation.complete();
142 waitingForScreenshot =
false;
145 function requestNewScreenshot() {
146 waitingForScreenshot =
true;
147 ApplicationManager.updateScreenshot(focusedAppId);
150 function switchToApp(appId) {
151 if (priv.focusedAppId) {
152 priv.newFocusedAppId = appId;
153 root.fullscreen = ApplicationManager.findApplication(appId).fullscreen;
154 applicationSwitchingAnimation.start();
155 if (LightDM.Greeter.active && !LightDM.Greeter.promptless) {
158 applicationSwitchingAnimation.complete();
161 ApplicationManager.focusApplication(appId);
165 function indexOf(appId) {
166 for (var i = 0; i < ApplicationManager.count; i++) {
167 if (ApplicationManager.get(i).appId == appId) {
178 target: priv.focusedApplication
179 onScreenshotChanged: priv.focusedScreenshot = priv.focusedApplication.screenshot
183 property:
"fullscreen"
184 value: priv.focusedApplication ? priv.focusedApplication.fullscreen :
false
194 priv.applicationStarting =
false;
195 priv.secondApplicationStarting =
false;
199 SequentialAnimation {
200 id: applicationSwitchingAnimation
202 PropertyAction { target: mainScreenshotImage;
property:
"anchors.leftMargin"; value: 0 }
203 PropertyAction { target: mainScreenshotImage;
property:
"source"; value: priv.focusedScreenshot }
204 PropertyAction { targets: [mainScreenshotImage, fadeInScreenshotImage];
property:
"visible"; value:
true }
205 PropertyAction { target: fadeInScreenshotImage;
property:
"source"; value: {
206 var newFocusedApp = ApplicationManager.findApplication(priv.newFocusedAppId);
207 return newFocusedApp ? newFocusedApp.screenshot :
"" }
209 PropertyAction { target: fadeInScreenshotImage;
property:
"opacity"; value: 0 }
210 PropertyAction { target: fadeInScreenshotImage;
property:
"scale"; value: .8 }
215 UbuntuNumberAnimation { target: mainScreenshotImage;
property:
"anchors.leftMargin"; to: root.width; duration: UbuntuAnimation.SlowDuration }
216 UbuntuNumberAnimation { target: fadeInScreenshotImage; properties:
"opacity,scale"; to: 1; duration: UbuntuAnimation.SlowDuration }
220 ScriptAction { script: ApplicationManager.focusApplication(priv.newFocusedAppId); }
221 PropertyAction { target: fadeInScreenshotImage;
property:
"visible"; value:
false }
222 PropertyAction { target: mainScreenshotImage;
property:
"visible"; value:
false }
230 visible: priv.secondApplicationStarting
233 id: fadeInScreenshotImage
234 anchors { left: parent.left; bottom: parent.bottom }
244 visible: priv.applicationStarting
250 id: mainScreenshotImage
251 anchors { left: parent.left; bottom: parent.bottom }
258 direction: Direction.Leftwards
259 enabled: ApplicationManager.count > 1 && spreadView.phase != 2 && root.spreadEnabled
261 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
262 width: root.dragAreaWidth
267 property bool attachedToView:
true
269 property var gesturePoints:
new Array()
272 if (!dragging && !priv.waitingForScreenshot) {
274 priv.requestNewScreenshot();
275 spreadView.phase = 0;
276 spreadView.contentX = -spreadView.shift;
278 if (dragging && attachedToView) {
280 spreadView.contentX = -touchX - spreadView.shift;
282 if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
284 attachedToView =
false;
287 gesturePoints.push(touchX);
291 if (status == DirectionalDragArea.Recognized) {
292 attachedToView =
true;
304 var oneWayFlick =
true;
305 var smallestX = spreadDragArea.width;
306 for (var i = 0; i < gesturePoints.length; i++) {
307 if (gesturePoints[i] >= smallestX) {
311 smallestX = gesturePoints[i];
315 if (oneWayFlick && spreadView.shiftedContentX > units.gu(2) &&
316 spreadView.shiftedContentX < spreadView.positionMarker1 * spreadView.width) {
319 spreadView.snapTo(1);
320 }
else if (!dragging && attachedToView) {
329 id: coverFlipBackground
332 visible: spreadView.visible
337 blockInput: spreadView.visible
342 objectName:
"spreadView"
344 visible: spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1 || snapAnimation.running
345 contentWidth: spreadRow.width - shift
353 property real shift: width / 2
354 property real shiftedContentX: contentX + shift
356 property int tileDistance: width / 4
360 property real positionMarker1: 0.3
362 property real positionMarker2: 0.45
364 property real positionMarker3: 0.6
366 property real positionMarker4: 0.9
369 property real snapPosition: 0.75
375 property int phase: 0
377 property int selectedIndex: -1
379 onShiftedContentXChanged: {
382 if (shiftedContentX > width * positionMarker2) {
387 if (shiftedContentX < width * positionMarker2) {
389 }
else if (shiftedContentX >= width * positionMarker4) {
397 if (shiftedContentX < positionMarker1 * width) {
398 snapAnimation.targetContentX = -shift;
399 snapAnimation.start();
400 }
else if (shiftedContentX < positionMarker2 * width) {
402 }
else if (shiftedContentX < positionMarker3 * width) {
404 }
else if (phase < 2){
406 snapAnimation.targetContentX = width * positionMarker4 + 1 - shift;
407 snapAnimation.start();
410 function snapTo(index) {
411 spreadView.selectedIndex = index;
412 root.fullscreen = ApplicationManager.get(index).fullscreen;
413 snapAnimation.targetContentX = -shift;
414 snapAnimation.start();
417 SequentialAnimation {
419 property int targetContentX: -spreadView.shift
421 UbuntuNumberAnimation {
424 to: snapAnimation.targetContentX
425 duration: UbuntuAnimation.FastDuration
430 if (spreadView.selectedIndex >= 0) {
431 ApplicationManager.focusApplication(ApplicationManager.get(spreadView.selectedIndex).appId);
432 spreadView.selectedIndex = -1
433 spreadView.phase = 0;
434 spreadView.contentX = -spreadView.shift;
445 width: Math.max(3, ApplicationManager.count) * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5
447 x: spreadView.contentX
451 model: ApplicationManager
452 delegate: TransformedSpreadDelegate {
454 objectName:
"appDelegate" + index
459 startDistance: spreadView.tileDistance
460 endDistance: units.gu(.5)
461 width: spreadView.width
462 height: spreadView.height
463 selected: spreadView.selectedIndex == index
464 otherSelected: spreadView.selectedIndex >= 0 && !selected
467 x: index == 0 ? 0 : spreadView.width + (index - 1) * spreadView.tileDistance
472 var tileProgress = (spreadView.shiftedContentX - index * spreadView.tileDistance) / spreadView.width;
474 if (index == 1 && spreadView.phase < 2) {
475 tileProgress += spreadView.tileDistance / spreadView.width;
482 if (spreadView.phase == 0 && index < 2) {
483 if (progress < spreadView.positionMarker1) {
485 }
else if (progress < spreadView.positionMarker1 + snappingCurve.period){
486 return spreadView.positionMarker1 + snappingCurve.value * 3;
488 return spreadView.positionMarker2;
498 progress: appDelegate.progress - spreadView.positionMarker1
502 if (spreadView.phase == 2) {
503 if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
504 spreadView.snapTo(index);
506 ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);