1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
import Qt 4.7
import UnityApplications 1.0
import Unity2d 1.0 /* required for drag’n’drop handling */
AutoScrollingListView {
id: list
/* The spacing is explicitly set to 0 and compensated for
by adding some padding to the tiles because of
http://bugreports.qt.nokia.com/browse/QTBUG-17622. */
spacing: 0
property int tileSize: 54
/* Keep a reference to the currently visible contextual menu */
property variant visibleMenu
/* A hint for items to determine the value of their 'z' property */
property real itemZ: 0
delegate: LauncherItem {
id: launcherItem
width: list.width
tileSize: list.tileSize
desktopFile: item.desktop_file ? item.desktop_file : ""
icon: "image://icons/" + item.icon
running: item.running
active: item.active
urgent: item.urgent
launching: item.launching
pips: Math.min(item.windowCount, 3)
property bool noOverlays: item.counter == undefined
counter: (noOverlays) ? 0 : item.counter
counterVisible: (noOverlays) ? false : item.counterVisible
progress: (noOverlays) ? 0.0 : item.progress
progressBarVisible: (noOverlays) ? false : item.progressBarVisible
emblem: (noOverlays && item.emblem) ? "image://icons/" + item.emblem : ""
emblemVisible: (noOverlays) ? false : item.emblemVisible
shortcutVisible: item.toString().indexOf("LauncherApplication") == 0 &&
index <= 9 && launcherView.superKeyPressed
shortcutText: index + 1
/* Best way I could find to check if the item is an application or the
workspaces switcher. There may be something cleaner and better. */
backgroundFromIcon: item.toString().indexOf("LauncherApplication") == 0 ||
item.toString().indexOf("Workspaces") == 0
Binding { target: item.menu; property: "title"; value: item.name }
/* Drag’n’drop handling */
function dragEnterEvent(event) { item.onDragEnter(event) }
function dropEvent(event) { item.onDrop(event) }
function showMenu() {
/* Prevent the simultaneous display of multiple menus */
if (list.visibleMenu != item.menu && list.visibleMenu != undefined) {
list.visibleMenu.hide()
}
list.visibleMenu = item.menu
// The extra 4 pixels are needed to center exactly with the arrow
// indicating the active tile.
item.menu.show(width, panel.y + list.y +
y + height / 2 - list.contentY
- list.paddingTop + 4)
}
onClicked: {
if (mouse.button == Qt.LeftButton) {
item.menu.hide()
item.activate()
}
else if (mouse.button == Qt.RightButton) {
item.menu.folded = false
showMenu()
}
}
/* Display the tooltip when hovering the item only when the list
is not moving */
onEntered: if (!list.moving && !list.autoScrolling) showMenu()
onExited: {
/* When unfolded, leave enough time for the user to reach the
menu. Necessary because there is some void between the item
and the menu. Also it fixes the case when the user
overshoots. */
if (!item.menu.folded)
item.menu.hideWithDelay(400)
else
item.menu.hide()
}
Connections {
target: list
onMovementStarted: item.menu.hide()
onAutoScrollingChanged: if (list.autoScrolling) item.menu.hide()
}
Connections {
target: dnd
/* Hide the tooltip/menu when dragging an application. */
onCurrentIdChanged: if (dnd.currentId != "") item.menu.hide()
}
function setIconGeometry() {
if (running) {
item.setIconGeometry(x + panel.x, y + panel.y, width, height)
}
}
ListView.onAdd: SequentialAnimation {
PropertyAction { target: launcherItem; property: "scale"; value: 0 }
NumberAnimation { target: launcherItem; property: "height";
from: 0; to: launcherItem.tileSize; duration: 250; easing.type: Easing.InOutQuad }
NumberAnimation { target: launcherItem; property: "scale"; to: 1; duration: 250; easing.type: Easing.InOutQuad }
}
ListView.onRemove: SequentialAnimation {
PropertyAction { target: launcherItem; property: "ListView.delayRemove"; value: true }
NumberAnimation { target: launcherItem; property: "scale"; to: 0; duration: 250; easing.type: Easing.InOutQuad }
NumberAnimation { target: launcherItem; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad }
PropertyAction { target: launcherItem; property: "ListView.delayRemove"; value: false }
}
onRunningChanged: setIconGeometry()
/* Note: this doesn’t work as expected for the first favorite
application in the list if it is already running when the
launcher is started, because its y property doesn’t change.
This isn’t too bad though, as the launcher is supposed to be
started before any other regular application. */
onYChanged: setIconGeometry()
Connections {
target: item
onWindowAdded: item.setIconGeometry(x + panel.x, y + panel.y, width, height, xid)
/* Not all items are applications. */
ignoreUnknownSignals: true
}
Connections {
target: launcherView
onKeyboardShortcutPressed: {
/* Only applications can be launched by keyboard shortcuts */
if (item.toString().indexOf("LauncherApplication") == 0 && index == itemIndex) {
item.menu.hide()
item.activate()
}
}
}
}
}
|