on xenial help sign in
Introduce "scaleTo" property instead of abusing sourceSize.
commit16545fd5096683b850d8de0bda3084b31c495abf authorMichał Sawicz <michal.sawicz@canonical.com> dateThu 26 Sep 2013, 13:25 (13 years ago) parent1b0eb8d
2 files changed+13−17
Components/LazyImage.qml+9−15 tests/qmltests/Components/tst_LazyImage.qml+4−2
Components/LazyImage.qml+9−15
@@ -24,11 +24,13 @@ Item {
2424 id: root
2525
2626 property url source
27+ // TODO convert into enums when available in QML
28+ property string scaleTo
2729
28− property real initialWidth: sourceSize.width > -1 ? sourceSize.width : units.gu(10)
29− property real initialHeight: sourceSize.height > -1 ? sourceSize.height : units.gu(10)
30− property size sourceSize
30+ property real initialWidth: units.gu(10)
31+ property real initialHeight: units.gu(10)
3132
33+ property alias sourceSize: image.sourceSize
3234 property alias fillMode: image.fillMode
3335 property alias asynchronous: image.asynchronous
3436 property alias cache: image.cache
@@ -87,23 +89,15 @@ Item {
8789
8890 property url nextSource
8991
90− width: {
91− if (root.sourceSize.width > -1) return root.sourceSize.width;
92− if (root.sourceSize.height > -1) return implicitWidth * root.sourceSize.height / implicitHeight
93− return implicitWidth
94− }
95− height: {
96− if (root.sourceSize.height > -1) return root.sourceSize.height;
97− if (root.sourceSize.width > -1) return implicitHeight* root.sourceSize.width / implicitWidth
98− return implicitHeight
99− }
92+ width: root.scaleTo == "height" ? implicitWidth * root.height / implicitHeight : implicitWidth
93+ height: root.scaleTo == "width" ? implicitHeight * root.width / implicitWidth : implicitHeight
10094 fillMode: Image.PreserveAspectCrop
10195 asynchronous: true
10296 cache: false
10397 horizontalAlignment: Image.AlignHCenter
10498 verticalAlignment: Image.AlignVCenter
105− sourceSize.width: root.sourceSize.width
106− sourceSize.height: root.sourceSize.height
99+ sourceSize.width: root.scaleTo == "width" ? root.width : 0
100+ sourceSize.height: root.scaleTo == "height" ? root.height : 0
107101 }
108102 }
109103
tests/qmltests/Components/tst_LazyImage.qml+4−2
@@ -57,7 +57,8 @@ Rectangle {
5757
5858 LazyImage {
5959 id: lazy2
60− sourceSize.width: units.gu(30)
60+ width: units.gu(30)
61+ scaleTo: "width"
6162 }
6263
6364 Label {
@@ -69,7 +70,8 @@ Rectangle {
6970
7071 LazyImage {
7172 id: lazy3
72− sourceSize.height: units.gu(10)
73+ height: units.gu(10)
74+ scaleTo: "height"
7375 }
7476 }
7577 }