on xenial help sign in
Add test for art only
commit16e6ba93bd7e5dd0ab7a7f12dcafd0d3934ecd63 authorAlbert Astals <albert.astals@canonical.com> dateTue 8 Jul 2014, 11:50 (12 years ago) parent81415ed
2 files changed+69
tests/plugins/Dash/cardcreator/6.res+66 tests/plugins/Dash/cardcreator/6.tst+3
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