on xenial help sign in
Merge
0f4b6e6Albert Astals
plugins/Dash/CroppedImageMinimumSourceSize.qml+2−3
@@ -20,15 +20,14 @@ import Dash 0.1
20Item {
20Item {
21 id: root
21 id: root
22
22
23− property alias image: image
24 property string source
23 property string source
24+ property alias image: image
25 property alias asynchronous: image.asynchronous
25 property alias asynchronous: image.asynchronous
26 property alias verticalAlignment: image.verticalAlignment
26 property alias verticalAlignment: image.verticalAlignment
27 property alias horizontalAlignment: image.horizontalAlignment
27 property alias horizontalAlignment: image.horizontalAlignment
28 property alias fillMode: image.fillMode
28 property alias fillMode: image.fillMode
29
29
30− CroppedImageSizer
30+ CroppedImageSizer {
31− {
32 id: sizer
31 id: sizer
33 source: root.source
32 source: root.source
34 width: root.width
33 width: root.width
plugins/Dash/croppedimagesizer.cpp+8−6
@@ -103,12 +103,14 @@ void CroppedImageSizer::requestFinished()
103 QImageReader m_reader(m_reply);
103 QImageReader m_reader(m_reply);
104 const QSize imageSize = m_reader.size();
104 const QSize imageSize = m_reader.size();
105 if (imageSize.isValid()) {
105 if (imageSize.isValid()) {
106+ if (m_height > 0 && imageSize.height() > 0) {
106− const qreal ar = width() / height();
107+ const qreal ar = m_width / m_height;
107− const qreal ssar = imageSize.width() / imageSize.height();
108+ const qreal ssar = imageSize.width() / (qreal)imageSize.height();
108− if (ar > ssar) {
109+ if (ar > ssar) {
109− m_sourceSize = QSize(m_width, 0);
110+ m_sourceSize = QSize(m_width, 0);
110− } else {
111+ } else {
111− m_sourceSize = QSize(0, m_height);
112+ m_sourceSize = QSize(0, m_height);
113+ }
112 }
114 }
113 } else {
115 } else {
114 qWarning() << "Could not find size of" << m_source;
116 qWarning() << "Could not find size of" << m_source;
tests/plugins/Dash/tst_CroppedImageMinimumSourceSize.qml+8
@@ -43,6 +43,14 @@ Rectangle {
43 function test_croppedSource() {
43 function test_croppedSource() {
44 tryCompare(cimss.image.sourceSize, "width", 100);
44 tryCompare(cimss.image.sourceSize, "width", 100);
45 tryCompare(cimss.image.sourceSize, "height", 0);
45 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);
46 }
54 }
47 }
55 }
48}
56}