on xenial help sign in
CardCreator: Give a correct implicitHeight if we only have art

The hasSubtitle change is really unrelated and not needed here, just sneaking it in to not create yet another review. Fixes: 1330899 Approved by: Michał Sawicz

commit953b0a222da0acce85becc57f974b2fc32955f64 authorAlbert Astals <albert.astals@canonical.com> dateWed 9 Jul 2014, 19:44 (12 years ago) parentfe9aa1a16e6ba9
3 files changed+72−1
plugins/Dash/CardCreator.js+3−1 tests/plugins/Dash/cardcreator/6.res+66 tests/plugins/Dash/cardcreator/6.tst+3
plugins/Dash/CardCreator.js+3−1
@@ -306,7 +306,7 @@ function cardString(template, components) {
306306 var hasTitle = components["title"] || false;
307307 var hasMascot = components["mascot"] || false;
308308 var headerAsOverlay = hasArt && template && template["overlay"] === true && (hasTitle || hasMascot);
309− var hasSubtitle = components["subtitle"] || false;
309+ var hasSubtitle = hasTitle && components["subtitle"] || false;
310310 var hasHeaderRow = hasMascot && hasTitle;
311311
312312 if (hasBackground) {
@@ -514,6 +514,8 @@ function cardString(template, components) {
514514 code += 'implicitHeight: subtitleLabel.y + subtitleLabel.height + units.gu(1);\n';
515515 } else if (hasTitle) {
516516 code += 'implicitHeight: titleLabel.y + titleLabel.height + units.gu(1);\n';
517+ } else if (hasArt) {
518+ code += 'implicitHeight: artShapeHolder.height;\n';
517519 }
518520 // Close the AbstractButton
519521 code += '}\n';
tests/plugins/Dash/cardcreator/6.resnew file+66
@@ -0,0 +1,66 @@
1+AbstractButton {
2+ id: root;
3+ property var template;
4+ property var components;
5+ property var cardData;
6+ property var artShapeBorderSource: undefined;
7+ property real fontScale: 1.0;
8+ property int headerAlignment: Text.AlignLeft;
9+ property int fixedHeaderHeight: -1;
10+ property size fixedArtShapeSize: Qt.size(-1, -1);
11+ readonly property string title: cardData && cardData["title"] || "";
12+ property bool asynchronous: true;
13+ property bool showHeader: true;
14+ implicitWidth: childrenRect.width;
15+onArtShapeBorderSourceChanged: { if (artShapeBorderSource !== undefined && artShapeLoader.item) artShapeLoader.item.borderSource = artShapeBorderSource; }
16+readonly property size artShapeSize: artShapeLoader.item ? Qt.size(artShapeLoader.item.width, artShapeLoader.item.height) : Qt.size(-1, -1);
17+Item {
18+ id: artShapeHolder;
19+ height: root.fixedArtShapeSize.height > 0 ? root.fixedArtShapeSize.height : artShapeLoader.height;
20+ width: root.fixedArtShapeSize.width > 0 ? root.fixedArtShapeSize.width : artShapeLoader.width;
21+ anchors { horizontalCenter: parent.horizontalCenter; }
22+ Loader {
23+ id: artShapeLoader;
24+ objectName: "artShapeLoader";
25+ active: cardData && cardData["art"] || false;
26+ asynchronous: root.asynchronous;
27+ visible: status == Loader.Ready;
28+ sourceComponent: UbuntuShape {
29+ id: artShape;
30+ objectName: "artShape";
31+ radius: "medium";
32+ visible: image.status == Image.Ready;
33+ readonly property real fixedArtShapeSizeAspect: (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) ? root.fixedArtShapeSize.width / root.fixedArtShapeSize.height : -1;
34+ readonly property real aspect: fixedArtShapeSizeAspect > 0 ? fixedArtShapeSizeAspect : components !== undefined ? components["art"]["aspect-ratio"] : 1;
35+ readonly property bool aspectSmallerThanImageAspect: aspect < image.aspect;
36+ Component.onCompleted: { updateWidthHeightBindings(); if (artShapeBorderSource !== undefined) borderSource = artShapeBorderSource; }
37+ onAspectSmallerThanImageAspectChanged: updateWidthHeightBindings();
38+ Connections { target: root; onFixedArtShapeSizeChanged: updateWidthHeightBindings(); }
39+ function updateWidthHeightBindings() {
40+ if (root.fixedArtShapeSize.height > 0 && root.fixedArtShapeSize.width > 0) {
41+ width = root.fixedArtShapeSize.width;
42+ height = root.fixedArtShapeSize.height;
43+ } else if (aspectSmallerThanImageAspect) {
44+ width = Qt.binding(function() { return !visible ? 0 : image.width });
45+ height = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.height : width / image.aspect });
46+ } else {
47+ width = Qt.binding(function() { return !visible ? 0 : image.fillMode === Image.PreserveAspectCrop ? image.width : height * image.aspect });
48+ height = Qt.binding(function() { return !visible ? 0 : image.height });
49+ }
50+ }
51+ image: Image {
52+ objectName: "artImage";
53+ source: cardData && cardData["art"] || "";
54+ cache: true;
55+ asynchronous: root.asynchronous;
56+ fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop;
57+ readonly property real aspect: implicitWidth / implicitHeight;
58+ width: root.width;
59+ height: width / artShape.aspect;
60+ }
61+ }
62+ }
63+ }
64+readonly property int headerHeight: 0;
65+implicitHeight: artShapeHolder.height;
66+}
tests/plugins/Dash/cardcreator/6.tstnew file+3
@@ -0,0 +1,3 @@
1+template: {"card-layout":"vertical","card-size":"small","category-layout":"grid","collapsed-rows":2}
2+components: {"art":{"aspect-ratio":1.6,"field":"art","fill-mode":"fit"}}
3+result: 6.res