@@ -0,0 +1,162 @@
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+
23+Item {
24+ id: root
25+
26+ anchors.fill: parent
27+
28+ Connections {
29+ target: ApplicationManager
30+ onApplicationAdded: {
31+ // Initial placement to avoid having the window decoration behind the panel
32+ appRepeater.itemAt(ApplicationManager.count-1).y = units.gu(3)
33+ ApplicationManager.requestFocusApplication(ApplicationManager.get(ApplicationManager.count-1).appId)
34+ }
35+
36+ onFocusRequested: {
37+ var appIndex = priv.indexOf(appId);
38+ var appDelegate = appRepeater.itemAt(appIndex);
39+ if (appDelegate.state === "minimized") {
40+ appDelegate.state = "normal"
41+ }
42+ ApplicationManager.focusApplication(appId);
43+ }
44+ }
45+
46+ QtObject {
47+ id: priv
48+ function indexOf(appId) {
49+ for (var i = 0; i < ApplicationManager.count; i++) {
50+ if (ApplicationManager.get(i).appId == appId) {
51+ return i;
52+ }
53+ }
54+ return -1;
55+ }
56+ }
57+
58+ Repeater {
59+ id: appRepeater
60+ model: ApplicationManager
61+
62+ delegate: Item {
63+ id: appDelegate
64+ height: units.gu(30)
65+ width: units.gu(30)
66+ z: ApplicationManager.count - index
67+
68+ states: [
69+ State {
70+ name: "normal"
71+ },
72+ State {
73+ name: "maximized"
74+ PropertyChanges { target: appDelegate; x: 0; y: 0; width: root.width; height: root.height }
75+ },
76+ State {
77+ name: "minimized"
78+ PropertyChanges { target: appDelegate; x: -appDelegate.width / 2; scale: units.gu(5) / appDelegate.width; opacity: 0 }
79+ }
80+ ]
81+ transitions: [
82+ Transition {
83+ PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
84+ }
85+ ]
86+
87+ BorderImage {
88+ anchors {
89+ fill: appDelegate
90+ margins: -units.gu(2)
91+ }
92+ source: "graphics/dropshadow2gu.sci"
93+ opacity: .3
94+ Behavior on opacity { UbuntuNumberAnimation {} }
95+ }
96+
97+ MouseArea {
98+ anchors.fill: parent
99+ anchors.margins: -units.gu(0.5)
100+
101+ property bool resizeWidth: false
102+ property bool resizeHeight: false
103+
104+ property int startX: 0
105+ property int startWidth: 0
106+ property int startY: 0
107+ property int startHeight: 0
108+
109+ onPressed: {
110+ ApplicationManager.requestFocusApplication(model.appId)
111+ if (mouseX > width - units.gu(1)) {
112+ resizeWidth = true;
113+ startX = mouseX;
114+ startWidth = appDelegate.width;
115+ }
116+ if (mouseY > height - units.gu(1)) {
117+ resizeHeight = true;
118+ startY = mouseY;
119+ startHeight = appDelegate.height;
120+ }
121+ if (!resizeHeight && !resizeWidth) {
122+ drag.target = appDelegate;
123+ }
124+ }
125+
126+ onMouseXChanged: {
127+ if (resizeWidth) {
128+ appDelegate.width = startWidth + (mouseX - startX)
129+ }
130+ }
131+ onMouseYChanged: {
132+ if (resizeHeight) {
133+ appDelegate.height = startHeight + (mouseY - startY)
134+ }
135+ }
136+
137+ onReleased: {
138+ resizeWidth = false;
139+ resizeHeight = false;
140+ drag.target = undefined;
141+ }
142+ }
143+
144+ WindowDecoration {
145+ anchors { left: parent.left; top: parent.top; right: parent.right }
146+ height: units.gu(3)
147+ title: model.name
148+ onClose: ApplicationManager.stopApplication(model.appId)
149+ onMaximize: appDelegate.state = (appDelegate.state == "maximized" ? "normal" : "maximized")
150+ onMinimize: appDelegate.state = "minimized"
151+ active: ApplicationManager.focusedApplicationId == model.appId
152+ }
153+
154+ ApplicationWindow {
155+ anchors.fill: parent
156+ anchors.topMargin: units.gu(3)
157+ application: ApplicationManager.get(index)
158+ interactive: index == 0
159+ }
160+ }
161+ }
162+}