Merge lp:~unity-team/unity8/new-scopes-title-alignment into lp:~unity-team/unity8/new-scopes

Proposed by Michał Karnicki
Status: Superseded
Proposed branch: lp:~unity-team/unity8/new-scopes-title-alignment
Merge into: lp:~unity-team/unity8/new-scopes
Prerequisite: lp:~saviq/unity8/newscopes-card-tool
Diff against target: 315 lines (+156/-6)
6 files modified
qml/Dash/Card.qml (+65/-3)
qml/Dash/CardFilterGrid.qml (+2/-0)
qml/Dash/CardHeader.qml (+10/-1)
qml/Dash/CardTool.qml (+23/-1)
tests/qmltests/Dash/tst_Card.qml (+8/-0)
tests/qmltests/Dash/tst_CardTool.qml (+48/-1)
To merge this branch: bzr merge lp:~unity-team/unity8/new-scopes-title-alignment
Reviewer Review Type Date Requested Status
Michał Sawicz Needs Fixing
Review via email: mp+204677@code.launchpad.net

This proposal supersedes a proposal from 2014-02-04.

This proposal has been superseded by a proposal from 2014-02-07.

Description of the change

Title alignment.

Are there any related MPs required for this MP to build/function as expected? Please list.
 * The prerequisite.
Did you perform an exploratory manual test run of your code change and any related functionality?
 * Yes, used unity-scope-tool and tryCardTool. Tests pass.
If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
 * N/A
If you changed the UI, has there been a design review?
 * Yes, worked on this with Katie and updated spec.

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote :

make test fails with:
20/20 Test #20: timeformattertest ....................***Failed 0.02 sec

Revision history for this message
Michał Karnicki (karni) wrote :

LC_ALL=C make -C builddir test
100% pass

Revision history for this message
Michał Sawicz (saviq) wrote :

This is not just about title, after all price and rating alone should be centered, too?

review: Needs Fixing
Revision history for this message
Michał Karnicki (karni) wrote :

Title was critical for us, I'm happy to continue work in another branch if we can get this merged asap.

Revision history for this message
Michał Sawicz (saviq) wrote :

s/titleHorizontalAlignment/headerAlignment/, so that we don't have to rename it later when we apply it to other components.

=====

43 + verticalAlignment: Text.AlignVCenter

The Label has no height defined, so this doesn't do anything.

=====

55 + property var titleHorizontalAlignment: card.titleHorizontalAlignment
56 +
57 Card {
58 id: card
59 template: cardTool.template
60 @@ -110,6 +112,19 @@
61 width: cardTool.cardWidth || implicitWidth
62 height: cardTool.cardHeight || implicitHeight
63
64 + property var titleHorizontalAlignment: {
65 + var subtitle = components["subtitle"];
66 + var price = components["price"];
67 +
68 + var hasSubtitle = subtitle && (typeof subtitle === "string" || subtitle["field"])
69 + var hasPrice = price && (typeof price === "string" || subtitle["field"]);
70 +
71 + var isOnlyTextComponent = !hasSubtitle && !hasPrice;
72 + if (!isOnlyTextComponent) return Text.AlignLeft;
73 +
74 + return (template["card-layout"] === "horizontal") ? Text.AlignHCenter : Text.AlignLeft;
75 + }
76 +

Make it readonly, and just put the whole binding under CardTool, don't move it under Card.

=====

You also need to take summary into account.

review: Needs Fixing
595. By Michał Karnicki

/s/titleHorizontalAlignment/titleAlignment

596. By Michał Karnicki

Move titleAlignment from within card to CardTool.

597. By Michał Karnicki

Make titleAlignment readonly.

598. By Michał Karnicki

Merge prerequisite.

599. By Michał Karnicki

Merge new-scopes.

600. By Michał Karnicki

s/titleAlignment/headerAlignment

601. By Michał Karnicki

Fix CardTool tests.

Revision history for this message
Michał Karnicki (karni) wrote :

Card tests occasionally fail in test_card_size. Check out this paste:
http://paste.ubuntu.com/6888056/
uncomment red rectangle and see how implicitHeight does not shrink when Card size shrinks.

Revision history for this message
Michał Karnicki (karni) wrote :

What paste suggests appears in unity8-card-overlay so we'll get it in.

602. By Michał Sawicz

Merge trunk header-alignment.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/Dash/Card.qml'
2--- qml/Dash/Card.qml 2014-02-04 18:14:07 +0000
3+++ qml/Dash/Card.qml 2014-02-07 11:08:41 +0000
4@@ -23,8 +23,14 @@
5 property var components
6 property var cardData
7
8+ property alias fontScale: header.fontScale
9+ property alias headerAlignment: header.headerAlignment
10+ readonly property alias headerHeight: header.height
11+
12+ property bool showHeader: true
13+
14 implicitWidth: childrenRect.width
15- implicitHeight: childrenRect.height
16+ implicitHeight: summary.y + summary.height
17
18 UbuntuShape {
19 id: artShape
20@@ -58,21 +64,77 @@
21 }
22 }
23
24+ ShaderEffect {
25+ id: overlay
26+ anchors {
27+ left: artShape.left
28+ right: artShape.right
29+ bottom: artShape.bottom
30+ }
31+
32+ height: header.height
33+ opacity: header.opacity * 0.6
34+ visible: template && template["overlay"] && artShape.visible && artShape.image.status === Image.Ready || false
35+
36+ property var source: ShaderEffectSource {
37+ id: shaderSource
38+ sourceItem: artShape
39+ onVisibleChanged: if (visible) scheduleUpdate()
40+ live: false
41+ sourceRect: Qt.rect(0, artShape.height - overlay.height, artShape.width, overlay.height)
42+ }
43+
44+ vertexShader: "
45+ uniform highp mat4 qt_Matrix;
46+ attribute highp vec4 qt_Vertex;
47+ attribute highp vec2 qt_MultiTexCoord0;
48+ varying highp vec2 coord;
49+ void main() {
50+ coord = qt_MultiTexCoord0;
51+ gl_Position = qt_Matrix * qt_Vertex;
52+ }"
53+
54+ fragmentShader: "
55+ varying highp vec2 coord;
56+ uniform sampler2D source;
57+ uniform lowp float qt_Opacity;
58+ void main() {
59+ lowp vec4 tex = texture2D(source, coord);
60+ gl_FragColor = vec4(0, 0, 0, tex.a) * qt_Opacity;
61+ }"
62+ }
63+
64 CardHeader {
65 id: header
66 objectName: "cardHeader"
67 anchors {
68- top: template && template["card-layout"] === "horizontal" ? artShape.top : artShape.bottom
69- left: template && template["card-layout"] === "horizontal" ? artShape.right : parent.left
70+ top: {
71+ if (template) {
72+ if (template["overlay"]) return overlay.top;
73+ if (template["card-layout"] === "horizontal") return artShape.top;
74+ }
75+ return artShape.bottom;
76+ }
77+ left: {
78+ if (template) {
79+ if (!template["overlay"] && template["card-layout"] === "horizontal") return artShape.right;
80+ }
81+ return parent.left;
82+ }
83 right: parent.right
84 }
85
86 mascot: cardData && cardData["mascot"] || ""
87 title: cardData && cardData["title"] || ""
88 subtitle: cardData && cardData["subtitle"] || ""
89+
90+ opacity: showHeader ? 1 : 0
91+
92+ Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
93 }
94
95 Label {
96+ id: summary
97 objectName: "summaryLabel"
98 anchors { top: header.visible ? header.bottom : artShape.bottom; left: parent.left; right: parent.right }
99 wrapMode: Text.Wrap
100
101=== modified file 'qml/Dash/CardFilterGrid.qml'
102--- qml/Dash/CardFilterGrid.qml 2014-01-31 17:02:29 +0000
103+++ qml/Dash/CardFilterGrid.qml 2014-02-07 11:08:41 +0000
104@@ -45,6 +45,8 @@
105 template: genericFilterGrid.template
106 components: genericFilterGrid.components
107
108+ headerAlignment: cardTool.headerAlignment
109+
110 onClicked: genericFilterGrid.clicked(index, card.y)
111 onPressAndHold: genericFilterGrid.pressAndHold(index, card.y)
112 }
113
114=== modified file 'qml/Dash/CardHeader.qml'
115--- qml/Dash/CardHeader.qml 2014-02-04 18:14:07 +0000
116+++ qml/Dash/CardHeader.qml 2014-02-07 11:08:41 +0000
117@@ -26,6 +26,11 @@
118 property alias oldPrice: oldPriceLabel.text
119 property alias altPrice: altPriceLabel.text
120
121+ // FIXME: Saviq, used to scale fonts down in Carousel
122+ property real fontScale: 1.0
123+
124+ property alias headerAlignment: titleLabel.horizontalAlignment
125+
126 visible: mascotImage.status === Image.Ready || title || price
127 height: row.height > 0 ? row.height + row.margins * 2 : 0
128
129@@ -41,7 +46,7 @@
130 leftMargin: spacing
131 rightMargin: spacing
132 }
133- spacing: mascotShape.visible ? margins : 0
134+ spacing: mascotShape.visible || (template && template["overlay"]) ? margins : 0
135
136 UbuntuShape {
137 id: mascotShape
138@@ -77,6 +82,8 @@
139 wrapMode: Text.Wrap
140 maximumLineCount: 2
141 fontSize: "small"
142+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
143+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
144 }
145
146 Label {
147@@ -87,6 +94,8 @@
148 font.weight: Font.Light
149 visible: titleLabel.text && text
150 fontSize: "x-small"
151+ font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
152+ color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
153 }
154
155 Row {
156
157=== modified file 'qml/Dash/CardTool.qml'
158--- qml/Dash/CardTool.qml 2014-02-03 09:41:39 +0000
159+++ qml/Dash/CardTool.qml 2014-02-07 11:08:41 +0000
160@@ -100,10 +100,32 @@
161 }
162 }
163
164- readonly property QtObject priv: card
165+ /*!
166+ type:real \brief Height of the card's header.
167+ */
168+ readonly property alias headerHeight: card.headerHeight
169+
170+ /*!
171+ \brief Desired alignment of header components.
172+ */
173+ readonly property int headerAlignment: {
174+ var subtitle = components["subtitle"];
175+ var price = components["price"];
176+ var summary = components["summary"];
177+
178+ var hasSubtitle = subtitle && (typeof subtitle === "string" || subtitle["field"])
179+ var hasPrice = price && (typeof price === "string" || subtitle["field"]);
180+ var hasSummary = summary && (typeof summary === "string" || summary["field"])
181+
182+ var isOnlyTextComponent = !hasSubtitle && !hasPrice && !hasSummary;
183+ if (!isOnlyTextComponent) return Text.AlignLeft;
184+
185+ return (template["card-layout"] === "horizontal") ? Text.AlignHCenter : Text.AlignLeft;
186+ }
187
188 Card {
189 id: card
190+ objectName: "card"
191 template: cardTool.template
192 components: cardTool.components
193
194
195=== modified file 'tests/qmltests/Dash/tst_Card.qml'
196--- tests/qmltests/Dash/tst_Card.qml 2014-02-04 18:14:07 +0000
197+++ tests/qmltests/Dash/tst_Card.qml 2014-02-07 11:08:41 +0000
198@@ -74,6 +74,11 @@
199 "name": "Header title only",
200 "layout": { "components": { "title": "title" } }
201 },
202+ {
203+ "name": "Art, header, summary - overlaid",
204+ "layout": { "template": { "overlay": true },
205+ "components": JSON.parse(Helpers.fullMapping) }
206+ },
207 ]
208
209 CardTool {
210@@ -224,6 +229,7 @@
211 }
212
213 function test_card_size(data) {
214+ waitForRendering(card);
215 selector.selectedIndex = data.index;
216
217 if (data.hasOwnProperty("size")) {
218@@ -314,6 +320,8 @@
219 left: function() { return art.x }, index: 0 },
220 { tag: "Horizontal", top: function() { return art.y },
221 left: function() { return art.x + art.width }, index: 5 },
222+ { tag: "Overlay", top: function() { return art.y + art.height - header.height },
223+ left: function() { return art.x }, index: 9 },
224 ]
225 }
226
227
228=== modified file 'tests/qmltests/Dash/tst_CardTool.qml'
229--- tests/qmltests/Dash/tst_CardTool.qml 2014-01-31 16:23:32 +0000
230+++ tests/qmltests/Dash/tst_CardTool.qml 2014-02-07 11:08:41 +0000
231@@ -72,6 +72,22 @@
232 "name": "Art, header - portrait",
233 "layout": { "components": Helpers.update(JSON.parse(Helpers.fullMapping), { "art": {"aspect-ratio": 0.5, "summary": undefined }}) }
234 },
235+ {
236+ "name": "Title - vertical",
237+ "layout": { "template": { "card-layout": "vertical" }, "components": { "title": "title" } }
238+ },
239+ {
240+ "name": "Title - horizontal",
241+ "layout": { "template": { "card-layout": "horizontal" }, "components": { "title": "title" } }
242+ },
243+ {
244+ "name": "Title, subtitle - vertical",
245+ "layout": { "template": { "card-layout": "vertical" }, "components": { "title": "title", "subtitle": "subtitle" } }
246+ },
247+ {
248+ "name": "Title, price - horizontal",
249+ "layout": { "template": { "card-layout": "horizontal" }, "components": { "title": "title", "price": "price" } }
250+ },
251 ]
252
253 CardTool {
254@@ -121,6 +137,7 @@
255 height: cardTool.cardHeight || implicitHeight
256
257 clip: true
258+ headerAlignment: cardTool.headerAlignment
259
260 Rectangle {
261 anchors.fill: parent
262@@ -209,7 +226,7 @@
263 id: dataArea
264 anchors { left: parent.left; right: parent.right }
265 height: units.gu(25)
266- text: JSON.stringify(cardTool.priv.cardData, undefined, 2)
267+ text: JSON.stringify(testCase.internalCard.cardData, undefined, 2)
268 }
269
270 Label {
271@@ -239,8 +256,14 @@
272 id: testCase
273 name: "Card"
274
275+ property Card internalCard: findChild(cardTool, "card")
276+
277 when: windowShown
278
279+ function init() {
280+ verify(typeof testCase.internalCard === "object", "Couldn't find internal card object.");
281+ }
282+
283 function cleanup() {
284 selector.selectedIndex = -1;
285 layoutSelector.selectedIndex = -1;
286@@ -296,5 +319,29 @@
287 } else tryCompare(cardTool, "cardHeight", data.height);
288 }
289 }
290+
291+ function test_card_header_component_alignment_data() {
292+ return [
293+ { tag: "Title - vertical", component: "titleLabel", property: "headerAlignment",
294+ value: Text.AlignLeft, index: 11, layout_index: 0 },
295+ { tag: "Title - horizontal", component: "titleLabel", property: "headerAlignment",
296+ value: Text.AlignHCenter, index: 12, layout_index: 0},
297+ { tag: "Title, subtitle - vertical", component: "titleLabel", property: "headerAlignment",
298+ value: Text.AlignLeft, index: 13, layout_index: 0},
299+ { tag: "Title, price - horizontal", component: "titleLabel", property: "headerAlignment",
300+ value: Text.AlignLeft, index: 14, layout_index: 0},
301+ ]
302+ }
303+
304+ function test_card_header_component_alignment(data) {
305+ selector.selectedIndex = data.index;
306+ if (data.hasOwnProperty("layout_index")) {
307+ layoutSelector.selectedIndex = data.layout_index;
308+ }
309+
310+ if (data.hasOwnProperty("property")) {
311+ tryCompare(cardTool, data.property, data.value);
312+ }
313+ }
314 }
315 }

Subscribers

People subscribed via source and target branches

to all changes: