on xenial help sign in
Only create an image if we have one
2de1a6fAlbert Astals
qml/Dash/CardHeader.qml+21−17
@@ -19,7 +19,7 @@ import Ubuntu.Components 0.1
19
19
20Item {
20Item {
21 id: root
21 id: root
22− property alias mascot: mascotImage.source
22+ property var mascot
23 property alias title: titleLabel.text
23 property alias title: titleLabel.text
24 property var subtitle
24 property var subtitle
25
25
@@ -35,7 +35,7 @@ Item {
35 property bool useMascotShape: true
35 property bool useMascotShape: true
36 property color fontColor: Theme.palette.selected.backgroundText
36 property color fontColor: Theme.palette.selected.backgroundText
37
37
38− visible: mascotImage.status === Image.Ready || title
38+ visible: mascot || title
39 implicitHeight: row.height > 0 ? row.height + row.margins * 2 : 0
39 implicitHeight: row.height > 0 ? row.height + row.margins * 2 : 0
40
40
41 Row {
41 Row {
@@ -44,7 +44,7 @@ Item {
44
44
45 property real margins: units.gu(1)
45 property real margins: units.gu(1)
46
46
47− spacing: mascotShapeLoader.active || mascotImage.visible || inOverlay ? margins : 0
47+ spacing: mascotShapeLoader.active || mascotImageLoader.active || inOverlay ? margins : 0
48 anchors {
48 anchors {
49 top: parent.top; left: parent.left; right: parent.right
49 top: parent.top; left: parent.left; right: parent.right
50 margins: margins
50 margins: margins
@@ -56,7 +56,7 @@ Item {
56 id: mascotShapeLoader
56 id: mascotShapeLoader
57 objectName: "mascotShapeLoader"
57 objectName: "mascotShapeLoader"
58
58
59− active: useMascotShape && mascotImage && mascotImage.status === Image.Ready
59+ active: useMascotShape && mascotImageLoader.item && mascotImageLoader.item.status === Image.Ready
60 visible: active
60 visible: active
61 anchors.verticalCenter: parent.verticalCenter
61 anchors.verticalCenter: parent.verticalCenter
62 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
62 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
@@ -65,23 +65,27 @@ Item {
65 readonly property int maxSize: Math.max(width, height) * 4
65 readonly property int maxSize: Math.max(width, height) * 4
66
66
67 sourceComponent: UbuntuShape {
67 sourceComponent: UbuntuShape {
68− image: useMascotShape ? mascotImage : null
68+ image: mascotImageLoader.item
69 }
69 }
70 }
70 }
71
71
72− Image {
72+ Loader {
73− id: mascotImage
73+ id: mascotImageLoader
74− objectName: "mascotImage"
74+ active: root.mascot
75−
76− width: source ? mascotShapeLoader.width : 0
77− height: mascotShapeLoader.height
78 anchors.verticalCenter: parent.verticalCenter
75 anchors.verticalCenter: parent.verticalCenter
76+ sourceComponent: Image {
77+ objectName: "mascotImage"
78+
79+ source: root.mascot
80+ width: source ? mascotShapeLoader.width : 0
81+ height: mascotShapeLoader.height
79− visible: !useMascotShape && status === Image.Ready
82+ visible: !useMascotShape && status === Image.Ready
80−
83+
81− sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
84+ sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
82− fillMode: Image.PreserveAspectCrop
85+ fillMode: Image.PreserveAspectCrop
83− horizontalAlignment: Image.AlignHCenter
86+ horizontalAlignment: Image.AlignHCenter
84− verticalAlignment: Image.AlignVCenter
87+ verticalAlignment: Image.AlignVCenter
88+ }
85 }
89 }
86
90
87 Column {
91 Column {
tests/qmltests/Dash/tst_Card.qml+1−1
@@ -207,7 +207,7 @@ Rectangle {
207
207
208 function test_header_binding_data() {
208 function test_header_binding_data() {
209 return [
209 return [
210− { tag: "Mascot", property: "mascot", value: Qt.resolvedUrl("artwork/avatar.png"), index: 0 },
210+ { tag: "Mascot", property: "mascot", value: "../../tests/qmltests/Dash/artwork/avatar.png", index: 0 },
211 { tag: "Title", property: "title", value: "foo", index: 0 },
211 { tag: "Title", property: "title", value: "foo", index: 0 },
212 { tag: "Subtitle", property: "subtitle", value: "bar", index: 0 },
212 { tag: "Subtitle", property: "subtitle", value: "bar", index: 0 },
213 ];
213 ];
tests/qmltests/Dash/tst_CardBenchmark.qml+8−4
@@ -36,13 +36,17 @@ Rectangle {
36 "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
36 "summary": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
37 }'
37 }'
38
38
39−// property string artCardModel: '{ "components": { "art": "art" } }'
39+// property string cardModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle", "mascot": "mascot", "summary": "summary" } }'
40+// property string cardModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle", "mascot": "mascot" } }'
40− property string artCardModel: '{ "components": { "art": "art", "title": "title" } }'
41+ property string cardModel: '{ "components": { "title": "title", "art": "art", "subtitle": "subtitle" } }'
42+// property string cardModel: '{ "components": { "title": "title", "art": "art" } }'
43+// property string cardModel: '{ "components": { "art": "art" } }'
44+// property string cardModel: '{ "components": { "title": "title" } }'
41
45
42 CardTool {
46 CardTool {
43 id: cardTool
47 id: cardTool
44− template: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(artCardModel))['template'];
48+ template: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(cardModel))['template'];
45− components: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(artCardModel))['components'];
49+ components: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(cardModel))['components'];
46 viewWidth: units.gu(48)
50 viewWidth: units.gu(48)
47 }
51 }
48
52