Merge lp:~fboucault/ubuntu-ui-toolkit/scaling_image_provider_respect_size into lp:ubuntu-ui-toolkit

Proposed by Florian Boucault
Status: Merged
Approved by: Zsombor Egri
Approved revision: 436
Merged at revision: 435
Proposed branch: lp:~fboucault/ubuntu-ui-toolkit/scaling_image_provider_respect_size
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 94 lines (+56/-6)
2 files modified
modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp (+17/-6)
tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp (+39/-0)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-toolkit/scaling_image_provider_respect_size
Reviewer Review Type Date Requested Status
Zsombor Egri Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+159908@code.launchpad.net

Commit message

UCScalingImageProvider: respect 'requestedSize' parameter. That ensures that the 'sourceSize' property of Image is respected even when the toolkit automatically scales the asset for the device.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

No complains, pretty straight forward :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp'
2--- modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2012-10-28 02:23:12 +0000
3+++ modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2013-04-20 01:20:35 +0000
4@@ -38,8 +38,6 @@
5
6 QImage UCScalingImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
7 {
8- Q_UNUSED(requestedSize);
9-
10 int separatorPosition = id.indexOf("/");
11 float scaleFactor = id.left(separatorPosition).toFloat();
12 QString path = id.mid(separatorPosition+1);
13@@ -48,12 +46,25 @@
14 if (file.open(QIODevice::ReadOnly)) {
15 QImage image;
16 QImageReader imageReader(&file);
17+ QSize realSize = imageReader.size();
18+ QSize scaledSize = realSize;
19+ QSize constrainedSize;
20+
21 if (!qFuzzyCompare(scaleFactor, (float)1.0)) {
22- QSize realSize = imageReader.size();
23- imageReader.setScaledSize(realSize * scaleFactor);
24- }
25+ scaledSize = realSize * scaleFactor;
26+ }
27+ if (requestedSize.isValid() && (requestedSize.width() < realSize.width() || requestedSize.height() < realSize.height())) {
28+ constrainedSize = scaledSize.scaled(requestedSize, Qt::KeepAspectRatio);
29+ }
30+
31+ if (constrainedSize.isValid()) {
32+ imageReader.setScaledSize(constrainedSize);
33+ } else if (scaledSize != realSize) {
34+ imageReader.setScaledSize(scaledSize);
35+ }
36+
37 imageReader.read(&image);
38- *size = image.size();
39+ *size = scaledSize;
40 return image;
41 } else {
42 return QImage();
43
44=== added file 'tests/unit/tst_scaling_image_provider/input128x256.png'
45Binary files tests/unit/tst_scaling_image_provider/input128x256.png 1970-01-01 00:00:00 +0000 and tests/unit/tst_scaling_image_provider/input128x256.png 2013-04-20 01:20:35 +0000 differ
46=== modified file 'tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp'
47--- tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2012-10-28 00:57:40 +0000
48+++ tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2013-04-20 01:20:35 +0000
49@@ -50,6 +50,45 @@
50 QCOMPARE(result, expected);
51 QCOMPARE(returnedSize, expected.size());
52 }
53+
54+ void respectRequestedSize_data() {
55+ QTest::addColumn<QString>("inputFile");
56+ QTest::addColumn<QString>("scalingFactor");
57+ QTest::addColumn<QSize>("requestedSize");
58+ QTest::addColumn<QSize>("returnedSize");
59+ QTest::addColumn<QSize>("resultSize");
60+
61+ QString inputFile(QDir::currentPath() + QDir::separator() + "input128x256.png");
62+ QTest::newRow("no scaling, bigger width and height") << inputFile << "1.0" << QSize(1000, 1000) << QSize(128, 256) << QSize(128, 256);
63+ QTest::newRow("no scaling, smaller width") << inputFile << "1.0" << QSize(50, 1000) << QSize(128, 256) << QSize(50, 100);
64+ QTest::newRow("no scaling, smaller height") << inputFile << "1.0" << QSize(1000, 50) << QSize(128, 256) << QSize(25, 50);
65+ QTest::newRow("no scaling, smaller width and height")<< inputFile << "1.0" << QSize(50, 50) << QSize(128, 256) << QSize(25, 50);
66+ QTest::newRow("downscaling, bigger width and height")<< inputFile << "0.5" << QSize(1000, 1000) << QSize(64, 128) << QSize(64, 128);
67+ QTest::newRow("downscaling, smaller width") << inputFile << "0.5" << QSize(50, 1000) << QSize(64, 128) << QSize(50, 100);
68+ QTest::newRow("downscaling, smaller height") << inputFile << "0.5" << QSize(1000, 50) << QSize(64, 128) << QSize(25, 50);
69+ QTest::newRow("downscaling, smaller width and height")<< inputFile << "0.5" << QSize(50, 50) << QSize(64, 128) << QSize(25, 50);
70+ QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512);
71+ QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100);
72+ QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50);
73+ QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50);
74+ }
75+
76+ void respectRequestedSize() {
77+ UCScalingImageProvider provider;
78+ QImage result;
79+ QSize size;
80+
81+ QFETCH(QString, inputFile);
82+ QFETCH(QString, scalingFactor);
83+ QFETCH(QSize, requestedSize);
84+ QFETCH(QSize, returnedSize);
85+ QFETCH(QSize, resultSize);
86+
87+ result = provider.requestImage(scalingFactor + "/" + inputFile, &size, requestedSize);
88+
89+ QCOMPARE(size, returnedSize);
90+ QCOMPARE(result.size(), resultSize);
91+ }
92 };
93
94 QTEST_MAIN(tst_UCScalingImageProvider)

Subscribers

People subscribed via source and target branches

to status/vote changes: