Merge lp:~gerboland/unity-2d/dash-lenses into lp:unity-2d/3.0

Proposed by Gerry Boland
Status: Superseded
Proposed branch: lp:~gerboland/unity-2d/dash-lenses
Merge into: lp:unity-2d/3.0
Diff against target: 368 lines (+230/-21)
7 files modified
launcher/Launcher.qml (+0/-4)
places/Home.qml (+1/-1)
places/HomeShortcuts.qml (+7/-7)
places/LensBar.qml (+114/-0)
places/LensButton.qml (+83/-0)
places/app/dashdeclarativeview.cpp (+1/-1)
places/dash.qml (+24/-8)
To merge this branch: bzr merge lp:~gerboland/unity-2d/dash-lenses
Reviewer Review Type Date Requested Status
Florian Boucault (community) Approve
Review via email: mp+71065@code.launchpad.net

This proposal has been superseded by a proposal from 2011-08-11.

Description of the change

[dash] Add Lens Bar to Dash. Remove it from Launcher and adjust sizes to fit.

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

Functionally, everything checks out!

review: Approve (functional)
Revision history for this message
Florian Boucault (fboucault) wrote :

places/LensBar.qml:

import Qt 4.7

should be:

import QtQuick 1.0

review: Needs Fixing (code)
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml, please remove the:

[...] /* required for drag’n’drop handling */

Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml:

    /* Lens Bar rectangle */
    Rectangle {
        id: lensBar

[...]

Don't give it for id 'lensBar' as the whole component's class is LensBar which could lead to confusion. Use 'background' instead for example.
The comment above is not very helpful. Drop it if the id is explicit enough.

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml:

    Rectangle {
        id: lensBar
        anchors.top: parent.top
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        width: parent.width
[...]

could be replaced by:

anchors.fill: parent

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/dash.qml:

[...]
        LensBar {
[...]
            anchors.left: parent.left
            anchors.right: parent.right
            width: parent.width

either set the left and right anchors or the width, not both. Using anchors is more efficient.

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

General note, I like having the id of the component as the first line and then leaving a blank line afterwards.

Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml:

Instead of using a ListView inside the Row, just use a Repeater. It will make things easier and simplify your keyboard navigation code that will then become generic.

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

Consistency in styling comments would be nice:

    /* BLA BLA */
    // BLA BLA
    //BLA BLA

I usually just use the first form.

Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml:

        ListView {
            id: lensList
[...]
            orientation: "Horizontal"
[...]

That code is likely to go away but note that it's probably better to use the enum value ListView.Horizontal instead of a string "Horizontal".

Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensBar.qml:

Please move up the activateLens to dash.qml, rename it to activatePlaceEntry and factor the code between it and its sibling "function activatePlaceEntry(fileName, groupName, section)"

It would look like:
    function activatePlaceEntry(fileName, groupName, section) {
        var placeEntryModel = places.findPlaceEntry(fileName, groupName)
        if (placeEntryModel == null) {
            console.log("No match for place: %1 [Entry:%2]".arg(fileName).arg(groupName))
            return
        }
        activatePlaceEntry(placeEntryModel, section)
    }

    function activatePlaceEntry(placeEntry, section=0) {
         CODE OF THE FORMER activatePlaceEntry
    }

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensButton.qml:

    property alias iconSourceSize: icon.sourceSize

is not used.

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensButton.qml:

'iconWidth' is used in a couple of places but not defined in that file thus breaking encapsulation. Same for 'lensBar'.

Solution:
- for the root element: don't set the width and height for the root element in this file but in LensBar.qml
- for icon: use parent.height

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensButton.qml:

    Rectangle {
        width: 32
        height: parent.height
[...]

hardcoded 32 should probably be parent.width, or better yet, replace the all thing with anchors.fill: parent

Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensButton.qml:

    Image {
        id: indicator
        width: 5
        height: 9

maybe use sourceSize.width and sourceSize.height instead if it works?

[...]

        y: 37
        anchors.horizontalCenter: parent.horizontalCenter

Setting it centered horizontally conflicts with hardcoding its y coordinate.

review: Needs Fixing
Revision history for this message
Florian Boucault (fboucault) wrote :

In places/LensButton.qml:

    // Lens icon supplied is of size 48x48. This is too much for the 44pixels high
    // lensBar. However much of the icon is transparent so we effectively crop it to 32x32.

I am not sure I am a big fan of this. Let's discuss it.

lp:~gerboland/unity-2d/dash-lenses updated
676. By Gerry Boland

Fix lensbar imports

677. By Gerry Boland

Fix layout issues and coment style

678. By Gerry Boland

Refactor activatePlaceEntry

679. By Gerry Boland

Another layout fix to LensBar in dash

680. By Gerry Boland

Fix keyboard navigation when Repeater used

681. By Gerry Boland

Revert rename of activePlaceEntryFromFile

682. By Gerry Boland

Fix iconWidth and layout

Revision history for this message
Florian Boucault (fboucault) wrote :

Everything checks out now. Thanks

review: Approve

Unmerged revisions

682. By Gerry Boland

Fix iconWidth and layout

681. By Gerry Boland

Revert rename of activePlaceEntryFromFile

680. By Gerry Boland

Fix keyboard navigation when Repeater used

679. By Gerry Boland

Another layout fix to LensBar in dash

678. By Gerry Boland

Refactor activatePlaceEntry

677. By Gerry Boland

Fix layout issues and coment style

676. By Gerry Boland

Fix lensbar imports

675. By Gerry Boland

[dash] Home Lens is special case, and for the moment requires own icon to be supplied.

674. By Gerry Boland

[launcher] Remove Lenses from Launcher, as they now exist in the Dash.

673. By Gerry Boland

[dash] With new LensBar in the dash, the Home Shortcuts layout needs to be adjusted to fit correctly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/Launcher.qml'
2--- launcher/Launcher.qml 2011-08-01 11:58:35 +0000
3+++ launcher/Launcher.qml 2011-08-10 19:03:55 +0000
4@@ -105,10 +105,6 @@
5 id: applications
6 }
7
8- LauncherPlacesList {
9- id: places
10- }
11-
12 LauncherDevicesList {
13 id: devices
14 }
15
16=== modified file 'places/Home.qml'
17--- places/Home.qml 2011-08-10 10:01:52 +0000
18+++ places/Home.qml 2011-08-10 19:03:55 +0000
19@@ -135,7 +135,7 @@
20 anchors.verticalCenter: parent.verticalCenter
21
22 width: 888
23- height: 466
24+ height: 436
25
26 Rectangle {
27 anchors.fill: parent
28
29=== modified file 'places/HomeShortcuts.qml'
30--- places/HomeShortcuts.qml 2011-08-10 00:22:07 +0000
31+++ places/HomeShortcuts.qml 2011-08-10 19:03:55 +0000
32@@ -21,11 +21,11 @@
33
34 Grid {
35 anchors.fill: parent
36- anchors.topMargin: 26
37+ anchors.topMargin: 21
38 anchors.bottomMargin: 35
39- anchors.leftMargin: 32
40+ anchors.leftMargin: 46
41 anchors.rightMargin: 32
42- spacing: 61
43+ spacing: 51
44 columns: 4
45 rows: 2
46
47@@ -55,25 +55,25 @@
48 focus: true
49 label: u2d.tr("Media Apps")
50 icon: "artwork/find_media_apps.png"
51- onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 9)
52+ onClicked: activatePlaceEntryFromFile("/usr/share/unity/places/applications.place", "Files", 9)
53 }
54
55 HomeButton {
56 label: u2d.tr("Internet Apps")
57 icon: "artwork/find_internet_apps.png"
58- onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 8)
59+ onClicked: activatePlaceEntryFromFile("/usr/share/unity/places/applications.place", "Files", 8)
60 }
61
62 HomeButton {
63 label: u2d.tr("More Apps")
64 icon: "artwork/find_more_apps.png"
65- onClicked: activatePlaceEntry("/usr/share/unity/places/applications.place", "Files", 0)
66+ onClicked: activatePlaceEntryFromFile("/usr/share/unity/places/applications.place", "Files", 0)
67 }
68
69 HomeButton {
70 label: u2d.tr("Find Files")
71 icon: "artwork/find_files.png"
72- onClicked: activatePlaceEntry("/usr/share/unity/places/files.place", "Files", 0)
73+ onClicked: activatePlaceEntryFromFile("/usr/share/unity/places/files.place", "Files", 0)
74 }
75
76 /* FIXME: use user's preferred applications instead of hardcoding them */
77
78=== added file 'places/LensBar.qml'
79--- places/LensBar.qml 1970-01-01 00:00:00 +0000
80+++ places/LensBar.qml 2011-08-10 19:03:55 +0000
81@@ -0,0 +1,114 @@
82+/*
83+ * This file is part of unity-2d
84+ *
85+ * Copyright 2011 Canonical Ltd.
86+ *
87+ * This program is free software; you can redistribute it and/or modify
88+ * it under the terms of the GNU General Public License as published by
89+ * the Free Software Foundation; version 3.
90+ *
91+ * This program is distributed in the hope that it will be useful,
92+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
93+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94+ * GNU General Public License for more details.
95+ *
96+ * You should have received a copy of the GNU General Public License
97+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
98+ */
99+
100+import QtQuick 1.0
101+import Unity2d 1.0
102+
103+FocusScope {
104+ /* declare width & spacing of icons as required for layout calculations */
105+ property int iconWidth: 32
106+ property int iconSpacing: 28
107+
108+ property variant lenses: SortFilterProxyModel {
109+ id: visiblePlaces
110+ model: places
111+ dynamicSortFilter: true
112+
113+ filterRole: Place.RoleShowEntry
114+ filterRegExp: RegExp("^true$")
115+ }
116+
117+ Rectangle {
118+ id: background
119+
120+ anchors.fill: parent
121+ color: "black"
122+ opacity: 0.22
123+ }
124+
125+ /* LensBar contains a row of LensButtons */
126+ Row {
127+ id: lensContainer
128+
129+ anchors.horizontalCenter: background.horizontalCenter
130+ anchors.top: background.top
131+ anchors.bottom: background.bottom
132+ spacing: iconSpacing
133+
134+ Keys.onPressed: if (handleKeyPress(event.key)) event.accepted = true
135+
136+ /* The Home lens is unfortunately not supplied by the "lenses" list
137+ This causes the keyboard navigation logic to be messy */
138+ property int currentIndex: 0
139+
140+ function selectChild(index) {
141+ var child = lensContainer.childFromIndex(index)
142+ if (child != undefined) {
143+ child.focus = true
144+ currentIndex = index
145+ return true
146+ } else {
147+ return false
148+ }
149+ }
150+
151+ function handleKeyPress(key) {
152+ switch (key) {
153+ case Qt.Key_Right:
154+ return selectChild(currentIndex+1)
155+ case Qt.Key_Left:
156+ return selectChild(currentIndex-1)
157+ }
158+ }
159+
160+ function childFromIndex(index) {
161+ var indexInChildren = 0
162+ for(var i=0; i<children.length; i++) {
163+ if (children[i] != repeater) {
164+ if (indexInChildren == index) return children[i]
165+ indexInChildren++
166+ }
167+ }
168+ return undefined
169+ }
170+
171+ /* Need to manually include the Home lens */
172+ LensButton {
173+ id: homeLens
174+
175+ focus: true
176+ icon: "artwork/home.png"
177+ onClicked: activateHome()
178+ active: ( dashView.activePlaceEntry == "" )
179+ width: iconWidth
180+ }
181+
182+ /* Now fetch all other lenses and display */
183+ Repeater{
184+ id: repeater
185+
186+ model: lenses
187+ delegate: LensButton {
188+ icon: item.icon
189+ active: item.active
190+ onClicked: activatePlaceEntry(item)
191+ width: iconWidth
192+ }
193+ }
194+ }
195+}
196
197=== added file 'places/LensButton.qml'
198--- places/LensButton.qml 1970-01-01 00:00:00 +0000
199+++ places/LensButton.qml 2011-08-10 19:03:55 +0000
200@@ -0,0 +1,83 @@
201+/*
202+ * This file is part of unity-2d
203+ *
204+ * Copyright 2010-2011 Canonical Ltd.
205+ *
206+ * This program is free software; you can redistribute it and/or modify
207+ * it under the terms of the GNU General Public License as published by
208+ * the Free Software Foundation; version 3.
209+ *
210+ * This program is distributed in the hope that it will be useful,
211+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
213+ * GNU General Public License for more details.
214+ *
215+ * You should have received a copy of the GNU General Public License
216+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
217+ */
218+
219+import QtQuick 1.0
220+import Effects 1.0
221+
222+/* This component represents a single "lens" in the dash and an active
223+ * indicator icon positioned above it if necessary.
224+ */
225+AbstractButton {
226+ property alias icon: icon.source
227+ property bool active: false
228+
229+ id: lensButton
230+
231+ anchors.top: parent.top
232+ anchors.bottom: parent.bottom
233+
234+ effect: DropShadow {
235+ blurRadius: 8
236+ color: "white"
237+ offset.x: 0
238+ offset.y: 0
239+ enabled: ( lensButton.state == "selected" || active )
240+ }
241+
242+ Rectangle {
243+ anchors.fill: parent
244+ anchors.topMargin: 7
245+ anchors.bottomMargin: 7
246+
247+ border.color: "white"
248+ border.width: 1
249+ color: "transparent"
250+ radius: 2
251+ visible: ( parent.state == "selected" )
252+ }
253+
254+ /* Lens icon supplied is of size 48x48. This is too much for the 44pixels high
255+ lensBar. However much of the icon is transparent so we effectively crop it to 32x32. */
256+ Image {
257+ id: icon
258+
259+ height: iconWidth
260+ fillMode: Image.PreserveAspectCrop
261+ clip: true
262+
263+ anchors.horizontalCenter: parent.horizontalCenter
264+ anchors.centerIn: parent
265+
266+ opacity: ( parent.state == "mouseOver" || parent.state == "pressed" || active ) ? 1.0 : 0.57
267+ }
268+
269+ /* Indicator arrow to show Lens active */
270+ Image {
271+ id: indicator
272+ source: "artwork/arrow.png"
273+
274+ width: sourceSize.width
275+ height: sourceSize.height
276+ anchors.bottomMargin: (width-height)/2 /* Correct for rotation */
277+ anchors.bottom: parent.bottom
278+ anchors.horizontalCenter: parent.horizontalCenter
279+
280+ rotation: -90
281+ visible: active
282+ }
283+}
284
285=== modified file 'places/app/dashdeclarativeview.cpp'
286--- places/app/dashdeclarativeview.cpp 2011-08-09 14:32:13 +0000
287+++ places/app/dashdeclarativeview.cpp 2011-08-10 19:03:55 +0000
288@@ -238,7 +238,7 @@
289 DashDeclarativeView::activatePlaceEntry(const QString& file, const QString& entry, const int section)
290 {
291 QGraphicsObject* dash = rootObject();
292- QMetaObject::invokeMethod(dash, "activatePlaceEntry", Qt::AutoConnection,
293+ QMetaObject::invokeMethod(dash, "activatePlaceEntryFromFile", Qt::AutoConnection,
294 Q_ARG(QVariant, QVariant::fromValue(file)),
295 Q_ARG(QVariant, QVariant::fromValue(entry)),
296 Q_ARG(QVariant, QVariant::fromValue(section)));
297
298=== added file 'places/artwork/home.png'
299Binary files places/artwork/home.png 1970-01-01 00:00:00 +0000 and places/artwork/home.png 2011-08-10 19:03:55 +0000 differ
300=== modified file 'places/dash.qml'
301--- places/dash.qml 2011-08-10 00:10:39 +0000
302+++ places/dash.qml 2011-08-10 19:03:55 +0000
303@@ -64,25 +64,28 @@
304 currentPage.visible = true
305 }
306
307- function activatePlaceEntry(fileName, groupName, section) {
308+ function activatePlaceEntryFromFile(fileName, groupName, section) {
309 var placeEntryModel = places.findPlaceEntry(fileName, groupName)
310 if (placeEntryModel == null) {
311 console.log("No match for place: %1 [Entry:%2]".arg(fileName).arg(groupName))
312 return
313 }
314
315+ activatePlaceEntry( placeEntryModel, section)
316+ }
317+
318+ function activatePlaceEntry( place, section ) {
319 /* FIXME: PlaceEntry.SetActiveSection needs to be called after
320 PlaceEntry.SetActive in order for it to have an effect.
321- This is likely a bug in the place daemons.
322- */
323- placeEntryModel.active = true
324- placeEntryModel.activeSection = section
325+ This is likely a bug in the place daemons. */
326+ place.active = true
327+ place.activeSection = ( section != undefined ) ? section : 0
328 pageLoader.source = "PlaceEntryView.qml"
329 /* Take advantage of the fact that the loaded qml is local and setting
330 the source loads it immediately making pageLoader.item valid */
331- pageLoader.item.model = placeEntryModel
332+ pageLoader.item.model = place
333 activatePage(pageLoader.item)
334- dashView.activePlaceEntry = placeEntryModel.dbusObjectPath
335+ dashView.activePlaceEntry = place.dbusObjectPath
336 }
337
338 function activateHome() {
339@@ -221,15 +224,28 @@
340 */
341 KeyNavigation.right: refine_search.visible && !refine_search.folded ? refine_search : pageLoader
342 KeyNavigation.up: search_entry
343+ KeyNavigation.down: lensBar
344
345 anchors.top: search_entry.bottom
346 anchors.topMargin: 2
347- anchors.bottom: parent.bottom
348+ anchors.bottom: lensBar.top
349 anchors.left: parent.left
350 anchors.right: !refine_search.visible || refine_search.folded ? parent.right : refine_search.left
351 anchors.rightMargin: !refine_search.visible || refine_search.folded ? 0 : 15
352 onLoaded: item.focus = true
353 }
354+
355+ LensBar {
356+ id: lensBar
357+
358+ KeyNavigation.up: pageLoader
359+
360+ anchors.bottom: parent.bottom
361+ anchors.left: parent.left
362+ anchors.right: parent.right
363+ height: 44
364+ visible: dashView.expanded
365+ }
366 }
367
368 Button {

Subscribers

People subscribed via source and target branches