~ubuntu-branches/ubuntu/precise/unity-2d/precise-proposed

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
 * This file is part of unity-2d
 *
 * Copyright 2010-2011 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 1.0
import Unity2d 1.0
import "../common"
import "../common/utils.js" as Utils

LauncherDropItem {
    id: launcher
    Accessible.name: "launcher"

    property bool outerEdgeContainsMouse
    property bool shown
    property bool showMenus: true

    property bool containsMouse: declarativeView.monitoredAreaContainsMouse

    function hideMenu() {
        if (main.visibleMenu !== undefined) {
            main.visibleMenu.hide()
        }
        if (shelf.visibleMenu !== undefined) {
            shelf.visibleMenu.hide()
        }
    }

    function focusBFB() {
        if (!main.activeFocus) {
            main.focus = true
        }

        main.currentIndex = 0
        main.positionViewAtBeginning()
    }

    Item {
        anchors.fill: parent
        clip: true

        GnomeBackground {
            Accessible.name: "background"
            anchors.fill: parent
            overlay_color: "black"
            overlay_alpha: 0.66
            visible: !desktop.isCompositingManagerRunning
        }
    }

    Rectangle {
        Accessible.name: "background"
        anchors.fill: parent
        anchors.rightMargin: declarativeView.dashActive ? 0 : border.width
        color: "black"
        opacity: 0.66
        visible: desktop.isCompositingManagerRunning
    }

    Image {
        Accessible.name: "borderWithDash"
        id: border

        width: 1
        height: parent.height
        anchors.right: Utils.isLeftToRight() ? parent.right : undefined
        anchors.left:  Utils.isLeftToRight() ? undefined : parent.left
        visible: declarativeView.dashActive
        source: "artwork/border.png"
        fillMode: Image.Stretch
    }

    Rectangle {
        Accessible.name: "borderWithoutDash"

        width: border.width
        height: parent.height
        anchors.right: Utils.isLeftToRight() ? border.anchors.right : undefined
        anchors.left:  Utils.isLeftToRight() ? undefined : border.anchors.left
        visible: !declarativeView.dashActive

        color: "white"
        opacity: 0.15
    }

    onDesktopFileDropped: applications.insertFavoriteApplication(path)
    onWebpageUrlDropped: applications.insertWebFavorite(url)

    FocusScope {
        Accessible.name: "content"

        focus: true
        anchors.fill: parent
        anchors.rightMargin: border.width
        z: 1 /* ensure the lists are always strictly on top of the background */

        LauncherList {
            id: main
            objectName: "main"

            /* function to position highlighted tile so that the shadow does not cover it */
            function positionMainViewForIndex(index) {
                /* Tile considered 'visible' if it fully drawn */
                var numberVisibleTiles = Math.floor(height / selectionOutlineSize)
                var indexFirstVisibleTile = Math.ceil(contentY / selectionOutlineSize)
                var indexLastVisibleTile = indexFirstVisibleTile + numberVisibleTiles - 1
                var nearestVisibleTile = Utils.clamp(index, indexFirstVisibleTile, indexLastVisibleTile)

                if (nearestVisibleTile == indexFirstVisibleTile) {
                    positionViewAtIndex(Math.max(index - 1, 0), ListView.Beginning)
                }
                else if (nearestVisibleTile == indexLastVisibleTile) {
                    positionViewAtIndex(Math.min(index + 1, count - 1), ListView.End)
                }
            }

            anchors.top: parent.top
            anchors.bottomMargin: 0
            /* the distance from the top of the launcher and the dash tile is 6 instead of 7 */
            anchors.topMargin: -1
            height: parent.height - shelf.height + ((selectionOutlineSize - tileSize)) - 4
            width: parent.width

            /* Ensure all delegates are cached in order to improve smoothness of
               scrolling on very low end platforms */
            cacheBuffer: 10000

            autoScrollSize: tileSize / 2
            autoScrollVelocity: 200
            reorderable: true
            showMenus: launcher.showMenus

            model: ListAggregatorModel {
                id: items
            }

            focus: true
            KeyNavigation.down: shelf

            /* Prevent shadow from overlapping a highlighted item */
            Keys.onPressed: {
                if (event.key == Qt.Key_Up) {
                    positionMainViewForIndex(currentIndex - 1)
                } else if (event.key == Qt.Key_Down) {
                    positionMainViewForIndex(currentIndex + 1)
                }
            }

            /* Always reset highlight to so-called BFB or Dash button */
            Connections {
                target: declarativeView
                onFocusChanged: {
                    if (declarativeView.focus && !main.flicking) {
                        hideMenu()
                    }
                }
            }
        }

        LauncherList {
            id: shelf
            objectName: "shelf"

            anchors.bottom: parent.bottom
            anchors.bottomMargin: main.anchors.bottomMargin
            anchors.topMargin: main.anchors.topMargin
            height: selectionOutlineSize * count
            width: parent.width
            interactive: false
            showMenus: launcher.showMenus

            model: ListAggregatorModel {
                id: shelfItems
            }

            KeyNavigation.up: main
        }
    }

    BfbModel {
        id: bfbModel
        dashView: declarativeView
    }

    ApplicationsList {
        id: applications
    }

    LauncherDevicesList {
        id: devices
    }

    WorkspacesList {
        id: workspaces
    }

    Trashes {
        id: trashes
    }

    Component.onCompleted: {
        items.appendModel(bfbModel);
        items.appendModel(applications);
        items.appendModel(workspaces);
        items.appendModel(devices);
        shelfItems.appendModel(trashes);
    }

    Connections {
        target: applications
        onApplicationBecameUrgent: {
            if (main.autoScrolling) {
                main.stopAutoScrolling()
            }

            /* index does not need to be translated because we know that
               applications are always first in the list. */
            main.positionViewAtIndex(index, ListView.Center)
        }
    }
}