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

« back to all changes in this revision

Viewing changes to shell/hud/Hud.qml

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2012-03-05 09:52:30 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20120305095230-alpmktmmfnjs2t4b
Tags: 5.6.0-0ubuntu1
* New upstream release
  - [dash] [hud] If no active window, shell processes crashes (LP: #944724)
  - Long delay on session logout (LP: #812104)
  - apps/docs are not launched when performing a search on the home lens
    (LP: #932092)
  - [unity-2d] FF exception to add HUD to Unity2d (LP: #942045)
  - There's a gap between the launcher and the upper panel (LP: #942031)
  - Dash - Genre filter category in the Music Lens should use a 3 column
    layout (LP: #841902)
  - selected lens arrow should be on top instead of bottom (LP: #932291)
  - [launcher] pixel-perfection fixes, new assets, tile & pip position,
    border line & context menu position (LP: #936881)
  - Workspace switcher icon should not generate background from icon
    (LP: #939586)
  - No glow assets still needed X Y Z (LP: #934059)
* Revert an upstream commit to ensure that there is not regression with
  libunity-core 5.4 (change will be introduced again when unity 5.6 released)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of unity-2d
 
3
 *
 
4
 * Copyright 2012 Canonical Ltd.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 1.1
 
20
import Unity2d 1.0
 
21
import Effects 1.0
 
22
import "../common"
 
23
import "../common/utils.js" as Utils
 
24
 
 
25
FocusScope {
 
26
    id: hud
 
27
    objectName: "Hud"
 
28
    Accessible.name: "Hud"
 
29
 
 
30
    LayoutMirroring.enabled: Utils.isRightToLeft()
 
31
    LayoutMirroring.childrenInherit: true
 
32
 
 
33
    property bool active: false
 
34
 
 
35
    property int resultHeight: 42
 
36
 
 
37
    property bool animating: heightAnimation.running
 
38
 
 
39
    height: layout.childrenRect.height + layout.anchors.bottomMargin + 10
 
40
 
 
41
    Behavior on height {
 
42
        enabled: desktop.isCompositingManagerRunning
 
43
        PropertyAnimation { id: heightAnimation; duration: 150; easing.type: Easing.InOutQuad }
 
44
    }
 
45
 
 
46
    WindowInfo {
 
47
        id: activeWindow
 
48
        contentXid: declarativeView.lastFocusedWindow
 
49
    }
 
50
 
 
51
    SpreadMonitor {
 
52
        id: spread
 
53
        onShownChanged: active = false
 
54
    }
 
55
 
 
56
    onActiveChanged: {
 
57
        if (active) {
 
58
            declarativeView.forceActivateWindow()
 
59
            resultList.focus = true
 
60
        } else {
 
61
            hudModel.endSearch
 
62
            resultList.currentIndex = -1
 
63
        }
 
64
    }
 
65
 
 
66
    Connections {
 
67
        target: declarativeView
 
68
 
 
69
        onToggleHud: toggleHud()
 
70
    }
 
71
 
 
72
    Keys.onPressed: {
 
73
        if (event.key == Qt.Key_Escape) toggleHud()
 
74
    }
 
75
 
 
76
    function toggleHud() {
 
77
        if (spread.shown) return
 
78
        if (active) declarativeView.forceDeactivateWindow()
 
79
        active = !active
 
80
    }
 
81
 
 
82
    function executeResult(resultId) {
 
83
        declarativeView.forceDeactivateWindow()
 
84
        hudModel.executeResult(resultId)
 
85
        active = false
 
86
    }
 
87
 
 
88
    property variant hudModel: Hud {}
 
89
 
 
90
    Background {
 
91
        id: background
 
92
 
 
93
        anchors.fill: parent
 
94
 
 
95
        active: hud.active
 
96
    }
 
97
 
 
98
    Item {
 
99
        id: layout
 
100
 
 
101
        anchors.fill: parent
 
102
 
 
103
        /* Margins so content does not overlap with the background border */
 
104
        anchors.bottomMargin: background.bottomBorderThickness
 
105
        anchors.rightMargin: background.rightBorderThickness
 
106
 
 
107
        clip: true
 
108
 
 
109
        Image {
 
110
            id: panelBorder
 
111
 
 
112
            height: 1
 
113
            anchors.top: parent.top
 
114
            anchors.left: parent.left
 
115
            anchors.leftMargin: tile.width
 
116
            anchors.right: parent.right
 
117
            source: "../common/artwork/panel_border.png"
 
118
            fillMode: Image.Stretch
 
119
        }
 
120
 
 
121
        Item {
 
122
            id: tile
 
123
 
 
124
            anchors.left: parent.left
 
125
            anchors.top: parent.top
 
126
            width: 65
 
127
 
 
128
            Image {
 
129
                id: pip
 
130
 
 
131
                anchors.verticalCenter: iconTile.verticalCenter
 
132
                anchors.horizontalCenterOffset: -1
 
133
                anchors.left: parent.left
 
134
                mirror: Utils.isRightToLeft()
 
135
 
 
136
                source: "image://blended/%1color=%2alpha=%3"
 
137
                        .arg("launcher/artwork/launcher_arrow_ltr.png")
 
138
                        .arg("lightgrey").arg(1.0)
 
139
            }
 
140
 
 
141
            IconTile {
 
142
                id: iconTile
 
143
 
 
144
                anchors.top: parent.top
 
145
                anchors.topMargin: 5
 
146
                anchors.left: parent.left
 
147
                anchors.leftMargin: 5
 
148
                width: 54
 
149
                height: 54
 
150
 
 
151
                source: (resultList.currentItem != null && resultList.count > 0)
 
152
                        ? "image://icons/" + resultList.currentItem.icon
 
153
                        : (activeWindow.icon
 
154
                           ? "image://icons/" + activeWindow.icon
 
155
                           : "image://icons/unknown")
 
156
            }
 
157
        }
 
158
 
 
159
        /* Unhandled keys will always be forwarded to the search bar. That way
 
160
           the user can type and search from anywhere in the interface without
 
161
           necessarily focusing the search bar first. */
 
162
        Keys.forwardTo: [searchEntry]
 
163
 
 
164
        Rectangle {
 
165
            id: container
 
166
 
 
167
            anchors.top: parent.top
 
168
            anchors.topMargin: 11
 
169
            anchors.left: tile.right
 
170
            anchors.leftMargin: 10
 
171
            anchors.right: parent.right
 
172
            anchors.rightMargin: 10
 
173
            height: childrenRect.height
 
174
 
 
175
            border.color: "#21ffffff" // 80% opaque
 
176
            border.width: 1
 
177
            color: "transparent"
 
178
            radius: 7
 
179
            smooth: true
 
180
 
 
181
            SearchEntry {
 
182
                id: searchEntry
 
183
 
 
184
                anchors.top: parent.top
 
185
                anchors.left: parent.left
 
186
                anchors.right: parent.right
 
187
                height: 42
 
188
 
 
189
                opacity: 1
 
190
 
 
191
                active: hud.active
 
192
                placeHolderText: u2d.tr("Type your Command")
 
193
 
 
194
                onSearchQueryChanged: {
 
195
                    hudModel.searchQuery = searchQuery
 
196
                    resultList.currentIndex = 0
 
197
                }
 
198
                onActivateFirstResult: executeResult(0)
 
199
            }
 
200
 
 
201
            ListView {
 
202
                id: resultList
 
203
 
 
204
                focus: true
 
205
 
 
206
                Accessible.name: "result list"
 
207
 
 
208
                model: hudModel
 
209
 
 
210
                anchors.top: searchEntry.bottom
 
211
                anchors.left: parent.left
 
212
                anchors.right: parent.right
 
213
                height: count * resultHeight
 
214
 
 
215
                boundsBehavior: ListView.StopAtBounds
 
216
 
 
217
                delegate: ResultItem {
 
218
                    height: resultHeight
 
219
                    width: ListView.view.width
 
220
 
 
221
                    icon: iconName /* expose this property for tile */
 
222
 
 
223
                    onClicked: executeResult(resultId)
 
224
                }
 
225
            }
 
226
        }
 
227
    }
 
228
}