on xenial help sign in
Only create an image if we have one
commit2de1a6fff46031f5ef05d03d39891cef43eb07e5 authorAlbert Astals <albert.astals@canonical.com> dateTue 1 Apr 2014, 12:34 (13 years ago) parent57e3f5e
3 files changed+30−22
qml/Dash/CardHeader.qml+21−17 tests/qmltests/Dash/tst_Card.qml+1−1 tests/qmltests/Dash/tst_CardBenchmark.qml+8−4
qml/Dash/CardHeader.qml+21−17
@@ -19,7 +19,7 @@ import Ubuntu.Components 0.1
1919
2020Item {
2121 id: root
22− property alias mascot: mascotImage.source
22+ property var mascot
2323 property alias title: titleLabel.text
2424 property var subtitle
2525
@@ -35,7 +35,7 @@ Item {
3535 property bool useMascotShape: true
3636 property color fontColor: Theme.palette.selected.backgroundText
3737
38− visible: mascotImage.status === Image.Ready || title
38+ visible: mascot || title
3939 implicitHeight: row.height > 0 ? row.height + row.margins * 2 : 0
4040
4141 Row {
@@ -44,7 +44,7 @@ Item {
4444
4545 property real margins: units.gu(1)
4646
47− spacing: mascotShapeLoader.active || mascotImage.visible || inOverlay ? margins : 0
47+ spacing: mascotShapeLoader.active || mascotImageLoader.active || inOverlay ? margins : 0
4848 anchors {
4949 top: parent.top; left: parent.left; right: parent.right
5050 margins: margins
@@ -56,7 +56,7 @@ Item {
5656 id: mascotShapeLoader
5757 objectName: "mascotShapeLoader"
5858
59− active: useMascotShape && mascotImage && mascotImage.status === Image.Ready
59+ active: useMascotShape && mascotImageLoader.item && mascotImageLoader.item.status === Image.Ready
6060 visible: active
6161 anchors.verticalCenter: parent.verticalCenter
6262 // TODO karni: Icon aspect-ratio is 8:7.5. Revisit these values to avoid fraction of pixels.
@@ -65,23 +65,27 @@ Item {
6565 readonly property int maxSize: Math.max(width, height) * 4
6666
6767 sourceComponent: UbuntuShape {
68− image: useMascotShape ? mascotImage : null
68+ image: mascotImageLoader.item
6969 }
7070 }
7171
72− Image {
73− id: mascotImage
74− objectName: "mascotImage"
75−
76− width: source ? mascotShapeLoader.width : 0
77− height: mascotShapeLoader.height
72+ Loader {
73+ id: mascotImageLoader
74+ active: root.mascot
7875 anchors.verticalCenter: parent.verticalCenter
79− visible: !useMascotShape && status === Image.Ready
80−
81− sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
82− fillMode: Image.PreserveAspectCrop
83− horizontalAlignment: Image.AlignHCenter
84− verticalAlignment: Image.AlignVCenter
76+ sourceComponent: Image {
77+ objectName: "mascotImage"
78+
79+ source: root.mascot
80+ width: source ? mascotShapeLoader.width : 0
81+ height: mascotShapeLoader.height
82+ visible: !useMascotShape && status === Image.Ready
83+
84+ sourceSize { width: mascotShapeLoader.maxSize; height: mascotShapeLoader.maxSize }
85+ fillMode: Image.PreserveAspectCrop
86+ horizontalAlignment: Image.AlignHCenter
87+ verticalAlignment: Image.AlignVCenter
88+ }
8589 }
8690
8791 Column {
tests/qmltests/Dash/tst_Card.qml+1−1
@@ -207,7 +207,7 @@ Rectangle {
207207
208208 function test_header_binding_data() {
209209 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 },
211211 { tag: "Title", property: "title", value: "foo", index: 0 },
212212 { tag: "Subtitle", property: "subtitle", value: "bar", index: 0 },
213213 ];
tests/qmltests/Dash/tst_CardBenchmark.qml+8−4
@@ -36,13 +36,17 @@ Rectangle {
3636 "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."
3737 }'
3838
39−// property string artCardModel: '{ "components": { "art": "art" } }'
40− property string artCardModel: '{ "components": { "art": "art", "title": "title" } }'
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" } }'
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" } }'
4145
4246 CardTool {
4347 id: cardTool
44− template: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(artCardModel))['template'];
45− components: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(artCardModel))['components'];
48+ template: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(cardModel))['template'];
49+ components: Helpers.update(JSON.parse(Helpers.defaultLayout), JSON.parse(cardModel))['components'];
4650 viewWidth: units.gu(48)
4751 }
4852