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

Proposed by Albert Astals Cid
Status: Rejected
Rejected by: Florian Boucault
Proposed branch: lp:~aacid/ubuntu-ui-toolkit/dpr_rebase_qt_5.1_with_ifdefs
Merge into: lp:ubuntu-ui-toolkit
Diff against target: 449 lines (+172/-7)
9 files modified
modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml (+1/-0)
modules/Ubuntu/Components/plugin/shapeitem.cpp (+17/-0)
modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp (+47/-3)
modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp (+20/-0)
modules/Ubuntu/Components/plugin/ucunits.cpp (+17/-1)
modules/Ubuntu/Components/plugin/ucunits.h (+2/-0)
tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp (+4/-0)
tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp (+10/-3)
tests/unit/tst_units/tst_units.cpp (+54/-0)
To merge this branch: bzr merge lp:~aacid/ubuntu-ui-toolkit/dpr_rebase_qt_5.1_with_ifdefs
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu SDK team Pending
Review via email: mp+196253@code.launchpad.net

Commit message

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

To post a comment you must log in.
Revision history for this message
Albert Astals Cid (aacid) wrote :
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)
Revision history for this message
Florian Boucault (fboucault) wrote :

Unmerged revisions

749. By Albert Astals Cid

Forgot this ifdef

748. By Albert Astals Cid

Add ifdefs for simultaneous 5.0 and 5.1/2 compilation

747. By Albert Astals Cid

Merge

746. By Florian Boucault

Merged trunk

745. By Florian Boucault

Merged trunk

744. By Florian Boucault

Merged from trunk

743. By Florian Boucault

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

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 2013-11-12 06:41:24 +0000
+++ modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml 2013-11-22 10:29:14 +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/plugin/shapeitem.cpp'
--- modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-10-18 08:56:39 +0000
+++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-11-22 10:29:14 +0000
@@ -31,6 +31,9 @@
3131
32// Threshold in grid unit defining the texture quality to be used.32// Threshold in grid unit defining the texture quality to be used.
33const float lowHighTextureThreshold = 11.0f;33const float lowHighTextureThreshold = 11.0f;
34#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
35const float defaultGridUnit = 8.0f;
36#endif
3437
35static const char* const shapeVertexShader =38static const char* const shapeVertexShader =
36 "uniform lowp mat4 matrix; \n"39 "uniform lowp mat4 matrix; \n"
@@ -146,8 +149,13 @@
146 setFlag(ItemHasContents);149 setFlag(ItemHasContents);
147 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,150 QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this,
148 SLOT(gridUnitChanged()));151 SLOT(gridUnitChanged()));
152#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
153 setImplicitWidth(8 * defaultGridUnit);
154 setImplicitHeight(8 * defaultGridUnit);
155#else
149 setImplicitWidth(8 * gridUnit_);156 setImplicitWidth(8 * gridUnit_);
150 setImplicitHeight(8 * gridUnit_);157 setImplicitHeight(8 * gridUnit_);
158#endif
151 update();159 update();
152}160}
153161
@@ -324,8 +332,13 @@
324void ShapeItem::gridUnitChanged()332void ShapeItem::gridUnitChanged()
325{333{
326 gridUnit_ = UCUnits::instance().gridUnit();334 gridUnit_ = UCUnits::instance().gridUnit();
335#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
336 setImplicitWidth(8 * defaultGridUnit);
337 setImplicitHeight(8 * defaultGridUnit);
338#else
327 setImplicitWidth(8 * gridUnit_);339 setImplicitWidth(8 * gridUnit_);
328 setImplicitHeight(8 * gridUnit_);340 setImplicitHeight(8 * gridUnit_);
341#endif
329 dirtyFlags_ |= ShapeItem::DirtyGridUnit;342 dirtyFlags_ |= ShapeItem::DirtyGridUnit;
330 update();343 update();
331}344}
@@ -390,7 +403,11 @@
390 // is less than 2 radii, the radius is scaled down anyhow.403 // is less than 2 radii, the radius is scaled down anyhow.
391 float radius = (radius_ == ShapeItem::SmallRadius) ?404 float radius = (radius_ == ShapeItem::SmallRadius) ?
392 textureData->smallRadius : textureData->mediumRadius;405 textureData->smallRadius : textureData->mediumRadius;
406#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
407 const float scaleFactor = defaultGridUnit / textureData->gridUnit;
408#else
393 const float scaleFactor = gridUnit_ / textureData->gridUnit;409 const float scaleFactor = gridUnit_ / textureData->gridUnit;
410#endif
394 radius *= scaleFactor;411 radius *= scaleFactor;
395 int scaledDown = 0;412 int scaledDown = 0;
396 if (scaleFactor != 1.0f) {413 if (scaleFactor != 1.0f) {
397414
=== 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 2013-11-22 10:29:14 +0000
@@ -75,6 +75,39 @@
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 QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
79 // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider.
80 if (!m_source.path().endsWith(".sci")) {
81 // Regular image file
82 m_image->setSource(QUrl("image://scaling/" + resolved));
83 } else {
84 // .sci image file. Rewrite the .sci file into a temporary file.
85 bool rewritten = true;
86 QTemporaryFile* rewrittenSciFile;
87
88 /* Ensure that only one temporary rewritten .sci file is created
89 for each source .sci file by storing the path to the temporary
90 file in a global hash.
91 */
92 rewrittenSciFile = UCQQuickImageExtension::s_rewrittenSciFiles.value(m_source).data();
93 if (rewrittenSciFile == NULL) {
94 rewrittenSciFile = new QTemporaryFile;
95 rewrittenSciFile->setFileTemplate(QDir::tempPath() + QDir::separator() + "XXXXXX.sci");
96 rewrittenSciFile->open();
97 QTextStream output(rewrittenSciFile);
98 rewritten = rewriteSciFile(selectedFilePath, scaleFactor, output);
99 rewrittenSciFile->close();
100
101 s_rewrittenSciFiles.insert(m_source, QSharedPointer<QTemporaryFile>(rewrittenSciFile));
102 }
103
104 if (rewritten) {
105 m_image->setSource(QUrl::fromLocalFile(rewrittenSciFile->fileName()));
106 } else {
107 m_image->setSource(m_source);
108 }
109 }
110#else
78 if (scaleFactor == "1") {111 if (scaleFactor == "1") {
79 // No scaling. Just pass the file as is.112 // No scaling. Just pass the file as is.
80 m_image->setSource(QUrl::fromLocalFile(selectedFilePath));113 m_image->setSource(QUrl::fromLocalFile(selectedFilePath));
@@ -89,8 +122,8 @@
89 QTemporaryFile* rewrittenSciFile;122 QTemporaryFile* rewrittenSciFile;
90123
91 /* Ensure that only one temporary rewritten .sci file is created124 /* Ensure that only one temporary rewritten .sci file is created
92 for each source .sci file by storing the path to the temporary125 for each source .sci file by storing the path to the temporary
93 file in a global hash.126 file in a global hash.
94 */127 */
95 rewrittenSciFile = UCQQuickImageExtension::s_rewrittenSciFiles.value(m_source).data();128 rewrittenSciFile = UCQQuickImageExtension::s_rewrittenSciFiles.value(m_source).data();
96 if (rewrittenSciFile == NULL) {129 if (rewrittenSciFile == NULL) {
@@ -111,6 +144,7 @@
111 }144 }
112 }145 }
113 }146 }
147#endif
114}148}
115149
116bool UCQQuickImageExtension::rewriteSciFile(const QString &sciFilePath, const QString &scaleFactor, QTextStream& output)150bool UCQQuickImageExtension::rewriteSciFile(const QString &sciFilePath, const QString &scaleFactor, QTextStream& output)
@@ -137,8 +171,18 @@
137QString UCQQuickImageExtension::scaledBorder(const QString &border, const QString &scaleFactor)171QString UCQQuickImageExtension::scaledBorder(const QString &border, const QString &scaleFactor)
138{172{
139 // Rewrite the border line with a scaled border value173 // Rewrite the border line with a scaled border value
174 float scaledValue;
140 QStringList parts = border.split(":");175 QStringList parts = border.split(":");
141 float scaledValue = parts[1].toFloat() * scaleFactor.toFloat();176#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
177 if (scaleFactor.toFloat() < 1.0) {
178 scaledValue = parts[1].toFloat() * scaleFactor.toFloat();
179 } else {
180 // match the behaviour of UCScalingImageProvider and do not upscale
181 scaledValue = parts[1].toFloat();
182 }
183#else
184 scaledValue = parts[1].toFloat() * scaleFactor.toFloat();
185#endif
142 return parts[0] + ": " + QString::number(qRound(scaledValue));186 return parts[0] + ": " + QString::number(qRound(scaledValue));
143}187}
144188
145189
=== 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 2013-11-22 10:29:14 +0000
@@ -17,9 +17,11 @@
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>
24#include <QtCore/QDebug>
2325
24/*!26/*!
25 \internal27 \internal
@@ -29,6 +31,10 @@
29 - 'scale' is the scaling factor applied to the image31 - 'scale' is the scaling factor applied to the image
30 - 'path' is the full path of the image on the filesystem32 - 'path' is the full path of the image on the filesystem
3133
34 If the scaling factor is bigger than 1.0 then do not scale: UCScalingImageProvider
35 never upscales but instead set the devicePixelRatio appropriately so that upscaling
36 is done in the GPU.
37
32 Example:38 Example:
33 * image://scaling/0.5/arrow.png39 * image://scaling/0.5/arrow.png
34*/40*/
@@ -50,7 +56,11 @@
50 QSize scaledSize = realSize;56 QSize scaledSize = realSize;
51 QSize constrainedSize;57 QSize constrainedSize;
5258
59#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
60 if (!qFuzzyCompare(scaleFactor, (float)1.0) && scaleFactor < 1.0) {
61#else
53 if (!qFuzzyCompare(scaleFactor, (float)1.0)) {62 if (!qFuzzyCompare(scaleFactor, (float)1.0)) {
63#endif
54 scaledSize = realSize * scaleFactor;64 scaledSize = realSize * scaleFactor;
55 }65 }
56 if (requestedSize.isValid() && (requestedSize.width() < realSize.width() || requestedSize.height() < realSize.height())) {66 if (requestedSize.isValid() && (requestedSize.width() < realSize.width() || requestedSize.height() < realSize.height())) {
@@ -65,6 +75,16 @@
6575
66 imageReader.read(&image);76 imageReader.read(&image);
67 *size = scaledSize;77 *size = scaledSize;
78#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
79 float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX;
80 if (scaleFactor < 1.0) {
81 image.setDevicePixelRatio(windowPixelRatio);
82 } else {
83 /* When image needs to be upscaled, do not upscale it here but set its
84 devicePixelRatio appropriately so that upscaling is done when rendering. */
85 image.setDevicePixelRatio(windowPixelRatio / scaleFactor);
86 }
87#endif
68 return image;88 return image;
69 } else {89 } else {
70 return QImage();90 return QImage();
7191
=== 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 2013-11-22 10:29:14 +0000
@@ -24,9 +24,9 @@
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>
2728
28#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"29#define ENV_GRID_UNIT_PX "GRID_UNIT_PX"
29#define DEFAULT_GRID_UNIT_PX 8
3030
31static float getenvFloat(const char* name, float defaultValue)31static float getenvFloat(const char* name, float defaultValue)
32{32{
@@ -80,6 +80,14 @@
8080
81void UCUnits::setGridUnit(float gridUnit)81void UCUnits::setGridUnit(float gridUnit)
82{82{
83#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
84 /* Implementation of resolution independence is spread accross
85 the toolkit and qtubuntu. The number of pixels for a grid unit
86 is read by both from the environment variable GRID_UNIT_PX.
87 Setting the 'gridUnit' property here has no effect.
88 */
89 qWarning() << "UCUnits::setGridUnit is deprecated.";
90#endif
83 m_gridUnit = gridUnit;91 m_gridUnit = gridUnit;
84 Q_EMIT gridUnitChanged();92 Q_EMIT gridUnitChanged();
85}93}
@@ -91,6 +99,9 @@
91*/99*/
92float UCUnits::dp(float value)100float UCUnits::dp(float value)
93{101{
102#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
103 return qRound(value);
104#else
94 const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX;105 const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX;
95 if (value <= 2.0) {106 if (value <= 2.0) {
96 // for values under 2dp, return only multiples of the value107 // for values under 2dp, return only multiples of the value
@@ -98,6 +109,7 @@
98 } else {109 } else {
99 return qRound(value * ratio);110 return qRound(value * ratio);
100 }111 }
112#endif
101}113}
102114
103/*!115/*!
@@ -107,7 +119,11 @@
107*/119*/
108float UCUnits::gu(float value)120float UCUnits::gu(float value)
109{121{
122#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
123 return qRound(value * DEFAULT_GRID_UNIT_PX);
124#else
110 return qRound(value * m_gridUnit);125 return qRound(value * m_gridUnit);
126#endif
111}127}
112128
113QString UCUnits::resolveResource(const QUrl& url)129QString UCUnits::resolveResource(const QUrl& url)
114130
=== 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 2013-11-22 10:29:14 +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
2931
=== 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 2013-11-22 10:29:14 +0000
@@ -55,7 +55,11 @@
55 void scaledBorderDouble() {55 void scaledBorderDouble() {
56 UCQQuickImageExtension image;56 UCQQuickImageExtension image;
57 QString border = "border: 13";57 QString border = "border: 13";
58#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
59 QString expected = "border: 13";
60#else
58 QString expected = "border: 26";61 QString expected = "border: 26";
62#endif
59 QString result = image.scaledBorder(border, "2");63 QString result = image.scaledBorder(border, "2");
60 QCOMPARE(result, expected);64 QCOMPARE(result, expected);
61 }65 }
6266
=== 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 2013-11-22 10:29:14 +0000
@@ -67,10 +67,17 @@
67 QTest::newRow("downscaling, smaller width") << inputFile << "0.5" << QSize(50, 1000) << QSize(64, 128) << QSize(50, 100);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);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);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);70#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
71 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100);71 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);72 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(128, 256) << QSize(50, 100);
73 QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(128, 256) << QSize(25, 50);
74 QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(128, 256) << QSize(25, 50);
75#else
76 QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512);
77 QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100);
78 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);79 QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50);
80#endif
74 }81 }
7582
76 void respectRequestedSize() {83 void respectRequestedSize() {
7784
=== 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 2013-11-22 10:29:14 +0000
@@ -85,13 +85,26 @@
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#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
89 QCOMPARE(units.dp(1000.01), 1000.0f);
90#else
88 QCOMPARE(units.dp(1000.01), 1250.0f);91 QCOMPARE(units.dp(1000.01), 1250.0f);
92#endif
89 }93 }
9094
91 void guGridUnitTen() {95 void guGridUnitTen() {
92 UCUnits units;96 UCUnits units;
93 units.setGridUnit(10);97 units.setGridUnit(10);
9498
99#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
100 QCOMPARE(units.gu(0.5), 4.0f);
101 QCOMPARE(units.gu(1), 8.0f);
102 QCOMPARE(units.gu(1.5), 12.0f);
103 QCOMPARE(units.gu(2), 16.0f);
104 QCOMPARE(units.gu(4), 32.0f);
105 QCOMPARE(units.gu(100000), 800000.0f);
106 QCOMPARE(units.gu(150.51983), 1204.0f);
107#else
95 QCOMPARE(units.gu(0.5), 5.0f);108 QCOMPARE(units.gu(0.5), 5.0f);
96 QCOMPARE(units.gu(1), 10.0f);109 QCOMPARE(units.gu(1), 10.0f);
97 QCOMPARE(units.gu(1.5), 15.0f);110 QCOMPARE(units.gu(1.5), 15.0f);
@@ -99,12 +112,22 @@
99 QCOMPARE(units.gu(4), 40.0f);112 QCOMPARE(units.gu(4), 40.0f);
100 QCOMPARE(units.gu(100000), 1000000.0f);113 QCOMPARE(units.gu(100000), 1000000.0f);
101 QCOMPARE(units.gu(150.51983), 1505.0f);114 QCOMPARE(units.gu(150.51983), 1505.0f);
115#endif
102 }116 }
103117
104 void dpGridUnitSixteen() {118 void dpGridUnitSixteen() {
105 UCUnits units;119 UCUnits units;
106 units.setGridUnit(16);120 units.setGridUnit(16);
107121
122#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
123 QCOMPARE(units.dp(1.0), 1.0f);
124 QCOMPARE(units.dp(1.32), 1.0f);
125 QCOMPARE(units.dp(1.72), 2.0f);
126 QCOMPARE(units.dp(0.23), 0.0f);
127 QCOMPARE(units.dp(0.51), 1.0f);
128 QCOMPARE(units.dp(0.9999), 1.0f);
129 QCOMPARE(units.dp(1000.01), 1000.0f);
130#else
108 QCOMPARE(units.dp(1.0), 2.0f);131 QCOMPARE(units.dp(1.0), 2.0f);
109 QCOMPARE(units.dp(1.32), 3.0f);132 QCOMPARE(units.dp(1.32), 3.0f);
110 QCOMPARE(units.dp(1.72), 3.0f);133 QCOMPARE(units.dp(1.72), 3.0f);
@@ -112,12 +135,22 @@
112 QCOMPARE(units.dp(0.51), 1.0f);135 QCOMPARE(units.dp(0.51), 1.0f);
113 QCOMPARE(units.dp(0.9999), 2.0f);136 QCOMPARE(units.dp(0.9999), 2.0f);
114 QCOMPARE(units.dp(1000.01), 2000.0f);137 QCOMPARE(units.dp(1000.01), 2000.0f);
138#endif
115 }139 }
116140
117 void guGridUnitSixteen() {141 void guGridUnitSixteen() {
118 UCUnits units;142 UCUnits units;
119 units.setGridUnit(16);143 units.setGridUnit(16);
120144
145#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
146 QCOMPARE(units.gu(0.5), 4.0f);
147 QCOMPARE(units.gu(1), 8.0f);
148 QCOMPARE(units.gu(1.5), 12.0f);
149 QCOMPARE(units.gu(2), 16.0f);
150 QCOMPARE(units.gu(4), 32.0f);
151 QCOMPARE(units.gu(100000), 800000.0f);
152 QCOMPARE(units.gu(150.51983), 1204.0f);
153#else
121 QCOMPARE(units.gu(0.5), 8.0f);154 QCOMPARE(units.gu(0.5), 8.0f);
122 QCOMPARE(units.gu(1), 16.0f);155 QCOMPARE(units.gu(1), 16.0f);
123 QCOMPARE(units.gu(1.5), 24.0f);156 QCOMPARE(units.gu(1.5), 24.0f);
@@ -125,12 +158,22 @@
125 QCOMPARE(units.gu(4), 64.0f);158 QCOMPARE(units.gu(4), 64.0f);
126 QCOMPARE(units.gu(100000), 1600000.0f);159 QCOMPARE(units.gu(100000), 1600000.0f);
127 QCOMPARE(units.gu(150.51983), 2408.0f);160 QCOMPARE(units.gu(150.51983), 2408.0f);
161#endif
128 }162 }
129163
130 void dpGridUnitEighteen() {164 void dpGridUnitEighteen() {
131 UCUnits units;165 UCUnits units;
132 units.setGridUnit(18);166 units.setGridUnit(18);
133167
168#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
169 QCOMPARE(units.dp(1.0), 1.0f);
170 QCOMPARE(units.dp(1.32), 1.0f);
171 QCOMPARE(units.dp(1.72), 2.0f);
172 QCOMPARE(units.dp(0.23), 0.0f);
173 QCOMPARE(units.dp(0.51), 1.0f);
174 QCOMPARE(units.dp(0.9999), 1.0f);
175 QCOMPARE(units.dp(1000.01), 1000.0f);
176#else
134 QCOMPARE(units.dp(1.0), 2.0f);177 QCOMPARE(units.dp(1.0), 2.0f);
135 QCOMPARE(units.dp(1.32), 3.0f);178 QCOMPARE(units.dp(1.32), 3.0f);
136 QCOMPARE(units.dp(1.72), 3.0f);179 QCOMPARE(units.dp(1.72), 3.0f);
@@ -138,12 +181,22 @@
138 QCOMPARE(units.dp(0.51), 1.0f);181 QCOMPARE(units.dp(0.51), 1.0f);
139 QCOMPARE(units.dp(0.9999), 2.0f);182 QCOMPARE(units.dp(0.9999), 2.0f);
140 QCOMPARE(units.dp(1000.01), 2250.0f);183 QCOMPARE(units.dp(1000.01), 2250.0f);
184#endif
141 }185 }
142186
143 void dpGridUnitTwenty() {187 void dpGridUnitTwenty() {
144 UCUnits units;188 UCUnits units;
145 units.setGridUnit(20);189 units.setGridUnit(20);
146190
191#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
192 QCOMPARE(units.dp(1.0), 1.0f);
193 QCOMPARE(units.dp(1.32), 1.0f);
194 QCOMPARE(units.dp(1.72), 2.0f);
195 QCOMPARE(units.dp(0.23), 0.0f);
196 QCOMPARE(units.dp(0.51), 1.0f);
197 QCOMPARE(units.dp(0.9999), 1.0f);
198 QCOMPARE(units.dp(1000.01), 1000.0f);
199#else
147 QCOMPARE(units.dp(1.0), 2.0f);200 QCOMPARE(units.dp(1.0), 2.0f);
148 QCOMPARE(units.dp(1.32), 3.0f);201 QCOMPARE(units.dp(1.32), 3.0f);
149 QCOMPARE(units.dp(1.72), 3.0f);202 QCOMPARE(units.dp(1.72), 3.0f);
@@ -151,6 +204,7 @@
151 QCOMPARE(units.dp(0.51), 1.0f);204 QCOMPARE(units.dp(0.51), 1.0f);
152 QCOMPARE(units.dp(0.9999), 2.0f);205 QCOMPARE(units.dp(0.9999), 2.0f);
153 QCOMPARE(units.dp(1000.01), 2500.0f);206 QCOMPARE(units.dp(1000.01), 2500.0f);
207#endif
154 }208 }
155209
156 void resolveEmpty() {210 void resolveEmpty() {

Subscribers

People subscribed via source and target branches

to status/vote changes: