on xenial help sign in
CardHeader improvements depending on background. Also drop prices, they need to be reworked into attributes.
commit378050fe897f5732a607bfe29efbee75000e1370 authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 14 Mar 2014, 15:44 (13 years ago) parent37259c576213d3
4 files changed+79−82
qml/Dash/Card.qml+7 qml/Dash/CardHeader.qml+23−55 tests/qmltests/Dash/tst_Card.qml+49 tests/qmltests/Dash/tst_CardHeader.qml−27
qml/Dash/Card.qml+7
@@ -44,6 +44,8 @@ Item {
4444 anchors.fill: parent
4545 image: backgroundImage.source ? backgroundImage : null
4646
47+ property real luminance: 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b
48+
4749 property Image backgroundImage: Image {
4850 objectName: "backgroundImage"
4951 source: {
@@ -163,6 +165,9 @@ Item {
163165 titleWeight: components && components["subtitle"] ? Font.DemiBold : Font.Normal
164166
165167 opacity: showHeader ? 1 : 0
168+ inOverlay: template["overlay"] === true
169+ fontColor: inOverlay ? "white" : summary.color
170+ useMascotShape: !background.visible && !inOverlay
166171
167172 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
168173 }
@@ -183,5 +188,7 @@ Item {
183188 text: cardData && cardData["summary"] || ""
184189 height: text ? implicitHeight : 0
185190 fontSize: "small"
191+ // TODO karni: Change "grey" to Ubuntu.Components.Palette color once updated.
192+ color: background.visible && background.luminance < 0.7 ? "white" : "grey"
186193 }
187194}
qml/Dash/CardHeader.qml+23−55
@@ -22,9 +22,6 @@ Item {
2222 property alias mascot: mascotImage.source
2323 property alias title: titleLabel.text
2424 property alias subtitle: subtitleLabel.text
25− property alias price: priceLabel.text
26− property alias oldPrice: oldPriceLabel.text
27− property alias altPrice: altPriceLabel.text
2825
2926 property alias titleWeight: titleLabel.font.weight
3027
@@ -33,7 +30,11 @@ Item {
3330
3431 property alias headerAlignment: titleLabel.horizontalAlignment
3532
36− visible: mascotImage.status === Image.Ready || title || price
33+ property bool inOverlay: false
34+ property bool useMascotShape: true
35+ property color fontColor: Theme.palette.selected.backgroundText
36+
37+ visible: mascotImage.status === Image.Ready || title
3738 height: row.height > 0 ? row.height + row.margins * 2 : 0
3839
3940 Row {
@@ -42,13 +43,13 @@ Item {
4243
4344 property real margins: units.gu(1)
4445
46+ spacing: mascotShape.visible || mascotImage.visible || inOverlay ? margins : 0
4547 anchors {
4648 top: parent.top; left: parent.left; right: parent.right
4749 margins: margins
4850 leftMargin: spacing
4951 rightMargin: spacing
5052 }
51− spacing: mascotShape.visible || (template && template["overlay"]) ? margins : 0
5253
5354 UbuntuShape {
5455 id: mascotShape
@@ -57,17 +58,24 @@ Item {
5758 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
5859 width: units.gu(6)
5960 height: units.gu(5.625)
60− visible: image.status === Image.Ready
61+ visible: useMascotShape && image && image.status === Image.Ready
6162 readonly property int maxSize: Math.max(width, height)
6263
63− image: Image {
64− id: mascotImage
64+ image: useMascotShape ? mascotImage : null
65+ }
6566
66− sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
67− fillMode: Image.PreserveAspectCrop
68− horizontalAlignment: Image.AlignHCenter
69− verticalAlignment: Image.AlignVCenter
70− }
67+ Image {
68+ id: mascotImage
69+ objectName: "mascotImage"
70+
71+ width: source ? mascotShape.width : 0
72+ height: mascotShape.height
73+ visible: !useMascotShape && status === Image.Ready
74+
75+ sourceSize { width: mascotShape.maxSize; height: mascotShape.maxSize }
76+ fillMode: Image.PreserveAspectCrop
77+ horizontalAlignment: Image.AlignHCenter
78+ verticalAlignment: Image.AlignVCenter
7179 }
7280
7381 Column {
@@ -85,7 +93,7 @@ Item {
8593 maximumLineCount: 2
8694 fontSize: "small"
8795 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
88− color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
96+ color: fontColor
8997 }
9098
9199 Label {
@@ -97,47 +105,7 @@ Item {
97105 visible: titleLabel.text && text
98106 fontSize: "x-small"
99107 font.pixelSize: Math.round(FontUtils.sizeToPixels(fontSize) * fontScale)
100− color: template["overlay"] === true ? "white" : Theme.palette.selected.backgroundText
101− }
102−
103− Row {
104− id: prices
105− objectName: "prices"
106− anchors { left: parent.left; right: parent.right }
107−
108− property int labels: {
109− var labels = 1; // price always visible
110− if (oldPriceLabel.text !== "") labels += 1;
111− if (altPriceLabel.text !== "") labels += 1;
112− return labels;
113− }
114− property real labelWidth: width / labels
115−
116− Label {
117− id: priceLabel
118− width: parent.labelWidth
119− elide: Text.ElideRight
120− font.weight: Font.DemiBold
121− color: Theme.palette.selected.foreground
122− visible: text
123− }
124−
125− Label {
126− id: oldPriceLabel
127− objectName: "oldPriceLabel"
128− width: parent.labelWidth
129− elide: Text.ElideRight
130− horizontalAlignment: parent.labels === 3 ? Text.AlignHCenter : Text.AlignRight
131− visible: text
132− }
133−
134− Label {
135− id: altPriceLabel
136− width: parent.labelWidth
137− elide: Text.ElideRight
138− horizontalAlignment: Text.AlignRight
139− visible: text
140− }
108+ color: fontColor
141109 }
142110 }
143111 }
tests/qmltests/Dash/tst_Card.qml+49
@@ -427,5 +427,54 @@ Rectangle {
427427
428428 tryCompare(testCase.title.font, "weight", data.weight);
429429 }
430+
431+ function test_fontColor_data() {
432+ return [
433+ { tag: "#ffffff", dark: true },
434+ { tag: "#fdfdfd", dark: true },
435+ { tag: "#f9f9f9", dark: true },
436+ { tag: "#000000", dark: false },
437+ { tag: "#ef814c", dark: false },
438+ { tag: "#312f2c", dark: false },
439+ { tag: "#be332d", dark: false },
440+ { tag: "#52ace4", dark: false },
441+ { tag: "#3a5897", dark: false },
442+ { tag: "#1caeeb", dark: false },
443+ { tag: "#87c341", dark: false },
444+ { tag: "#50893b", dark: false },
445+ ];
446+ }
447+
448+ function test_fontColor(data) {
449+ selector.selectedIndex = 10;
450+
451+ background.color = data.tag;
452+
453+ var fontColor = data.dark ? "grey" : "white";
454+
455+ tryCompareFunction(function() { return Qt.colorEqual(summary.color, fontColor); }, true);
456+ tryCompareFunction(function() { return Qt.colorEqual(header.fontColor, fontColor); }, true);
457+ }
458+
459+ function test_mascotShape_data() {
460+ return [
461+ { tag: "Art and summary", shape: false, index: 0 },
462+ { tag: "No Summary", shape: true, index: 6 },
463+ { tag: "With background", shape: false, index: 10 },
464+ ];
465+ }
466+
467+ function test_mascotShape(data) {
468+ selector.selectedIndex = data.index;
469+
470+ var shape = findChild(card, "mascotShape");
471+ var image = findChild(card, "mascotImage");
472+
473+ verify(shape, "Could not find shape.");
474+ verify(image, "Could not find image.");
475+
476+ tryCompare(shape, "visible", data.shape);
477+ tryCompare(image, "visible", !data.shape);
478+ }
430479 }
431480}
tests/qmltests/Dash/tst_CardHeader.qml−27
@@ -46,7 +46,6 @@ Rectangle {
4646 property Item mascot: findChild(cardHeader, "mascotShape")
4747 property Item titleLabel: findChild(cardHeader, "titleLabel")
4848 property Item subtitleLabel: findChild(cardHeader, "subtitleLabel")
49− property Item prices: findChild(cardHeader, "prices")
5049 property Item oldPriceLabel: findChild(cardHeader, "oldPriceLabel")
5150 property Item outerRow: findChild(cardHeader, "outerRow")
5251 property Item column: findChild(cardHeader, "column")
@@ -55,7 +54,6 @@ Rectangle {
5554 verify(typeof testCase.mascot === "object", "Couldn't find mascot object.");
5655 verify(typeof testCase.titleLabel === "object", "Couldn't find titleLabel object.");
5756 verify(typeof testCase.subtitleLabel === "object", "Couldn't find subtitleLabel object.");
58− verify(typeof testCase.prices === "object", "Couldn't find prices object.");
5957 verify(typeof testCase.oldPriceLabel === "object", "Couldn't find oldPriceLabel object.");
6058 }
6159
@@ -63,9 +61,6 @@ Rectangle {
6361 cardHeader.mascot = "";
6462 cardHeader.title = "";
6563 cardHeader.subtitle = "";
66− cardHeader.price = "";
67− cardHeader.oldPrice = "";
68− cardHeader.altPrice = "";
6964 }
7065
7166 function test_mascot_data() {
@@ -96,28 +91,6 @@ Rectangle {
9691 tryCompare(cardHeader, "visible", data.visible);
9792 }
9893
99− function test_prices_data() {
100− return [
101− { tag: "Main", main: "$1.25", visible: true },
102− { tag: "Alt", alt: "€1.00", visible: false },
103− { tag: "Old", old: "€2.00", visible: false },
104− { tag: "Main and Alt", main: "$1.25", alt: "€1.00", visible: true },
105− { tag: "Main and Old", main: "$1.25", old: "$2.00", visible: true, oldAlign: Text.AlignRight },
106− { tag: "Alt and Old", alt: "€1.00", old: "$2.00", visible: false },
107− { tag: "All", main: "$1.25", alt: "€1.00", old: "$2.00", visible: true, oldAlign: Text.AlignHCenter },
108− ]
109− }
110−
111− function test_prices(data) {
112− cardHeader.price = data.main !== undefined ? data.main : "";
113− cardHeader.oldPrice = data.old !== undefined ? data.old : "";
114− cardHeader.altPrice = data.alt !== undefined ? data.alt : "";
115− tryCompare(cardHeader, "visible", data.visible);
116− if (data.hasOwnProperty("oldAlign")) {
117− compare(testCase.oldPriceLabel.horizontalAlignment, data.oldAlign, "Old price label is aligned wrong.")
118− }
119− }
120−
12194 function test_dimensions_data() {
12295 return [
12396 { tag: "Column width", object: column, width: cardHeader.width },