on 050141c help sign in
unity8/Launcher/LauncherPanel.qml
120 lines 4.6 kB history raw
1/*
2 * Copyright (C) 2013 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 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Unity 0.1
21Item {
22 id: root
24 rotation: inverted ? 180 : 0
26 property var model
27 property bool inverted: true
28 property bool dragging: false
29 property bool moving: launcherFlickable.moving
30 property int dragPosition: 0
31 property int highlightIndex: -1
33 signal applicationSelected(string desktopFile)
34 signal dashItemSelected(int index)
36 onDragPositionChanged: {
37 var effectiveDragPosition = root.inverted ? launcherFlickable.height - dragPosition : dragPosition - mainColumn.anchors.margins
39 var hiddenContentHeight = launcherFlickable.contentHeight - launcherFlickable.height
40 // Shortening scrollable height because the first/last item needs to be fully expanded before reaching the top/bottom
41 var scrollableHeight = launcherFlickable.height - (launcherFlickable.itemSize + launcherColumn.spacing) *2
42 // As we shortened the scrollableHeight, lets move everything down by the itemSize
43 var shortenedEffectiveDragPosition = effectiveDragPosition - launcherFlickable.itemSize - launcherColumn.spacing
44 var newContentY = shortenedEffectiveDragPosition * hiddenContentHeight / scrollableHeight
46 // limit top/bottom to prevent overshooting
47 launcherFlickable.contentY = Math.min(hiddenContentHeight, Math.max(0, newContentY));
49 // Now calculate the current index:
50 // > the current mouse position + the hidden/scolled content on top is the mouse position in the averall view
51 // > adjust that removing all the margins
52 // > divide by itemSize to get index
53 highlightIndex = (effectiveDragPosition + launcherFlickable.contentY - mainColumn.anchors.margins*3 - launcherColumn.spacing/2) / (launcherFlickable.itemSize + launcherColumn.spacing)
54 }
56 BorderImage {
57 id: background
58 source: "graphics/launcher_bg.sci"
59 anchors.fill: parent
60 }
62 Column {
63 id: mainColumn
64 anchors.fill: parent
65 anchors.margins: units.gu(1)
66 spacing: units.gu(1)
68 LauncherDelegate {
69 id: dashItem
70 objectName: "dashItem"
71 width: launcherFlickable.itemSize
72 height: launcherFlickable.itemSize
73 anchors.horizontalCenter: parent.horizontalCenter
74 iconName: "dash"
75 onClicked: root.dashItemSelected(0)
76 }
77 Flickable {
78 id: launcherFlickable
79 anchors.left: parent.left
80 anchors.right: parent.right
81 height: parent.height - dashItem.height - parent.spacing
82 contentHeight: launcherColumn.height
84 property int itemSize: width
86 Column {
87 id: launcherColumn
88 width: parent.width
89 spacing: units.gu(1)
90 anchors.horizontalCenter: parent.horizontalCenter
92 Repeater {
93 id: iconRepeater
94 model: root.model
96 LauncherDelegate {
97 id: launcherDelegate
98 objectName: "launcherDelegate" + index
99 width: launcherFlickable.itemSize
100 height: launcherFlickable.itemSize
101 iconName: model.icon
102 inverted: root.inverted
103 highlighted: root.dragging && index === root.highlightIndex
104 z: -Math.abs(offset)
105 state: "docked"
107 maxAngle: 60
109 itemsBeforeThis: index
110 itemsAfterThis: iconRepeater.count - (index+1)
112 onClicked: {
113 root.applicationSelected(launcherModel.get(index).desktopFile);
114 }
115 }
116 }
117 }
118 }
119 }