Unity 8
DesktopStage.qml
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17  */
18 
19 import QtQuick 2.3
20 import Ubuntu.Components 1.1
21 import Unity.Application 0.1
22 import "../Components/PanelState"
23 
24 Item {
25  id: root
26 
27  anchors.fill: parent
28 
29  property alias background: wallpaper.source
30 
31  CrossFadeImage {
32  id: wallpaper
33  anchors.fill: parent
34  sourceSize { height: root.height; width: root.width }
35  fillMode: Image.PreserveAspectCrop
36  }
37 
38  Connections {
39  target: ApplicationManager
40  onApplicationAdded: {
41  ApplicationManager.requestFocusApplication(ApplicationManager.get(ApplicationManager.count-1).appId)
42  }
43 
44  onFocusRequested: {
45  var appIndex = priv.indexOf(appId);
46  var appDelegate = appRepeater.itemAt(appIndex);
47  if (appDelegate.state === "minimized") {
48  appDelegate.state = "normal"
49  }
50  ApplicationManager.focusApplication(appId);
51  }
52  }
53 
54  QtObject {
55  id: priv
56 
57  readonly property string focusedAppId: ApplicationManager.focusedApplicationId
58  readonly property var focusedAppDelegate: focusedAppId ? appRepeater.itemAt(indexOf(focusedAppId)) : null
59 
60  function indexOf(appId) {
61  for (var i = 0; i < ApplicationManager.count; i++) {
62  if (ApplicationManager.get(i).appId == appId) {
63  return i;
64  }
65  }
66  return -1;
67  }
68  }
69 
70  Connections {
71  target: PanelState
72  onClose: {
73  ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
74  }
75  onMinimize: appRepeater.itemAt(0).state = "minimized"
76  onMaximize: appRepeater.itemAt(0).state = "normal"
77  }
78 
79  Binding {
80  target: PanelState
81  property: "buttonsVisible"
82  value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.state === "maximized"
83  }
84 
85  Repeater {
86  id: appRepeater
87  model: ApplicationManager
88 
89  delegate: Item {
90  id: appDelegate
91  z: ApplicationManager.count - index
92  y: units.gu(3)
93  width: units.gu(60)
94  height: units.gu(50)
95 
96  readonly property int minWidth: units.gu(10)
97  readonly property int minHeight: units.gu(10)
98 
99  states: [
100  State {
101  name: "normal"
102  },
103  State {
104  name: "maximized"
105  PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
106  },
107  State {
108  name: "minimized"
109  PropertyChanges { target: appDelegate; x: -appDelegate.width / 2; scale: units.gu(5) / appDelegate.width; opacity: 0 }
110  }
111  ]
112  transitions: [
113  Transition {
114  PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
115  }
116  ]
117 
118  WindowMoveResizeArea {
119  target: appDelegate
120  minWidth: appDelegate.minWidth
121  minHeight: appDelegate.minHeight
122  resizeHandleWidth: units.gu(0.5)
123  windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
124 
125  onPressed: ApplicationManager.requestFocusApplication(model.appId)
126  }
127 
128  DecoratedWindow {
129  anchors.fill: parent
130  application: ApplicationManager.get(index)
131  active: ApplicationManager.focusedApplicationId === model.appId
132 
133  onClose: ApplicationManager.stopApplication(model.appId)
134  onMaximize: appDelegate.state = (appDelegate.state == "maximized" ? "normal" : "maximized")
135  onMinimize: appDelegate.state = "minimized"
136  }
137  }
138  }
139 }