on xenial help sign in
Merge
commit0f4b6e60d977660df9d1d76b82ad9966290d1bbd authorAlbert Astals <albert.astals@canonical.com> dateFri 31 Oct 2014, 16:58 (12 years ago) parenta81dd0570ff5f8
3 files changed+18−9
plugins/Dash/CroppedImageMinimumSourceSize.qml+2−3 plugins/Dash/croppedimagesizer.cpp+8−6 tests/plugins/Dash/tst_CroppedImageMinimumSourceSize.qml+8
plugins/Dash/CroppedImageMinimumSourceSize.qml+2−3
@@ -20,15 +20,14 @@ import Dash 0.1
2020Item {
2121 id: root
2222
23− property alias image: image
2423 property string source
24+ property alias image: image
2525 property alias asynchronous: image.asynchronous
2626 property alias verticalAlignment: image.verticalAlignment
2727 property alias horizontalAlignment: image.horizontalAlignment
2828 property alias fillMode: image.fillMode
2929
30− CroppedImageSizer
31− {
30+ CroppedImageSizer {
3231 id: sizer
3332 source: root.source
3433 width: root.width
plugins/Dash/croppedimagesizer.cpp+8−6
@@ -103,12 +103,14 @@ void CroppedImageSizer::requestFinished()
103103 QImageReader m_reader(m_reply);
104104 const QSize imageSize = m_reader.size();
105105 if (imageSize.isValid()) {
106− const qreal ar = width() / height();
107− const qreal ssar = imageSize.width() / imageSize.height();
108− if (ar > ssar) {
109− m_sourceSize = QSize(m_width, 0);
110− } else {
111− m_sourceSize = QSize(0, m_height);
106+ if (m_height > 0 && imageSize.height() > 0) {
107+ const qreal ar = m_width / m_height;
108+ const qreal ssar = imageSize.width() / (qreal)imageSize.height();
109+ if (ar > ssar) {
110+ m_sourceSize = QSize(m_width, 0);
111+ } else {
112+ m_sourceSize = QSize(0, m_height);
113+ }
112114 }
113115 } else {
114116 qWarning() << "Could not find size of" << m_source;
tests/plugins/Dash/tst_CroppedImageMinimumSourceSize.qml+8
@@ -43,6 +43,14 @@ Rectangle {
4343 function test_croppedSource() {
4444 tryCompare(cimss.image.sourceSize, "width", 100);
4545 tryCompare(cimss.image.sourceSize, "height", 0);
46+
47+ cimss.width = 40;
48+ tryCompare(cimss.image.sourceSize, "width", 0);
49+ tryCompare(cimss.image.sourceSize, "height", 100);
50+
51+ cimss.width = 100;
52+ tryCompare(cimss.image.sourceSize, "width", 100);
53+ tryCompare(cimss.image.sourceSize, "height", 0);
4654 }
4755 }
4856}