on xenial help sign in
CroppedImageMinimumSourceSize: Fix 'Binding loop detected for property "imageAspectRatio"'

Approved by: Gerry Boland, Michał Sawicz

commit00e2272944faac7ec8c1014f2743a525de66c8bc authorAlbert Astals Cid <albert.astals@canonical.com> dateWed 4 Nov 2015, 14:58 (11 years ago) parent5eb50d2fe871d7
1 file changed+15−4
plugins/Dash/CroppedImageMinimumSourceSize.qml+15−4
plugins/Dash/CroppedImageMinimumSourceSize.qml+15−4
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2014 Canonical, Ltd.
2+ * Copyright (C) 2014, 2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,18 @@ Image {
2121
2222 fillMode: Image.PreserveAspectCrop
2323
24− readonly property real itemAspectRatio: width / height
25− readonly property real imageAspectRatio: implicitWidth / implicitHeight
26− sourceSize: (imageAspectRatio > itemAspectRatio) ? Qt.size(0, height) : Qt.size(width, 0)
24+ property bool useHeight: false
25+ function updateUseHeight()
26+ {
27+ // Do not turn into a binding since otherwise the qml
28+ // engine complains about binding loops
29+ useHeight = (implicitWidth / implicitHeight) > (width / height);
30+ }
31+
32+ onHeightChanged: updateUseHeight();
33+ onWidthChanged: updateUseHeight();
34+ onImplicitHeightChanged: updateUseHeight();
35+ onImplicitWidthChanged: updateUseHeight();
36+
37+ sourceSize: useHeight ? Qt.size(0, height) : Qt.size(width, 0)
2738}