~ubuntu-branches/ubuntu/natty/unity-2d/natty

« back to all changes in this revision

Viewing changes to launcher/LauncherList.qml

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2011-02-24 13:45:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110224134527-d2lk3qu3sxe9a8z0
Tags: 3.6.0-0ubuntu1
New Upstream version

Show diffs side-by-side

added added

removed removed

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