18 import Ubuntu.Components 0.1
19 import Ubuntu.Gestures 0.1
20 import Unity.Application 0.1
22 import
"../Components"
28 property bool shown:
false
29 property bool moving:
false
30 property int dragAreaWidth
33 readonly
property bool painting: mainScreenshotImage.visible || fadeInScreenshotImage.visible || appSplash.visible || spreadView.visible
34 property bool fullscreen: priv.focusedApplication ? priv.focusedApplication.fullscreen :
false
35 property bool locked: spreadView.visible
38 property bool overlayMode:
false
39 property int overlayWidth: 0
41 function select(appId) {
42 spreadView.snapTo(priv.indexOf(appId))
47 if (ApplicationManager.focusedApplicationId) {
48 priv.requestNewScreenshot();
50 mainScreenshotImage.anchors.leftMargin = 0;
51 mainScreenshotImage.source = ApplicationManager.get(0).screenshot;
52 mainScreenshotImage.visible =
true;
55 mainScreenshotImage.visible =
false;
60 target: ApplicationManager
63 if (spreadView.visible) {
64 spreadView.snapTo(priv.indexOf(appId));
66 priv.switchToApp(appId);
70 onFocusedApplicationIdChanged: {
71 if (ApplicationManager.focusedApplicationId.length > 0) {
72 if (priv.secondApplicationStarting || priv.applicationStarting) {
73 appSplashTimer.restart();
75 var application = priv.focusedApplication;
76 root.fullscreen = application.fullscreen;
77 mainScreenshotImage.source = application.screenshot;
80 spreadView.selectedIndex = -1;
82 spreadView.contentX = -spreadView.shift;
87 if (!priv.focusedApplication) {
88 mainScreenshotImage.source =
"";
89 mainScreenshotImage.visible =
false;
90 priv.applicationStarting =
true;
92 mainScreenshotImage.source =
"";
93 priv.newFocusedAppId = appId;
94 priv.secondApplicationStarting =
true;
95 priv.requestNewScreenshot();
98 if (spreadView.visible) {
103 onApplicationRemoved: {
104 if (ApplicationManager.count == 0) {
105 mainScreenshotImage.source =
""
106 mainScreenshotImage.visible =
false;
108 mainScreenshotImage.source = ApplicationManager.get(0).screenshot;
116 property string focusedAppId: ApplicationManager.focusedApplicationId
117 property var focusedApplication: ApplicationManager.findApplication(focusedAppId)
118 property url focusedScreenshot: focusedApplication ? focusedApplication.screenshot :
""
120 property bool waitingForScreenshot:
false
122 property bool applicationStarting:
false
123 property bool secondApplicationStarting:
false
125 property string newFocusedAppId
127 onFocusedScreenshotChanged: {
128 if (root.moving && priv.waitingForScreenshot) {
129 mainScreenshotImage.anchors.leftMargin = 0;
130 mainScreenshotImage.source = priv.focusedScreenshot
131 mainScreenshotImage.visible =
true;
132 }
else if (priv.secondApplicationStarting && priv.waitingForScreenshot) {
133 applicationSwitchingAnimation.start();
135 waitingForScreenshot =
false;
138 function requestNewScreenshot() {
139 waitingForScreenshot =
true;
140 ApplicationManager.updateScreenshot(focusedAppId);
143 function switchToApp(appId) {
144 if (priv.focusedAppId) {
145 priv.newFocusedAppId = appId;
146 root.fullscreen = ApplicationManager.findApplication(appId).fullscreen;
147 applicationSwitchingAnimation.start();
149 ApplicationManager.focusApplication(appId);
153 function indexOf(appId) {
154 for (var i = 0; i < ApplicationManager.count; i++) {
155 if (ApplicationManager.get(i).appId == appId) {
166 target: priv.focusedApplication
167 onScreenshotChanged: priv.focusedScreenshot = priv.focusedApplication.screenshot
171 property:
"fullscreen"
172 value: priv.focusedApplication ? priv.focusedApplication.fullscreen :
false
182 priv.applicationStarting =
false;
183 priv.secondApplicationStarting =
false;
187 SequentialAnimation {
188 id: applicationSwitchingAnimation
190 PropertyAction { target: mainScreenshotImage;
property:
"anchors.leftMargin"; value: 0 }
191 PropertyAction { target: mainScreenshotImage;
property:
"source"; value: priv.focusedScreenshot }
192 PropertyAction { targets: [mainScreenshotImage, fadeInScreenshotImage];
property:
"visible"; value:
true }
193 PropertyAction { target: fadeInScreenshotImage;
property:
"source"; value: {
194 var newFocusedApp = ApplicationManager.findApplication(priv.newFocusedAppId);
195 return newFocusedApp ? newFocusedApp.screenshot :
"" }
197 PropertyAction { target: fadeInScreenshotImage;
property:
"opacity"; value: 0 }
198 PropertyAction { target: fadeInScreenshotImage;
property:
"scale"; value: .8 }
203 UbuntuNumberAnimation { target: mainScreenshotImage;
property:
"anchors.leftMargin"; to: root.width; duration: UbuntuAnimation.SlowDuration }
204 UbuntuNumberAnimation { target: fadeInScreenshotImage; properties:
"opacity,scale"; to: 1; duration: UbuntuAnimation.SlowDuration }
208 ScriptAction { script: ApplicationManager.focusApplication(priv.newFocusedAppId); }
209 PropertyAction { target: fadeInScreenshotImage;
property:
"visible"; value:
false }
210 PropertyAction { target: mainScreenshotImage;
property:
"visible"; value:
false }
218 visible: priv.secondApplicationStarting
221 id: fadeInScreenshotImage
222 anchors { left: parent.left; bottom: parent.bottom }
232 visible: priv.applicationStarting
235 id: mainScreenshotImage
236 anchors { left: parent.left; bottom: parent.bottom }
243 direction: Direction.Leftwards
244 enabled: ApplicationManager.count > 1 && spreadView.phase != 2
246 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
247 width: root.dragAreaWidth
252 property bool attachedToView:
true
254 property var gesturePoints:
new Array()
257 if (!dragging && !priv.waitingForScreenshot) {
259 priv.requestNewScreenshot();
260 spreadView.phase = 0;
261 spreadView.contentX = -spreadView.shift;
263 if (dragging && attachedToView) {
265 spreadView.contentX = -touchX - spreadView.shift;
267 if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
269 attachedToView =
false;
272 gesturePoints.push(touchX);
276 if (status == DirectionalDragArea.Recognized) {
277 attachedToView =
true;
289 var oneWayFlick =
true;
290 var smallestX = spreadDragArea.width;
291 for (var i = 0; i < gesturePoints.length; i++) {
292 if (gesturePoints[i] >= smallestX) {
296 smallestX = gesturePoints[i];
300 if (oneWayFlick && spreadView.shiftedContentX > units.gu(2) &&
301 spreadView.shiftedContentX < spreadView.positionMarker1 * spreadView.width) {
304 spreadView.snapTo(1);
305 }
else if (!dragging && attachedToView) {
314 id: coverFlipBackground
317 visible: spreadView.visible
322 blockInput: spreadView.visible
327 objectName:
"spreadView"
329 visible: spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1 || snapAnimation.running
330 contentWidth: spreadRow.width - shift
338 property real shift: width / 2
339 property real shiftedContentX: contentX + shift
341 property int tileDistance: width / 4
345 property real positionMarker1: 0.3
347 property real positionMarker2: 0.45
349 property real positionMarker3: 0.6
351 property real positionMarker4: 0.9
354 property real snapPosition: 0.75
360 property int phase: 0
362 property int selectedIndex: -1
364 onShiftedContentXChanged: {
367 if (shiftedContentX > width * positionMarker2) {
372 if (shiftedContentX < width * positionMarker2) {
374 }
else if (shiftedContentX >= width * positionMarker4) {
382 if (shiftedContentX < positionMarker1 * width) {
383 snapAnimation.targetContentX = -shift;
384 snapAnimation.start();
385 }
else if (shiftedContentX < positionMarker2 * width) {
387 }
else if (shiftedContentX < positionMarker3 * width) {
389 }
else if (phase < 2){
391 snapAnimation.targetContentX = width * positionMarker4 + 1 - shift;
392 snapAnimation.start();
395 function snapTo(index) {
396 spreadView.selectedIndex = index;
397 root.fullscreen = ApplicationManager.get(index).fullscreen;
398 snapAnimation.targetContentX = -shift;
399 snapAnimation.start();
402 SequentialAnimation {
404 property int targetContentX: -spreadView.shift
406 UbuntuNumberAnimation {
409 to: snapAnimation.targetContentX
410 duration: UbuntuAnimation.FastDuration
415 if (spreadView.selectedIndex >= 0) {
416 ApplicationManager.focusApplication(ApplicationManager.get(spreadView.selectedIndex).appId);
417 spreadView.selectedIndex = -1
418 spreadView.phase = 0;
419 spreadView.contentX = -spreadView.shift;
430 width: Math.max(3, ApplicationManager.count) * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5
432 x: spreadView.contentX
436 model: ApplicationManager
437 delegate: TransformedSpreadDelegate {
439 objectName:
"appDelegate" + index
444 startDistance: spreadView.tileDistance
445 endDistance: units.gu(.5)
446 width: spreadView.width
447 height: spreadView.height
448 selected: spreadView.selectedIndex == index
449 otherSelected: spreadView.selectedIndex >= 0 && !selected
452 x: index == 0 ? 0 : spreadView.width + (index - 1) * spreadView.tileDistance
457 var tileProgress = (spreadView.shiftedContentX - index * spreadView.tileDistance) / spreadView.width;
459 if (index == 1 && spreadView.phase < 2) {
460 tileProgress += spreadView.tileDistance / spreadView.width;
467 if (spreadView.phase == 0 && index < 2) {
468 if (progress < spreadView.positionMarker1) {
470 }
else if (progress < spreadView.positionMarker1 + snappingCurve.period){
471 return spreadView.positionMarker1 + snappingCurve.value * 3;
473 return spreadView.positionMarker2;
483 progress: appDelegate.progress - spreadView.positionMarker1
487 if (spreadView.phase == 2) {
488 if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
489 spreadView.snapTo(index);
491 ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);