Unity 8
DesktopStage.qml
1 /*
2  * Copyright (C) 2014-2015 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 import Utils 0.1
24 
25 FocusScope {
26  id: root
27 
28  anchors.fill: parent
29 
30  property alias background: wallpaper.source
31 
32  property var windowStateStorage: WindowStateStorage
33 
34  CrossFadeImage {
35  id: wallpaper
36  anchors.fill: parent
37  sourceSize { height: root.height; width: root.width }
38  fillMode: Image.PreserveAspectCrop
39  }
40 
41  Connections {
42  target: ApplicationManager
43  onApplicationAdded: {
44  ApplicationManager.requestFocusApplication(ApplicationManager.get(ApplicationManager.count-1).appId)
45  }
46 
47  onFocusRequested: {
48  var appIndex = priv.indexOf(appId);
49  var appDelegate = appRepeater.itemAt(appIndex);
50  if (appDelegate.state === "minimized") {
51  appDelegate.state = "normal"
52  }
53  ApplicationManager.focusApplication(appId);
54  }
55  }
56 
57  QtObject {
58  id: priv
59 
60  readonly property string focusedAppId: ApplicationManager.focusedApplicationId
61  readonly property var focusedAppDelegate: focusedAppId ? appRepeater.itemAt(indexOf(focusedAppId)) : null
62 
63  function indexOf(appId) {
64  for (var i = 0; i < ApplicationManager.count; i++) {
65  if (ApplicationManager.get(i).appId == appId) {
66  return i;
67  }
68  }
69  return -1;
70  }
71  }
72 
73  Connections {
74  target: PanelState
75  onClose: {
76  ApplicationManager.stopApplication(ApplicationManager.focusedApplicationId)
77  }
78  onMinimize: appRepeater.itemAt(0).state = "minimized"
79  onMaximize: appRepeater.itemAt(0).state = "normal"
80  }
81 
82  Binding {
83  target: PanelState
84  property: "buttonsVisible"
85  value: priv.focusedAppDelegate !== null && priv.focusedAppDelegate.state === "maximized"
86  }
87 
88  Repeater {
89  id: appRepeater
90  model: ApplicationManager
91 
92  delegate: Item {
93  id: appDelegate
94  z: ApplicationManager.count - index
95  y: units.gu(3)
96  width: units.gu(60)
97  height: units.gu(50)
98 
99  readonly property int minWidth: units.gu(10)
100  readonly property int minHeight: units.gu(10)
101 
102  states: [
103  State {
104  name: "normal"
105  },
106  State {
107  name: "maximized"
108  PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
109  },
110  State {
111  name: "minimized"
112  PropertyChanges { target: appDelegate; x: -appDelegate.width / 2; scale: units.gu(5) / appDelegate.width; opacity: 0 }
113  }
114  ]
115  transitions: [
116  Transition {
117  PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
118  }
119  ]
120 
121  WindowMoveResizeArea {
122  windowStateStorage: root.windowStateStorage
123  target: appDelegate
124  minWidth: appDelegate.minWidth
125  minHeight: appDelegate.minHeight
126  resizeHandleWidth: units.gu(0.5)
127  windowId: model.appId // FIXME: Change this to point to windowId once we have such a thing
128 
129  onPressed: decoratedWindow.focus = true;
130  }
131 
132  DecoratedWindow {
133  id: decoratedWindow
134  objectName: "decoratedWindow_" + appId
135  anchors.fill: parent
136  application: ApplicationManager.get(index)
137  active: ApplicationManager.focusedApplicationId === model.appId
138 
139  onFocusChanged: {
140  if (focus) {
141  ApplicationManager.requestFocusApplication(model.appId);
142  }
143  }
144 
145  onClose: ApplicationManager.stopApplication(model.appId)
146  onMaximize: appDelegate.state = (appDelegate.state == "maximized" ? "normal" : "maximized")
147  onMinimize: appDelegate.state = "minimized"
148  }
149  }
150  }
151 }