Merge lp:~fboucault/ubuntu-ui-toolkit/dpr_rebase_qt_5.1 into lp:ubuntu-ui-toolkit

Proposed by Florian Boucault
Status: Rejected
Rejected by: Tim Peeters
Proposed branch: lp:~fboucault/ubuntu-ui-toolkit/dpr_rebase_qt_5.1
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 525 lines (+219/-61)
11 files modified
modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml (+1/-0)
modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml (+2/-2)
modules/Ubuntu/Components/plugin/shapeitem.cpp (+20/-5)
modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp (+42/-4)
modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp (+6/-0)
modules/Ubuntu/Components/plugin/ucunits.cpp (+30/-7)
modules/Ubuntu/Components/plugin/ucunits.h (+4/-0)
modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp (+5/-2)
tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp (+7/-1)
tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp (+12/-4)
tests/unit/tst_units/tst_units.cpp (+90/-36)
To merge this branch: bzr merge lp:~fboucault/ubuntu-ui-toolkit/dpr_rebase_qt_5.1
Reviewer Review Type Date Requested Status
Tim Peeters Needs Resubmitting
PS Jenkins bot continuous-integration Approve
Zsombor Egri Pending
Review via email: mp+183762@code.launchpad.net

Commit message

Change is only enabled for the webbrowser app.

Rebase resolution independence on Qt's infrastructure:
- QPlatformScreen::devicePixelRatio
- QPlatformWindow::devicePixelRatio

Change is only enabled for Qt version >= 5.1 and when qtubuntu is in use.
A 'dp' is now exactly one Qt pixel and a 'gu' is 8 Qt pixels.
devicePixelRatio is set to be GRID_UNIT_PX / 8.

To post a comment you must log in.
Revision history for this message
Dmitry Shachnev (mitya57) wrote :

The tests currently fail here:

FAIL! : qmltestrunner::UCUnitsAPI::test_gu() can use units.gu
   Actual (): 8
   Expected (): 9
   Loc: [/home/dmitry/tests/ubuntu-ui-toolkit/tests/unit/tst_components/tst_plugin_ucunits.qml(40)]

Revision history for this message
Albert Astals Cid (aacid) wrote :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
751. By Florian Boucault

Merged from trunk.

752. By Florian Boucault

Removed duplicated constant.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
753. By Florian Boucault

Removed useless include.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
754. By Florian Boucault

Do not avoid upscaling.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
755. By Florian Boucault

Icon image provider: convert from device independent pixels to real pixels

756. By Florian Boucault

Fix BorderImage scaling with a workaround.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
757. By Florian Boucault

Merged from trunk.

758. By Florian Boucault

Only activate new code path when Qt is at least version 5.1 and we are using qtubuntu.

759. By Florian Boucault

Removed stray debug.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
760. By Florian Boucault

Merged from trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
761. By Florian Boucault

Also activate useDevicePixelRatio for MIR's qtubuntu.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
762. By Florian Boucault

Removed stray debug.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
763. By Florian Boucault

TabBar: do not rely on sourceSize that uses real pixels.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

25 - height: 0.82*sourceSize.height
26 + height: units.dp(25)

This may cause the chevron issues on Mir, however we need to check whether it appears on SurfaceFlinger. If it does, the image scaling needs to be revisited.

764. By Florian Boucault

Made tab bar chevron a bit smaller and prettier.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
765. By Florian Boucault

Only activate devicePixelRatio based scaling for webbrowser-app.

766. By Florian Boucault

Reverted unwanted change from previous commit.

767. By Florian Boucault

Also activate devicePixelRatio based scaling for webapps.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tim Peeters (tpeeters) wrote :

If this MR is still valid, please resubmit it to staging

review: Needs Resubmitting

Unmerged revisions

767. By Florian Boucault

Also activate devicePixelRatio based scaling for webapps.

766. By Florian Boucault

Reverted unwanted change from previous commit.

765. By Florian Boucault

Only activate devicePixelRatio based scaling for webbrowser-app.

764. By Florian Boucault

Made tab bar chevron a bit smaller and prettier.

763. By Florian Boucault

TabBar: do not rely on sourceSize that uses real pixels.

762. By Florian Boucault

Removed stray debug.

761. By Florian Boucault

Also activate useDevicePixelRatio for MIR's qtubuntu.

760. By Florian Boucault

Merged from trunk

759. By Florian Boucault

Removed stray debug.

758. By Florian Boucault

Only activate new code path when Qt is at least version 5.1 and we are using qtubuntu.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml'
--- modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml 2014-01-08 16:32:38 +0000
+++ modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml 2014-03-10 17:18:58 +0000
@@ -50,6 +50,7 @@
50 left: parent.left50 left: parent.left
51 right: parent.right51 right: parent.right
52 }52 }
53 height: units.dp(15)
53 source: headerStyle.separatorSource54 source: headerStyle.separatorSource
54 }55 }
55 Image {56 Image {
5657
=== modified file 'modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml'
--- modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml 2014-02-26 18:29:40 +0000
+++ modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml 2014-03-10 17:18:58 +0000
@@ -162,11 +162,11 @@
162 source: indicatorImageSource162 source: indicatorImageSource
163 anchors {163 anchors {
164 bottom: parent.bottom164 bottom: parent.bottom
165 bottomMargin: headerTextBottomMargin165 bottomMargin: headerTextBottomMargin - units.dp(3)
166 }166 }
167 x: button.width - width167 x: button.width - width
168 // FIXME: temporary hack for the chevron's height to match the font size168 // FIXME: temporary hack for the chevron's height to match the font size
169 height: 0.82*sourceSize.height169 height: units.dp(20)
170170
171 // The indicator image must be visible after the selected tab button, when the171 // The indicator image must be visible after the selected tab button, when the
172 // tab bar is not in selection mode, or after the "last" button (starting with172 // tab bar is not in selection mode, or after the "last" button (starting with
173173
=== modified file 'modules/Ubuntu/Components/plugin/shapeitem.cpp'
--- modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-11-22 19:21:34 +0000
+++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-03-10 17:18:58 +0000
@@ -146,8 +146,13 @@
146 setFlag(ItemHasContents);146 setFlag(ItemHasContents);
147 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,147 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,
148 SLOT(gridUnitChanged()));148 SLOT(gridUnitChanged()));
149 setImplicitWidth(8 * gridUnit_);149 if (UCUnits::useDevicePixelRatio) {
150 setImplicitHeight(8 * gridUnit_);150 setImplicitWidth(8 * DEFAULT_GRID_UNIT_PX);
151 setImplicitHeight(8 * DEFAULT_GRID_UNIT_PX);
152 } else {
153 setImplicitWidth(8 * gridUnit_);
154 setImplicitHeight(8 * gridUnit_);
155 }
151 update();156 update();
152}157}
153158
@@ -324,8 +329,13 @@
324void ShapeItem::gridUnitChanged()329void ShapeItem::gridUnitChanged()
325{330{
326 gridUnit_ = UCUnits::instance().gridUnit();331 gridUnit_ = UCUnits::instance().gridUnit();
327 setImplicitWidth(8 * gridUnit_);332 if (UCUnits::useDevicePixelRatio) {
328 setImplicitHeight(8 * gridUnit_);333 setImplicitWidth(8 * DEFAULT_GRID_UNIT_PX);
334 setImplicitHeight(8 * DEFAULT_GRID_UNIT_PX);
335 } else {
336 setImplicitWidth(8 * gridUnit_);
337 setImplicitHeight(8 * gridUnit_);
338 }
329 dirtyFlags_ |= ShapeItem::DirtyGridUnit;339 dirtyFlags_ |= ShapeItem::DirtyGridUnit;
330 update();340 update();
331}341}
@@ -390,7 +400,12 @@
390 // is less than 2 radii, the radius is scaled down anyhow.400 // is less than 2 radii, the radius is scaled down anyhow.
391 float radius = (radius_ == ShapeItem::SmallRadius) ?401 float radius = (radius_ == ShapeItem::SmallRadius) ?
392 textureData->smallRadius : textureData->mediumRadius;402 textureData->smallRadius : textureData->mediumRadius;
393 const float scaleFactor = gridUnit_ / textureData->gridUnit;403 float scaleFactor;
404 if (UCUnits::useDevicePixelRatio) {
405 scaleFactor = DEFAULT_GRID_UNIT_PX / textureData->gridUnit;
406 } else {
407 scaleFactor = gridUnit_ / textureData->gridUnit;
408 }
394 radius *= scaleFactor;409 radius *= scaleFactor;
395 int scaledDown = 0;410 int scaledDown = 0;
396 if (scaleFactor != 1.0f) {411 if (scaleFactor != 1.0f) {
397412
=== modified file 'modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp'
--- modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2013-10-18 08:56:39 +0000
+++ modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2014-03-10 17:18:58 +0000
@@ -75,15 +75,16 @@
75 QString scaleFactor = resolved.left(separatorPosition);75 QString scaleFactor = resolved.left(separatorPosition);
76 QString selectedFilePath = resolved.mid(separatorPosition+1);76 QString selectedFilePath = resolved.mid(separatorPosition+1);
7777
78 if (scaleFactor == "1") {78 if (UCUnits::useDevicePixelRatio) {
79 // No scaling. Just pass the file as is.
80 m_image->setSource(QUrl::fromLocalFile(selectedFilePath));
81 } else {
82 // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider.79 // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider.
83 if (!m_source.path().endsWith(".sci")) {80 if (!m_source.path().endsWith(".sci")) {
84 // Regular image file81 // Regular image file
85 m_image->setSource(QUrl("image://scaling/" + resolved));82 m_image->setSource(QUrl("image://scaling/" + resolved));
86 } else {83 } else {
84 /* FIXME: workaround for https://bugreports.qt-project.org/browse/QTBUG-37206 */
85 float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX;
86 scaleFactor = QString::number(scaleFactor.toFloat() / windowPixelRatio);
87
87 // .sci image file. Rewrite the .sci file into a temporary file.88 // .sci image file. Rewrite the .sci file into a temporary file.
88 bool rewritten = true;89 bool rewritten = true;
89 QTemporaryFile* rewrittenSciFile;90 QTemporaryFile* rewrittenSciFile;
@@ -110,6 +111,43 @@
110 m_image->setSource(m_source);111 m_image->setSource(m_source);
111 }112 }
112 }113 }
114 } else {
115 if (scaleFactor == "1") {
116 // No scaling. Just pass the file as is.
117 m_image->setSource(QUrl::fromLocalFile(selectedFilePath));
118 } else {
119 // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider.
120 if (!m_source.path().endsWith(".sci")) {
121 // Regular image file
122 m_image->setSource(QUrl("image://scaling/" + resolved));
123 } else {
124 // .sci image file. Rewrite the .sci file into a temporary file.
125 bool rewritten = true;
126 QTemporaryFile* rewrittenSciFile;
127
128 /* Ensure that only one temporary rewritten .sci file is created
129 for each source .sci file by storing the path to the temporary
130 file in a global hash.
131 */
132 rewrittenSciFile = UCQQuickImageExtension::s_rewrittenSciFiles.value(m_source).data();
133 if (rewrittenSciFile == NULL) {
134 rewrittenSciFile = new QTemporaryFile;
135 rewrittenSciFile->setFileTemplate(QDir::tempPath() + QDir::separator() + "XXXXXX.sci");
136 rewrittenSciFile->open();
137 QTextStream output(rewrittenSciFile);
138 rewritten = rewriteSciFile(selectedFilePath, scaleFactor, output);
139 rewrittenSciFile->close();
140
141 s_rewrittenSciFiles.insert(m_source, QSharedPointer<QTemporaryFile>(rewrittenSciFile));
142 }
143
144 if (rewritten) {
145 m_image->setSource(QUrl::fromLocalFile(rewrittenSciFile->fileName()));
146 } else {
147 m_image->setSource(m_source);
148 }
149 }
150 }
113 }151 }
114}152}
115153
116154
=== modified file 'modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp'
--- modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2013-04-20 01:14:43 +0000
+++ modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2014-03-10 17:18:58 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "ucscalingimageprovider.h"19#include "ucscalingimageprovider.h"
20#include "ucunits.h"
2021
21#include <QtCore/QFile>22#include <QtCore/QFile>
22#include <QtGui/QImageReader>23#include <QtGui/QImageReader>
@@ -65,6 +66,11 @@
6566
66 imageReader.read(&image);67 imageReader.read(&image);
67 *size = scaledSize;68 *size = scaledSize;
69
70 if (UCUnits::useDevicePixelRatio) {
71 float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX;
72 image.setDevicePixelRatio(windowPixelRatio);
73 }
68 return image;74 return image;
69 } else {75 } else {
70 return QImage();76 return QImage();
7177
=== modified file 'modules/Ubuntu/Components/plugin/ucunits.cpp'
--- modules/Ubuntu/Components/plugin/ucunits.cpp 2013-10-18 08:56:39 +0000
+++ modules/Ubuntu/Components/plugin/ucunits.cpp 2014-03-10 17:18:58 +0000
@@ -24,9 +24,11 @@
24#include <QtCore/QDir>24#include <QtCore/QDir>
25#include <QtCore/QRegularExpression>25#include <QtCore/QRegularExpression>
26#include <QtCore/qmath.h>26#include <QtCore/qmath.h>
27#include <QtCore/QDebug>
28#include <QtGui/QGuiApplication>
29#include <QtCore/QCoreApplication>
2730
28#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"31#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
29#define DEFAULT_GRID_UNIT_PX 8
3032
31static float getenvFloat(const char* name, float defaultValue)33static float getenvFloat(const char* name, float defaultValue)
32{34{
@@ -36,6 +38,12 @@
36 return ok ? value : defaultValue;38 return ok ? value : defaultValue;
37}39}
3840
41bool UCUnits::useDevicePixelRatio = (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)) &&
42 (QGuiApplication::platformName() == "ubuntu" ||
43 QGuiApplication::platformName() == "ubuntumirserver" ||
44 QGuiApplication::platformName() == "ubuntumirclient") &&
45 (QCoreApplication::applicationName() == "webbrowser-app" ||
46 QCoreApplication::applicationName() == "webapp-container");
3947
40/*!48/*!
41 \qmltype Units49 \qmltype Units
@@ -80,6 +88,13 @@
8088
81void UCUnits::setGridUnit(float gridUnit)89void UCUnits::setGridUnit(float gridUnit)
82{90{
91 /* Implementation of resolution independence is spread accross
92 the toolkit and qtubuntu. The number of pixels for a grid unit
93 is read by both from the environment variable GRID_UNIT_PX.
94 Setting the 'gridUnit' property here has no effect.
95 */
96 qWarning() << "UCUnits::setGridUnit is deprecated.";
97
83 m_gridUnit = gridUnit;98 m_gridUnit = gridUnit;
84 Q_EMIT gridUnitChanged();99 Q_EMIT gridUnitChanged();
85}100}
@@ -91,12 +106,16 @@
91*/106*/
92float UCUnits::dp(float value)107float UCUnits::dp(float value)
93{108{
94 const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX;109 if (UCUnits::useDevicePixelRatio) {
95 if (value <= 2.0) {110 return qRound(value);
96 // for values under 2dp, return only multiples of the value
97 return qRound(value * qFloor(ratio));
98 } else {111 } else {
99 return qRound(value * ratio);112 const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX;
113 if (value <= 2.0) {
114 // for values under 2dp, return only multiples of the value
115 return qRound(value * qFloor(ratio));
116 } else {
117 return qRound(value * ratio);
118 }
100 }119 }
101}120}
102121
@@ -107,7 +126,11 @@
107*/126*/
108float UCUnits::gu(float value)127float UCUnits::gu(float value)
109{128{
110 return qRound(value * m_gridUnit);129 if (UCUnits::useDevicePixelRatio) {
130 return qRound(value * DEFAULT_GRID_UNIT_PX);
131 } else {
132 return qRound(value * m_gridUnit);
133 }
111}134}
112135
113QString UCUnits::resolveResource(const QUrl& url)136QString UCUnits::resolveResource(const QUrl& url)
114137
=== modified file 'modules/Ubuntu/Components/plugin/ucunits.h'
--- modules/Ubuntu/Components/plugin/ucunits.h 2013-10-18 08:56:39 +0000
+++ modules/Ubuntu/Components/plugin/ucunits.h 2014-03-10 17:18:58 +0000
@@ -23,6 +23,8 @@
23#include <QtCore/QHash>23#include <QtCore/QHash>
24#include <QtCore/QUrl>24#include <QtCore/QUrl>
2525
26#define DEFAULT_GRID_UNIT_PX 8
27
26class UCUnits : public QObject28class UCUnits : public QObject
27{29{
28 Q_OBJECT30 Q_OBJECT
@@ -45,6 +47,8 @@
45 // setters47 // setters
46 void setGridUnit(float gridUnit);48 void setGridUnit(float gridUnit);
4749
50 static bool useDevicePixelRatio;
51
48Q_SIGNALS:52Q_SIGNALS:
49 void gridUnitChanged();53 void gridUnitChanged();
5054
5155
=== modified file 'modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp'
--- modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2014-02-24 18:20:43 +0000
+++ modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2014-03-10 17:18:58 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "unitythemeiconprovider.h"19#include "unitythemeiconprovider.h"
20#include "ucunits.h"
2021
21#include <QIcon>22#include <QIcon>
2223
@@ -34,8 +35,10 @@
34 icon = QIcon::fromTheme(name);35 icon = QIcon::fromTheme(name);
35 if (!icon.isNull()) {36 if (!icon.isNull()) {
36 if (requestedSize.isValid()) {37 if (requestedSize.isValid()) {
37 *realSize =requestedSize;38 /* Convert from device independent pixels to pixels into actual pixels */
38 return icon.pixmap(requestedSize);39 float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX;
40 *realSize = requestedSize * windowPixelRatio;
41 return icon.pixmap(*realSize);
39 } else {42 } else {
40 QList<QSize> sizes = icon.availableSizes();43 QList<QSize> sizes = icon.availableSizes();
41 if (sizes.count() > 0 && sizes.last().isValid()) {44 if (sizes.count() > 0 && sizes.last().isValid()) {
4245
=== modified file 'tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp'
--- tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp 2013-05-06 16:33:54 +0000
+++ tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp 2014-03-10 17:18:58 +0000
@@ -18,6 +18,7 @@
1818
19#include <QtTest/QtTest>19#include <QtTest/QtTest>
20#include <QtQuick/private/qquickimagebase_p.h>20#include <QtQuick/private/qquickimagebase_p.h>
21#include "ucunits.h"
2122
22// Make protected methods of QQuickImageExtension public in order to test them23// Make protected methods of QQuickImageExtension public in order to test them
23#define protected public24#define protected public
@@ -55,7 +56,12 @@
55 void scaledBorderDouble() {56 void scaledBorderDouble() {
56 UCQQuickImageExtension image;57 UCQQuickImageExtension image;
57 QString border = "border: 13";58 QString border = "border: 13";
58 QString expected = "border: 26";59 QString expected;
60 if (UCUnits::useDevicePixelRatio) {
61 expected = "border: 13";
62 } else {
63 expected = "border: 26";
64 }
59 QString result = image.scaledBorder(border, "2");65 QString result = image.scaledBorder(border, "2");
60 QCOMPARE(result, expected);66 QCOMPARE(result, expected);
61 }67 }
6268
=== modified file 'tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp'
--- tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2013-04-20 00:39:40 +0000
+++ tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2014-03-10 17:18:58 +0000
@@ -18,6 +18,7 @@
1818
19#include <QtTest/QtTest>19#include <QtTest/QtTest>
20#include "ucscalingimageprovider.h"20#include "ucscalingimageprovider.h"
21#include "ucunits.h"
2122
22class tst_UCScalingImageProvider: public QObject23class tst_UCScalingImageProvider: public QObject
23{24{
@@ -67,10 +68,17 @@
67 QTest::newRow("downscaling, smaller width") << inputFile << "0.5" << QSize(50, 1000) << QSize(64, 128) << QSize(50, 100);68 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 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("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 if (UCUnits::useDevicePixelRatio) {
71 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100);72 QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(128, 256) << QSize(128, 256);
72 QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50);73 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(128, 256) << QSize(50, 100);
73 QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50);74 QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(128, 256) << QSize(25, 50);
75 QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(128, 256) << QSize(25, 50);
76 } else {
77 QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512);
78 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100);
79 QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50);
80 QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50);
81 }
74 }82 }
7583
76 void respectRequestedSize() {84 void respectRequestedSize() {
7785
=== modified file 'tests/unit/tst_units/tst_units.cpp'
--- tests/unit/tst_units/tst_units.cpp 2013-02-05 17:10:20 +0000
+++ tests/unit/tst_units/tst_units.cpp 2014-03-10 17:18:58 +0000
@@ -85,72 +85,126 @@
85 QCOMPARE(units.dp(0.23), 0.0f);85 QCOMPARE(units.dp(0.23), 0.0f);
86 QCOMPARE(units.dp(0.51), 1.0f);86 QCOMPARE(units.dp(0.51), 1.0f);
87 QCOMPARE(units.dp(0.9999), 1.0f);87 QCOMPARE(units.dp(0.9999), 1.0f);
88 QCOMPARE(units.dp(1000.01), 1250.0f);88 if (UCUnits::useDevicePixelRatio) {
89 QCOMPARE(units.dp(1000.01), 1000.0f);
90 } else {
91 QCOMPARE(units.dp(1000.01), 1250.0f);
92 }
89 }93 }
9094
91 void guGridUnitTen() {95 void guGridUnitTen() {
92 UCUnits units;96 UCUnits units;
93 units.setGridUnit(10);97 units.setGridUnit(10);
9498
95 QCOMPARE(units.gu(0.5), 5.0f);99 if (UCUnits::useDevicePixelRatio) {
96 QCOMPARE(units.gu(1), 10.0f);100 QCOMPARE(units.gu(0.5), 4.0f);
97 QCOMPARE(units.gu(1.5), 15.0f);101 QCOMPARE(units.gu(1), 8.0f);
98 QCOMPARE(units.gu(2), 20.0f);102 QCOMPARE(units.gu(1.5), 12.0f);
99 QCOMPARE(units.gu(4), 40.0f);103 QCOMPARE(units.gu(2), 16.0f);
100 QCOMPARE(units.gu(100000), 1000000.0f);104 QCOMPARE(units.gu(4), 32.0f);
101 QCOMPARE(units.gu(150.51983), 1505.0f);105 QCOMPARE(units.gu(100000), 800000.0f);
106 QCOMPARE(units.gu(150.51983), 1204.0f);
107 } else {
108 QCOMPARE(units.gu(0.5), 5.0f);
109 QCOMPARE(units.gu(1), 10.0f);
110 QCOMPARE(units.gu(1.5), 15.0f);
111 QCOMPARE(units.gu(2), 20.0f);
112 QCOMPARE(units.gu(4), 40.0f);
113 QCOMPARE(units.gu(100000), 1000000.0f);
114 QCOMPARE(units.gu(150.51983), 1505.0f);
115 }
102 }116 }
103117
104 void dpGridUnitSixteen() {118 void dpGridUnitSixteen() {
105 UCUnits units;119 UCUnits units;
106 units.setGridUnit(16);120 units.setGridUnit(16);
107121
108 QCOMPARE(units.dp(1.0), 2.0f);122 if (UCUnits::useDevicePixelRatio) {
109 QCOMPARE(units.dp(1.32), 3.0f);123 QCOMPARE(units.dp(1.0), 1.0f);
110 QCOMPARE(units.dp(1.72), 3.0f);124 QCOMPARE(units.dp(1.32), 1.0f);
111 QCOMPARE(units.dp(0.23), 0.0f);125 QCOMPARE(units.dp(1.72), 2.0f);
112 QCOMPARE(units.dp(0.51), 1.0f);126 QCOMPARE(units.dp(0.23), 0.0f);
113 QCOMPARE(units.dp(0.9999), 2.0f);127 QCOMPARE(units.dp(0.51), 1.0f);
114 QCOMPARE(units.dp(1000.01), 2000.0f);128 QCOMPARE(units.dp(0.9999), 1.0f);
129 QCOMPARE(units.dp(1000.01), 1000.0f);
130 } else {
131 QCOMPARE(units.dp(1.0), 2.0f);
132 QCOMPARE(units.dp(1.32), 3.0f);
133 QCOMPARE(units.dp(1.72), 3.0f);
134 QCOMPARE(units.dp(0.23), 0.0f);
135 QCOMPARE(units.dp(0.51), 1.0f);
136 QCOMPARE(units.dp(0.9999), 2.0f);
137 QCOMPARE(units.dp(1000.01), 2000.0f);
138 }
115 }139 }
116140
117 void guGridUnitSixteen() {141 void guGridUnitSixteen() {
118 UCUnits units;142 UCUnits units;
119 units.setGridUnit(16);143 units.setGridUnit(16);
120144
121 QCOMPARE(units.gu(0.5), 8.0f);145 if (UCUnits::useDevicePixelRatio) {
122 QCOMPARE(units.gu(1), 16.0f);146 QCOMPARE(units.gu(0.5), 4.0f);
123 QCOMPARE(units.gu(1.5), 24.0f);147 QCOMPARE(units.gu(1), 8.0f);
124 QCOMPARE(units.gu(2), 32.0f);148 QCOMPARE(units.gu(1.5), 12.0f);
125 QCOMPARE(units.gu(4), 64.0f);149 QCOMPARE(units.gu(2), 16.0f);
126 QCOMPARE(units.gu(100000), 1600000.0f);150 QCOMPARE(units.gu(4), 32.0f);
127 QCOMPARE(units.gu(150.51983), 2408.0f);151 QCOMPARE(units.gu(100000), 800000.0f);
152 QCOMPARE(units.gu(150.51983), 1204.0f);
153 } else {
154 QCOMPARE(units.gu(0.5), 8.0f);
155 QCOMPARE(units.gu(1), 16.0f);
156 QCOMPARE(units.gu(1.5), 24.0f);
157 QCOMPARE(units.gu(2), 32.0f);
158 QCOMPARE(units.gu(4), 64.0f);
159 QCOMPARE(units.gu(100000), 1600000.0f);
160 QCOMPARE(units.gu(150.51983), 2408.0f);
161 }
128 }162 }
129163
130 void dpGridUnitEighteen() {164 void dpGridUnitEighteen() {
131 UCUnits units;165 UCUnits units;
132 units.setGridUnit(18);166 units.setGridUnit(18);
133167
134 QCOMPARE(units.dp(1.0), 2.0f);168 if (UCUnits::useDevicePixelRatio) {
135 QCOMPARE(units.dp(1.32), 3.0f);169 QCOMPARE(units.dp(1.0), 1.0f);
136 QCOMPARE(units.dp(1.72), 3.0f);170 QCOMPARE(units.dp(1.32), 1.0f);
137 QCOMPARE(units.dp(0.23), 0.0f);171 QCOMPARE(units.dp(1.72), 2.0f);
138 QCOMPARE(units.dp(0.51), 1.0f);172 QCOMPARE(units.dp(0.23), 0.0f);
139 QCOMPARE(units.dp(0.9999), 2.0f);173 QCOMPARE(units.dp(0.51), 1.0f);
140 QCOMPARE(units.dp(1000.01), 2250.0f);174 QCOMPARE(units.dp(0.9999), 1.0f);
175 QCOMPARE(units.dp(1000.01), 1000.0f);
176 } else {
177 QCOMPARE(units.dp(1.0), 2.0f);
178 QCOMPARE(units.dp(1.32), 3.0f);
179 QCOMPARE(units.dp(1.72), 3.0f);
180 QCOMPARE(units.dp(0.23), 0.0f);
181 QCOMPARE(units.dp(0.51), 1.0f);
182 QCOMPARE(units.dp(0.9999), 2.0f);
183 QCOMPARE(units.dp(1000.01), 2250.0f);
184 }
141 }185 }
142186
143 void dpGridUnitTwenty() {187 void dpGridUnitTwenty() {
144 UCUnits units;188 UCUnits units;
145 units.setGridUnit(20);189 units.setGridUnit(20);
146190
147 QCOMPARE(units.dp(1.0), 2.0f);191 if (UCUnits::useDevicePixelRatio) {
148 QCOMPARE(units.dp(1.32), 3.0f);192 QCOMPARE(units.dp(1.0), 1.0f);
149 QCOMPARE(units.dp(1.72), 3.0f);193 QCOMPARE(units.dp(1.32), 1.0f);
150 QCOMPARE(units.dp(0.23), 0.0f);194 QCOMPARE(units.dp(1.72), 2.0f);
151 QCOMPARE(units.dp(0.51), 1.0f);195 QCOMPARE(units.dp(0.23), 0.0f);
152 QCOMPARE(units.dp(0.9999), 2.0f);196 QCOMPARE(units.dp(0.51), 1.0f);
153 QCOMPARE(units.dp(1000.01), 2500.0f);197 QCOMPARE(units.dp(0.9999), 1.0f);
198 QCOMPARE(units.dp(1000.01), 1000.0f);
199 } else {
200 QCOMPARE(units.dp(1.0), 2.0f);
201 QCOMPARE(units.dp(1.32), 3.0f);
202 QCOMPARE(units.dp(1.72), 3.0f);
203 QCOMPARE(units.dp(0.23), 0.0f);
204 QCOMPARE(units.dp(0.51), 1.0f);
205 QCOMPARE(units.dp(0.9999), 2.0f);
206 QCOMPARE(units.dp(1000.01), 2500.0f);
207 }
154 }208 }
155209
156 void resolveEmpty() {210 void resolveEmpty() {

Subscribers

People subscribed via source and target branches

to status/vote changes: