2import Ubuntu.Components 1.3
3import WindowManager 1.0
4import "MathUtils.js" as MathUtils
5import "../../Components"
9 implicitWidth: listView.contentWidth
11 property QtObject screen: null
12 property alias workspaceModel: listView.model
13 property var background // TODO: should be stored in the workspace data
15 signal commitScreenSetup();
23 var index = listView.getDropIndex(drag);
24 drag.source.workspace.assign(workspaceModel, index)
25 listView.dropItemIndex = index;
26 drag.source.inDropArea = true;
30 var index = listView.getDropIndex(drag);
31 if (listView.dropItemIndex == index) return;
32 listView.model.move(listView.dropItemIndex, index, 1);
33 listView.dropItemIndex = index;
37 drag.source.workspace.unassign()
38 listView.dropItemIndex = -1;
39 drag.source.inDropArea = false;
43 drop.accept(Qt.MoveAction);
44 listView.dropItemIndex = -1;
45 drag.source.inDropArea = false;
53 listView.progressiveScroll(drag.x)
54 listView.hoveredWorkspaceIndex = listView.getDropIndex(drag)
57 listView.hoveredWorkspaceIndex = -1
64 anchors.leftMargin: -itemWidth
65 anchors.rightMargin: -itemWidth
66 boundsBehavior: Flickable.StopAtBounds
68 orientation: ListView.Horizontal
71 rightMargin: itemWidth
73 property var screenSize: screen.availableModes[screen.currentModeIndex].size
74 property int itemWidth: height * screenSize.width / screenSize.height
75 property int foldingAreaWidth: units.gu(10)
76 property real realContentX: contentX - originX + leftMargin
77 property int dropItemIndex: -1
78 property int hoveredWorkspaceIndex: -1
80 function getDropIndex(drag) {
81 var coords = mapToItem(listView.contentItem, drag.x, drag.y)
82 var index = Math.floor((drag.x + listView.realContentX) / (listView.itemWidth + listView.spacing));
83 if (index < 0) index = 0;
84 var upperLimit = dropItemIndex == -1 ? listView.count : listView.count - 1
85 if (index > upperLimit) index = upperLimit;
89 function progressiveScroll(mouseX) {
90 var progress = Math.max(0, Math.min(1, (mouseX - listView.foldingAreaWidth) / (width - listView.leftMargin * 2 - listView.foldingAreaWidth * 2)))
91 listView.contentX = listView.originX + (listView.contentWidth - listView.width + listView.leftMargin + listView.rightMargin) * progress - listView.leftMargin
94 displaced: Transition { UbuntuNumberAnimation { properties: "x" } }
98 objectName: "delegate" + index
100 width: listView.itemWidth
101 Behavior on width { UbuntuNumberAnimation {} }
102 visible: listView.dropItemIndex !== index
104 property int itemX: -listView.realContentX + index * (listView.itemWidth + listView.spacing)
105 property int distanceFromLeft: itemX //- listView.leftMargin
106 property int distanceFromRight: listView.width - listView.leftMargin - listView.rightMargin - itemX - listView.itemWidth
108 property int maxAngle: 40
110 property int itemAngle: {
112 if (distanceFromLeft < 0) {
113 var progress = (distanceFromLeft + listView.foldingAreaWidth) / listView.foldingAreaWidth
114 return MathUtils.linearAnimation(1, -1, 0, maxAngle, Math.max(-1, Math.min(1, progress)));
118 if (index == listView.count - 1) {
119 if (distanceFromRight < 0) {
120 var progress = (distanceFromRight + listView.foldingAreaWidth) / listView.foldingAreaWidth
121 return MathUtils.linearAnimation(1, -1, 0, -maxAngle, Math.max(-1, Math.min(1, progress)));
126 if (distanceFromLeft < listView.foldingAreaWidth) {
127 // itemX : 10gu = p : 100
128 var progress = distanceFromLeft / listView.foldingAreaWidth
129 return MathUtils.linearAnimation(1, -1, 0, maxAngle, Math.max(-1, Math.min(1, progress)));
131 if (distanceFromRight < listView.foldingAreaWidth) {
132 var progress = distanceFromRight / listView.foldingAreaWidth
133 return MathUtils.linearAnimation(1, -1, 0, -maxAngle, Math.max(-1, Math.min(1, progress)));
138 property int itemOffset: {
139 var rotationOffset = (1 - Math.cos(itemAngle * Math.PI / 360)) * listView.itemWidth
141 if (distanceFromLeft < 0) {
142 return -distanceFromLeft - rotationOffset
146 if (index == listView.count - 1) {
147 if (distanceFromRight < 0) {
148 return distanceFromRight + rotationOffset
153 if (itemX < -listView.foldingAreaWidth) {
154 return -itemX - rotationOffset
156 if (distanceFromLeft < listView.foldingAreaWidth) {
157 return (listView.foldingAreaWidth - distanceFromLeft) / 2 - rotationOffset
160 if (distanceFromRight < -listView.foldingAreaWidth) {
161 return distanceFromRight + rotationOffset
164 if (distanceFromRight < listView.foldingAreaWidth) {
165 return -(listView.foldingAreaWidth - distanceFromRight) / 2 + rotationOffset
171// onItemXChanged: if (index == 1) print("x", itemX, listView.contentX)
173 z: itemOffset < 0 ? itemOffset : -itemOffset
177 axis { x: 0; y: 1; z: 0 }
178 origin { x: itemAngle < 0 ? listView.itemWidth : 0; y: height / 2 }
186 height: listView.height
187 width: listView.itemWidth
188 background: root.background
189 screenHeight: screen.availableModes[screen.currentModeIndex].size.height
190 containsDrag: listView.hoveredWorkspaceIndex == index
195 screenWindow.screen.currentWorkspace = model.workspace
201 objectName: "closeMouseArea"
202 anchors { left: parent.left; top: parent.top; leftMargin: -height / 2; topMargin: -height / 2 }
208 model.workspace.unassign();
209 root.commitScreenSetup();
213 source: "../graphics/window-close.svg"
214 anchors.fill: closeMouseArea
215 anchors.margins: units.gu(1)
216 sourceSize.width: width
217 sourceSize.height: height
218 readonly property var mousePos: hoverMouseArea.mapToItem(workspaceDelegate, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
219 readonly property bool shown: (hoverMouseArea.containsMouse || parent.containsMouse)
220 && mousePos.y < workspaceDelegate.width / 4
221 && mousePos.y > -units.gu(2)
222 && mousePos.x > -units.gu(2)
223 && mousePos.x < workspaceDelegate.height / 4
224 opacity: shown ? 1 : 0
226 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
236 propagateComposedEvents: true
237 anchors.leftMargin: listView.leftMargin
238 anchors.rightMargin: listView.rightMargin
240 property int draggedIndex: -1
242 property int startX: 0
243 property int startY: 0
246 if (!pressed || dragging) {
247 listView.progressiveScroll(mouseX)
251 if (Math.abs(mouseY - startY) > units.gu(3)) {
252 drag.axis = Drag.XAndYAxis;
257 var result = fakeDragItem.Drag.drop();
258// if (result == Qt.IgnoreAction) {
259// WorkspaceManager.destroyWorkspace(fakeDragItem.workspace);
261 root.commitScreenSetup();
265 property bool dragging: drag.active
268 print("drai", draggedIndex)
269 var ws = listView.model.get(draggedIndex);
272// listView.model.remove(draggedIndex, 1)
279 if (listView.model.count < 2) return;
281 var coords = mapToItem(listView.contentItem, mouseX, mouseY)
282 draggedIndex = listView.indexAt(coords.x, coords.y)
283 var clickedItem = listView.itemAt(coords.x, coords.y)
285 var itemCoords = clickedItem.mapToItem(listView, -listView.leftMargin, 0);
286 fakeDragItem.x = itemCoords.x
287 fakeDragItem.y = itemCoords.y
288 fakeDragItem.workspace = listView.model.get(draggedIndex)
290 var mouseCoordsInItem = mapToItem(clickedItem, mouseX, mouseY);
291 fakeDragItem.Drag.hotSpot.x = mouseCoordsInItem.x
292 fakeDragItem.Drag.hotSpot.y = mouseCoordsInItem.y
294 drag.axis = Drag.YAxis;
295 drag.target = fakeDragItem;
300 height: listView.height
301 width: listView.itemWidth
302 background: root.background
303 screenHeight: screen.availableModes[screen.currentModeIndex].size.height
306 Drag.active: hoverMouseArea.drag.active
307 Drag.keys: ['workspace']
309 property var workspace
310 property bool inDropArea: false
315 opacity: parent.inDropArea ? 0 : 1
316 Behavior on opacity { UbuntuNumberAnimation { } }
318 anchors.centerIn: parent
328 anchors.centerIn: parent
336 when: fakeDragItem.Drag.active
337 ParentChange { target: fakeDragItem; parent: shell }
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list