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
238 id: mainScreenshotImage
239 anchors { left: parent.left; bottom: parent.bottom }
246 direction: Direction.Leftwards
247 enabled: ApplicationManager.count > 1 && spreadView.phase != 2
249 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
250 width: root.dragAreaWidth
255 property bool attachedToView:
true
257 property var gesturePoints:
new Array()
260 if (!dragging && !priv.waitingForScreenshot) {
262 priv.requestNewScreenshot();
263 spreadView.phase = 0;
264 spreadView.contentX = -spreadView.shift;
266 if (dragging && attachedToView) {
268 spreadView.contentX = -touchX - spreadView.shift;
270 if (attachedToView && spreadView.shiftedContentX >= spreadView.width * spreadView.positionMarker3) {
272 attachedToView =
false;
275 gesturePoints.push(touchX);
279 if (status == DirectionalDragArea.Recognized) {
280 attachedToView =
true;
292 var oneWayFlick =
true;
293 var smallestX = spreadDragArea.width;
294 for (var i = 0; i < gesturePoints.length; i++) {
295 if (gesturePoints[i] >= smallestX) {
299 smallestX = gesturePoints[i];
303 if (oneWayFlick && spreadView.shiftedContentX > units.gu(2) &&
304 spreadView.shiftedContentX < spreadView.positionMarker1 * spreadView.width) {
307 spreadView.snapTo(1);
308 }
else if (!dragging && attachedToView) {
317 id: coverFlipBackground
320 visible: spreadView.visible
325 blockInput: spreadView.visible
330 objectName:
"spreadView"
332 visible: spreadDragArea.status == DirectionalDragArea.Recognized || phase > 1 || snapAnimation.running
333 contentWidth: spreadRow.width - shift
341 property real shift: width / 2
342 property real shiftedContentX: contentX + shift
344 property int tileDistance: width / 4
348 property real positionMarker1: 0.3
350 property real positionMarker2: 0.45
352 property real positionMarker3: 0.6
354 property real positionMarker4: 0.9
357 property real snapPosition: 0.75
363 property int phase: 0
365 property int selectedIndex: -1
367 onShiftedContentXChanged: {
370 if (shiftedContentX > width * positionMarker2) {
375 if (shiftedContentX < width * positionMarker2) {
377 }
else if (shiftedContentX >= width * positionMarker4) {
385 if (shiftedContentX < positionMarker1 * width) {
386 snapAnimation.targetContentX = -shift;
387 snapAnimation.start();
388 }
else if (shiftedContentX < positionMarker2 * width) {
390 }
else if (shiftedContentX < positionMarker3 * width) {
392 }
else if (phase < 2){
394 snapAnimation.targetContentX = width * positionMarker4 + 1 - shift;
395 snapAnimation.start();
398 function snapTo(index) {
399 spreadView.selectedIndex = index;
400 root.fullscreen = ApplicationManager.get(index).fullscreen;
401 snapAnimation.targetContentX = -shift;
402 snapAnimation.start();
405 SequentialAnimation {
407 property int targetContentX: -spreadView.shift
409 UbuntuNumberAnimation {
412 to: snapAnimation.targetContentX
413 duration: UbuntuAnimation.FastDuration
418 if (spreadView.selectedIndex >= 0) {
419 ApplicationManager.focusApplication(ApplicationManager.get(spreadView.selectedIndex).appId);
420 spreadView.selectedIndex = -1
421 spreadView.phase = 0;
422 spreadView.contentX = -spreadView.shift;
433 width: Math.max(3, ApplicationManager.count) * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5
435 x: spreadView.contentX
439 model: ApplicationManager
440 delegate: TransformedSpreadDelegate {
442 objectName:
"appDelegate" + index
447 startDistance: spreadView.tileDistance
448 endDistance: units.gu(.5)
449 width: spreadView.width
450 height: spreadView.height
451 selected: spreadView.selectedIndex == index
452 otherSelected: spreadView.selectedIndex >= 0 && !selected
455 x: index == 0 ? 0 : spreadView.width + (index - 1) * spreadView.tileDistance
460 var tileProgress = (spreadView.shiftedContentX - index * spreadView.tileDistance) / spreadView.width;
462 if (index == 1 && spreadView.phase < 2) {
463 tileProgress += spreadView.tileDistance / spreadView.width;
470 if (spreadView.phase == 0 && index < 2) {
471 if (progress < spreadView.positionMarker1) {
473 }
else if (progress < spreadView.positionMarker1 + snappingCurve.period){
474 return spreadView.positionMarker1 + snappingCurve.value * 3;
476 return spreadView.positionMarker2;
486 progress: appDelegate.progress - spreadView.positionMarker1
490 if (spreadView.phase == 2) {
491 if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
492 spreadView.snapTo(index);
494 ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);