on xenial help sign in
Card.qml binding loops are gone. hooray \o/
7080a5bAlbert Astals
qml/Dash/Card.qml+30−12
@@ -71,23 +71,27 @@ AbstractButton {
71 id: artShape
71 id: artShape
72 radius: "medium"
72 radius: "medium"
73 objectName: "artShape"
73 objectName: "artShape"
74− width: {
75− if (!visible) return 0
76− return image.fillMode === Image.PreserveAspectCrop || aspect < image.aspect ? image.width : height * image.aspect
77− }
78− height: {
79− if (!visible) return 0
80− return image.fillMode === Image.PreserveAspectCrop || aspect > image.aspect ? image.height : width / image.aspect
81− }
82 anchors.horizontalCenter: template && template["card-layout"] === "horizontal" ? undefined : parent.horizontalCenter
74 anchors.horizontalCenter: template && template["card-layout"] === "horizontal" ? undefined : parent.horizontalCenter
83 anchors.left: template && template["card-layout"] === "horizontal" ? parent.left : undefined
75 anchors.left: template && template["card-layout"] === "horizontal" ? parent.left : undefined
84 visible: cardData && cardData["art"] || false
76 visible: cardData && cardData["art"] || false
85
77
86− property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1
78+ readonly property real aspect: components !== undefined ? components["art"]["aspect-ratio"] : 1
79+ readonly property bool useImageWidthForWidth: image.fillMode === Image.PreserveAspectCrop || aspect < image.aspect
80+
81+ Component.onCompleted: updateWidthHeightBindings();
82+ onUseImageWidthForWidthChanged: updateWidthHeightBindings();
83+
84+ function updateWidthHeightBindings() {
85+ if (useImageWidthForWidth) {
86+ width = Qt.binding(function() { return visible ? image.width : 0 });
87+ height = Qt.binding(function() { return visible ? width / image.aspect : 0 });
88+ } else {
89+ width = Qt.binding(function() { return visible ? height * image.aspect : 0 });
90+ height = Qt.binding(function() { return visible ? image.height : 0 });
91+ }
92+ }
87
93
88 image: Image {
94 image: Image {
89− width: template && template["card-layout"] === "horizontal" ? height * artShape.aspect : root.width
90− height: template && template["card-layout"] === "horizontal" ? header.height : width / artShape.aspect
91 objectName: "artImage"
95 objectName: "artImage"
92 source: cardData && cardData["art"] || ""
96 source: cardData && cardData["art"] || ""
93 cache: true
97 cache: true
@@ -96,7 +100,21 @@ AbstractButton {
96 //sourceSize.height: height > width ? height : 0
100 //sourceSize.height: height > width ? height : 0
97 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop
101 fillMode: components && components["art"]["fill-mode"] === "fit" ? Image.PreserveAspectFit: Image.PreserveAspectCrop
98
102
99− property real aspect: implicitWidth / implicitHeight
103+ readonly property real aspect: implicitWidth / implicitHeight
104+ readonly property bool isHorizontal: template && template["card-layout"] === "horizontal"
105+
106+ Component.onCompleted: updateWidthHeightBindings();
107+ onIsHorizontalChanged: updateWidthHeightBindings();
108+
109+ function updateWidthHeightBindings() {
110+ if (isHorizontal) {
111+ width = Qt.binding(function() { return height * artShape.aspect });
112+ height = Qt.binding(function() { return header.height });
113+ } else {
114+ width = Qt.binding(function() { return root.width });
115+ height = Qt.binding(function() { return width / artShape.aspect });
116+ }
117+ }
100 }
118 }
101 }
119 }
102
120