Merge lp:~fboucault/ubuntu-ui-toolkit/dpr_rebase_qt_5.1 into lp:ubuntu-ui-toolkit
- dpr_rebase_qt_5.1
- Merge into trunk
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 |
Related bugs: |
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
- QPlatformWindow
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.
Description of the change
Dmitry Shachnev (mitya57) wrote : | # |
Albert Astals Cid (aacid) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:750
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 751. By Florian Boucault
-
Merged from trunk.
- 752. By Florian Boucault
-
Removed duplicated constant.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:751
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:752
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 753. By Florian Boucault
-
Removed useless include.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:753
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 754. By Florian Boucault
-
Do not avoid upscaling.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:754
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:756
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:757
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:759
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 760. By Florian Boucault
-
Merged from trunk
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:760
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 761. By Florian Boucault
-
Also activate useDevicePixelRatio for MIR's qtubuntu.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:761
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 762. By Florian Boucault
-
Removed stray debug.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:762
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 763. By Florian Boucault
-
TabBar: do not rely on sourceSize that uses real pixels.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:763
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : | # |
25 - height: 0.82*sourceSize
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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:764
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 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.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:766
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:767
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Tim Peeters (tpeeters) wrote : | # |
If this MR is still valid, please resubmit it to staging
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
1 | === modified file 'modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml' |
2 | --- modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml 2014-01-08 16:32:38 +0000 |
3 | +++ modules/Ubuntu/Components/Themes/Ambiance/HeaderStyle.qml 2014-03-10 17:18:58 +0000 |
4 | @@ -50,6 +50,7 @@ |
5 | left: parent.left |
6 | right: parent.right |
7 | } |
8 | + height: units.dp(15) |
9 | source: headerStyle.separatorSource |
10 | } |
11 | Image { |
12 | |
13 | === modified file 'modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml' |
14 | --- modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml 2014-02-26 18:29:40 +0000 |
15 | +++ modules/Ubuntu/Components/Themes/Ambiance/TabBarStyle.qml 2014-03-10 17:18:58 +0000 |
16 | @@ -162,11 +162,11 @@ |
17 | source: indicatorImageSource |
18 | anchors { |
19 | bottom: parent.bottom |
20 | - bottomMargin: headerTextBottomMargin |
21 | + bottomMargin: headerTextBottomMargin - units.dp(3) |
22 | } |
23 | x: button.width - width |
24 | // FIXME: temporary hack for the chevron's height to match the font size |
25 | - height: 0.82*sourceSize.height |
26 | + height: units.dp(20) |
27 | |
28 | // The indicator image must be visible after the selected tab button, when the |
29 | // tab bar is not in selection mode, or after the "last" button (starting with |
30 | |
31 | === modified file 'modules/Ubuntu/Components/plugin/shapeitem.cpp' |
32 | --- modules/Ubuntu/Components/plugin/shapeitem.cpp 2013-11-22 19:21:34 +0000 |
33 | +++ modules/Ubuntu/Components/plugin/shapeitem.cpp 2014-03-10 17:18:58 +0000 |
34 | @@ -146,8 +146,13 @@ |
35 | setFlag(ItemHasContents); |
36 | QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this, |
37 | SLOT(gridUnitChanged())); |
38 | - setImplicitWidth(8 * gridUnit_); |
39 | - setImplicitHeight(8 * gridUnit_); |
40 | + if (UCUnits::useDevicePixelRatio) { |
41 | + setImplicitWidth(8 * DEFAULT_GRID_UNIT_PX); |
42 | + setImplicitHeight(8 * DEFAULT_GRID_UNIT_PX); |
43 | + } else { |
44 | + setImplicitWidth(8 * gridUnit_); |
45 | + setImplicitHeight(8 * gridUnit_); |
46 | + } |
47 | update(); |
48 | } |
49 | |
50 | @@ -324,8 +329,13 @@ |
51 | void ShapeItem::gridUnitChanged() |
52 | { |
53 | gridUnit_ = UCUnits::instance().gridUnit(); |
54 | - setImplicitWidth(8 * gridUnit_); |
55 | - setImplicitHeight(8 * gridUnit_); |
56 | + if (UCUnits::useDevicePixelRatio) { |
57 | + setImplicitWidth(8 * DEFAULT_GRID_UNIT_PX); |
58 | + setImplicitHeight(8 * DEFAULT_GRID_UNIT_PX); |
59 | + } else { |
60 | + setImplicitWidth(8 * gridUnit_); |
61 | + setImplicitHeight(8 * gridUnit_); |
62 | + } |
63 | dirtyFlags_ |= ShapeItem::DirtyGridUnit; |
64 | update(); |
65 | } |
66 | @@ -390,7 +400,12 @@ |
67 | // is less than 2 radii, the radius is scaled down anyhow. |
68 | float radius = (radius_ == ShapeItem::SmallRadius) ? |
69 | textureData->smallRadius : textureData->mediumRadius; |
70 | - const float scaleFactor = gridUnit_ / textureData->gridUnit; |
71 | + float scaleFactor; |
72 | + if (UCUnits::useDevicePixelRatio) { |
73 | + scaleFactor = DEFAULT_GRID_UNIT_PX / textureData->gridUnit; |
74 | + } else { |
75 | + scaleFactor = gridUnit_ / textureData->gridUnit; |
76 | + } |
77 | radius *= scaleFactor; |
78 | int scaledDown = 0; |
79 | if (scaleFactor != 1.0f) { |
80 | |
81 | === modified file 'modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp' |
82 | --- modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2013-10-18 08:56:39 +0000 |
83 | +++ modules/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2014-03-10 17:18:58 +0000 |
84 | @@ -75,15 +75,16 @@ |
85 | QString scaleFactor = resolved.left(separatorPosition); |
86 | QString selectedFilePath = resolved.mid(separatorPosition+1); |
87 | |
88 | - if (scaleFactor == "1") { |
89 | - // No scaling. Just pass the file as is. |
90 | - m_image->setSource(QUrl::fromLocalFile(selectedFilePath)); |
91 | - } else { |
92 | + if (UCUnits::useDevicePixelRatio) { |
93 | // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider. |
94 | if (!m_source.path().endsWith(".sci")) { |
95 | // Regular image file |
96 | m_image->setSource(QUrl("image://scaling/" + resolved)); |
97 | } else { |
98 | + /* FIXME: workaround for https://bugreports.qt-project.org/browse/QTBUG-37206 */ |
99 | + float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX; |
100 | + scaleFactor = QString::number(scaleFactor.toFloat() / windowPixelRatio); |
101 | + |
102 | // .sci image file. Rewrite the .sci file into a temporary file. |
103 | bool rewritten = true; |
104 | QTemporaryFile* rewrittenSciFile; |
105 | @@ -110,6 +111,43 @@ |
106 | m_image->setSource(m_source); |
107 | } |
108 | } |
109 | + } else { |
110 | + if (scaleFactor == "1") { |
111 | + // No scaling. Just pass the file as is. |
112 | + m_image->setSource(QUrl::fromLocalFile(selectedFilePath)); |
113 | + } else { |
114 | + // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider. |
115 | + if (!m_source.path().endsWith(".sci")) { |
116 | + // Regular image file |
117 | + m_image->setSource(QUrl("image://scaling/" + resolved)); |
118 | + } else { |
119 | + // .sci image file. Rewrite the .sci file into a temporary file. |
120 | + bool rewritten = true; |
121 | + QTemporaryFile* rewrittenSciFile; |
122 | + |
123 | + /* Ensure that only one temporary rewritten .sci file is created |
124 | + for each source .sci file by storing the path to the temporary |
125 | + file in a global hash. |
126 | + */ |
127 | + rewrittenSciFile = UCQQuickImageExtension::s_rewrittenSciFiles.value(m_source).data(); |
128 | + if (rewrittenSciFile == NULL) { |
129 | + rewrittenSciFile = new QTemporaryFile; |
130 | + rewrittenSciFile->setFileTemplate(QDir::tempPath() + QDir::separator() + "XXXXXX.sci"); |
131 | + rewrittenSciFile->open(); |
132 | + QTextStream output(rewrittenSciFile); |
133 | + rewritten = rewriteSciFile(selectedFilePath, scaleFactor, output); |
134 | + rewrittenSciFile->close(); |
135 | + |
136 | + s_rewrittenSciFiles.insert(m_source, QSharedPointer<QTemporaryFile>(rewrittenSciFile)); |
137 | + } |
138 | + |
139 | + if (rewritten) { |
140 | + m_image->setSource(QUrl::fromLocalFile(rewrittenSciFile->fileName())); |
141 | + } else { |
142 | + m_image->setSource(m_source); |
143 | + } |
144 | + } |
145 | + } |
146 | } |
147 | } |
148 | |
149 | |
150 | === modified file 'modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp' |
151 | --- modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2013-04-20 01:14:43 +0000 |
152 | +++ modules/Ubuntu/Components/plugin/ucscalingimageprovider.cpp 2014-03-10 17:18:58 +0000 |
153 | @@ -17,6 +17,7 @@ |
154 | */ |
155 | |
156 | #include "ucscalingimageprovider.h" |
157 | +#include "ucunits.h" |
158 | |
159 | #include <QtCore/QFile> |
160 | #include <QtGui/QImageReader> |
161 | @@ -65,6 +66,11 @@ |
162 | |
163 | imageReader.read(&image); |
164 | *size = scaledSize; |
165 | + |
166 | + if (UCUnits::useDevicePixelRatio) { |
167 | + float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX; |
168 | + image.setDevicePixelRatio(windowPixelRatio); |
169 | + } |
170 | return image; |
171 | } else { |
172 | return QImage(); |
173 | |
174 | === modified file 'modules/Ubuntu/Components/plugin/ucunits.cpp' |
175 | --- modules/Ubuntu/Components/plugin/ucunits.cpp 2013-10-18 08:56:39 +0000 |
176 | +++ modules/Ubuntu/Components/plugin/ucunits.cpp 2014-03-10 17:18:58 +0000 |
177 | @@ -24,9 +24,11 @@ |
178 | #include <QtCore/QDir> |
179 | #include <QtCore/QRegularExpression> |
180 | #include <QtCore/qmath.h> |
181 | +#include <QtCore/QDebug> |
182 | +#include <QtGui/QGuiApplication> |
183 | +#include <QtCore/QCoreApplication> |
184 | |
185 | #define ENV_GRID_UNIT_PX "GRID_UNIT_PX" |
186 | -#define DEFAULT_GRID_UNIT_PX 8 |
187 | |
188 | static float getenvFloat(const char* name, float defaultValue) |
189 | { |
190 | @@ -36,6 +38,12 @@ |
191 | return ok ? value : defaultValue; |
192 | } |
193 | |
194 | +bool UCUnits::useDevicePixelRatio = (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)) && |
195 | + (QGuiApplication::platformName() == "ubuntu" || |
196 | + QGuiApplication::platformName() == "ubuntumirserver" || |
197 | + QGuiApplication::platformName() == "ubuntumirclient") && |
198 | + (QCoreApplication::applicationName() == "webbrowser-app" || |
199 | + QCoreApplication::applicationName() == "webapp-container"); |
200 | |
201 | /*! |
202 | \qmltype Units |
203 | @@ -80,6 +88,13 @@ |
204 | |
205 | void UCUnits::setGridUnit(float gridUnit) |
206 | { |
207 | + /* Implementation of resolution independence is spread accross |
208 | + the toolkit and qtubuntu. The number of pixels for a grid unit |
209 | + is read by both from the environment variable GRID_UNIT_PX. |
210 | + Setting the 'gridUnit' property here has no effect. |
211 | + */ |
212 | + qWarning() << "UCUnits::setGridUnit is deprecated."; |
213 | + |
214 | m_gridUnit = gridUnit; |
215 | Q_EMIT gridUnitChanged(); |
216 | } |
217 | @@ -91,12 +106,16 @@ |
218 | */ |
219 | float UCUnits::dp(float value) |
220 | { |
221 | - const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX; |
222 | - if (value <= 2.0) { |
223 | - // for values under 2dp, return only multiples of the value |
224 | - return qRound(value * qFloor(ratio)); |
225 | + if (UCUnits::useDevicePixelRatio) { |
226 | + return qRound(value); |
227 | } else { |
228 | - return qRound(value * ratio); |
229 | + const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX; |
230 | + if (value <= 2.0) { |
231 | + // for values under 2dp, return only multiples of the value |
232 | + return qRound(value * qFloor(ratio)); |
233 | + } else { |
234 | + return qRound(value * ratio); |
235 | + } |
236 | } |
237 | } |
238 | |
239 | @@ -107,7 +126,11 @@ |
240 | */ |
241 | float UCUnits::gu(float value) |
242 | { |
243 | - return qRound(value * m_gridUnit); |
244 | + if (UCUnits::useDevicePixelRatio) { |
245 | + return qRound(value * DEFAULT_GRID_UNIT_PX); |
246 | + } else { |
247 | + return qRound(value * m_gridUnit); |
248 | + } |
249 | } |
250 | |
251 | QString UCUnits::resolveResource(const QUrl& url) |
252 | |
253 | === modified file 'modules/Ubuntu/Components/plugin/ucunits.h' |
254 | --- modules/Ubuntu/Components/plugin/ucunits.h 2013-10-18 08:56:39 +0000 |
255 | +++ modules/Ubuntu/Components/plugin/ucunits.h 2014-03-10 17:18:58 +0000 |
256 | @@ -23,6 +23,8 @@ |
257 | #include <QtCore/QHash> |
258 | #include <QtCore/QUrl> |
259 | |
260 | +#define DEFAULT_GRID_UNIT_PX 8 |
261 | + |
262 | class UCUnits : public QObject |
263 | { |
264 | Q_OBJECT |
265 | @@ -45,6 +47,8 @@ |
266 | // setters |
267 | void setGridUnit(float gridUnit); |
268 | |
269 | + static bool useDevicePixelRatio; |
270 | + |
271 | Q_SIGNALS: |
272 | void gridUnitChanged(); |
273 | |
274 | |
275 | === modified file 'modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp' |
276 | --- modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2014-02-24 18:20:43 +0000 |
277 | +++ modules/Ubuntu/Components/plugin/unitythemeiconprovider.cpp 2014-03-10 17:18:58 +0000 |
278 | @@ -17,6 +17,7 @@ |
279 | */ |
280 | |
281 | #include "unitythemeiconprovider.h" |
282 | +#include "ucunits.h" |
283 | |
284 | #include <QIcon> |
285 | |
286 | @@ -34,8 +35,10 @@ |
287 | icon = QIcon::fromTheme(name); |
288 | if (!icon.isNull()) { |
289 | if (requestedSize.isValid()) { |
290 | - *realSize =requestedSize; |
291 | - return icon.pixmap(requestedSize); |
292 | + /* Convert from device independent pixels to pixels into actual pixels */ |
293 | + float windowPixelRatio = UCUnits::instance().gridUnit() / DEFAULT_GRID_UNIT_PX; |
294 | + *realSize = requestedSize * windowPixelRatio; |
295 | + return icon.pixmap(*realSize); |
296 | } else { |
297 | QList<QSize> sizes = icon.availableSizes(); |
298 | if (sizes.count() > 0 && sizes.last().isValid()) { |
299 | |
300 | === modified file 'tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp' |
301 | --- tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp 2013-05-06 16:33:54 +0000 |
302 | +++ tests/unit/tst_qquick_image_extension/tst_qquick_image_extension.cpp 2014-03-10 17:18:58 +0000 |
303 | @@ -18,6 +18,7 @@ |
304 | |
305 | #include <QtTest/QtTest> |
306 | #include <QtQuick/private/qquickimagebase_p.h> |
307 | +#include "ucunits.h" |
308 | |
309 | // Make protected methods of QQuickImageExtension public in order to test them |
310 | #define protected public |
311 | @@ -55,7 +56,12 @@ |
312 | void scaledBorderDouble() { |
313 | UCQQuickImageExtension image; |
314 | QString border = "border: 13"; |
315 | - QString expected = "border: 26"; |
316 | + QString expected; |
317 | + if (UCUnits::useDevicePixelRatio) { |
318 | + expected = "border: 13"; |
319 | + } else { |
320 | + expected = "border: 26"; |
321 | + } |
322 | QString result = image.scaledBorder(border, "2"); |
323 | QCOMPARE(result, expected); |
324 | } |
325 | |
326 | === modified file 'tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp' |
327 | --- tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2013-04-20 00:39:40 +0000 |
328 | +++ tests/unit/tst_scaling_image_provider/tst_scaling_image_provider.cpp 2014-03-10 17:18:58 +0000 |
329 | @@ -18,6 +18,7 @@ |
330 | |
331 | #include <QtTest/QtTest> |
332 | #include "ucscalingimageprovider.h" |
333 | +#include "ucunits.h" |
334 | |
335 | class tst_UCScalingImageProvider: public QObject |
336 | { |
337 | @@ -67,10 +68,17 @@ |
338 | QTest::newRow("downscaling, smaller width") << inputFile << "0.5" << QSize(50, 1000) << QSize(64, 128) << QSize(50, 100); |
339 | QTest::newRow("downscaling, smaller height") << inputFile << "0.5" << QSize(1000, 50) << QSize(64, 128) << QSize(25, 50); |
340 | QTest::newRow("downscaling, smaller width and height")<< inputFile << "0.5" << QSize(50, 50) << QSize(64, 128) << QSize(25, 50); |
341 | - QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512); |
342 | - QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100); |
343 | - QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50); |
344 | - QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50); |
345 | + if (UCUnits::useDevicePixelRatio) { |
346 | + QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(128, 256) << QSize(128, 256); |
347 | + QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(128, 256) << QSize(50, 100); |
348 | + QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(128, 256) << QSize(25, 50); |
349 | + QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(128, 256) << QSize(25, 50); |
350 | + } else { |
351 | + QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512); |
352 | + QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100); |
353 | + QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50); |
354 | + QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50); |
355 | + } |
356 | } |
357 | |
358 | void respectRequestedSize() { |
359 | |
360 | === modified file 'tests/unit/tst_units/tst_units.cpp' |
361 | --- tests/unit/tst_units/tst_units.cpp 2013-02-05 17:10:20 +0000 |
362 | +++ tests/unit/tst_units/tst_units.cpp 2014-03-10 17:18:58 +0000 |
363 | @@ -85,72 +85,126 @@ |
364 | QCOMPARE(units.dp(0.23), 0.0f); |
365 | QCOMPARE(units.dp(0.51), 1.0f); |
366 | QCOMPARE(units.dp(0.9999), 1.0f); |
367 | - QCOMPARE(units.dp(1000.01), 1250.0f); |
368 | + if (UCUnits::useDevicePixelRatio) { |
369 | + QCOMPARE(units.dp(1000.01), 1000.0f); |
370 | + } else { |
371 | + QCOMPARE(units.dp(1000.01), 1250.0f); |
372 | + } |
373 | } |
374 | |
375 | void guGridUnitTen() { |
376 | UCUnits units; |
377 | units.setGridUnit(10); |
378 | |
379 | - QCOMPARE(units.gu(0.5), 5.0f); |
380 | - QCOMPARE(units.gu(1), 10.0f); |
381 | - QCOMPARE(units.gu(1.5), 15.0f); |
382 | - QCOMPARE(units.gu(2), 20.0f); |
383 | - QCOMPARE(units.gu(4), 40.0f); |
384 | - QCOMPARE(units.gu(100000), 1000000.0f); |
385 | - QCOMPARE(units.gu(150.51983), 1505.0f); |
386 | + if (UCUnits::useDevicePixelRatio) { |
387 | + QCOMPARE(units.gu(0.5), 4.0f); |
388 | + QCOMPARE(units.gu(1), 8.0f); |
389 | + QCOMPARE(units.gu(1.5), 12.0f); |
390 | + QCOMPARE(units.gu(2), 16.0f); |
391 | + QCOMPARE(units.gu(4), 32.0f); |
392 | + QCOMPARE(units.gu(100000), 800000.0f); |
393 | + QCOMPARE(units.gu(150.51983), 1204.0f); |
394 | + } else { |
395 | + QCOMPARE(units.gu(0.5), 5.0f); |
396 | + QCOMPARE(units.gu(1), 10.0f); |
397 | + QCOMPARE(units.gu(1.5), 15.0f); |
398 | + QCOMPARE(units.gu(2), 20.0f); |
399 | + QCOMPARE(units.gu(4), 40.0f); |
400 | + QCOMPARE(units.gu(100000), 1000000.0f); |
401 | + QCOMPARE(units.gu(150.51983), 1505.0f); |
402 | + } |
403 | } |
404 | |
405 | void dpGridUnitSixteen() { |
406 | UCUnits units; |
407 | units.setGridUnit(16); |
408 | |
409 | - QCOMPARE(units.dp(1.0), 2.0f); |
410 | - QCOMPARE(units.dp(1.32), 3.0f); |
411 | - QCOMPARE(units.dp(1.72), 3.0f); |
412 | - QCOMPARE(units.dp(0.23), 0.0f); |
413 | - QCOMPARE(units.dp(0.51), 1.0f); |
414 | - QCOMPARE(units.dp(0.9999), 2.0f); |
415 | - QCOMPARE(units.dp(1000.01), 2000.0f); |
416 | + if (UCUnits::useDevicePixelRatio) { |
417 | + QCOMPARE(units.dp(1.0), 1.0f); |
418 | + QCOMPARE(units.dp(1.32), 1.0f); |
419 | + QCOMPARE(units.dp(1.72), 2.0f); |
420 | + QCOMPARE(units.dp(0.23), 0.0f); |
421 | + QCOMPARE(units.dp(0.51), 1.0f); |
422 | + QCOMPARE(units.dp(0.9999), 1.0f); |
423 | + QCOMPARE(units.dp(1000.01), 1000.0f); |
424 | + } else { |
425 | + QCOMPARE(units.dp(1.0), 2.0f); |
426 | + QCOMPARE(units.dp(1.32), 3.0f); |
427 | + QCOMPARE(units.dp(1.72), 3.0f); |
428 | + QCOMPARE(units.dp(0.23), 0.0f); |
429 | + QCOMPARE(units.dp(0.51), 1.0f); |
430 | + QCOMPARE(units.dp(0.9999), 2.0f); |
431 | + QCOMPARE(units.dp(1000.01), 2000.0f); |
432 | + } |
433 | } |
434 | |
435 | void guGridUnitSixteen() { |
436 | UCUnits units; |
437 | units.setGridUnit(16); |
438 | |
439 | - QCOMPARE(units.gu(0.5), 8.0f); |
440 | - QCOMPARE(units.gu(1), 16.0f); |
441 | - QCOMPARE(units.gu(1.5), 24.0f); |
442 | - QCOMPARE(units.gu(2), 32.0f); |
443 | - QCOMPARE(units.gu(4), 64.0f); |
444 | - QCOMPARE(units.gu(100000), 1600000.0f); |
445 | - QCOMPARE(units.gu(150.51983), 2408.0f); |
446 | + if (UCUnits::useDevicePixelRatio) { |
447 | + QCOMPARE(units.gu(0.5), 4.0f); |
448 | + QCOMPARE(units.gu(1), 8.0f); |
449 | + QCOMPARE(units.gu(1.5), 12.0f); |
450 | + QCOMPARE(units.gu(2), 16.0f); |
451 | + QCOMPARE(units.gu(4), 32.0f); |
452 | + QCOMPARE(units.gu(100000), 800000.0f); |
453 | + QCOMPARE(units.gu(150.51983), 1204.0f); |
454 | + } else { |
455 | + QCOMPARE(units.gu(0.5), 8.0f); |
456 | + QCOMPARE(units.gu(1), 16.0f); |
457 | + QCOMPARE(units.gu(1.5), 24.0f); |
458 | + QCOMPARE(units.gu(2), 32.0f); |
459 | + QCOMPARE(units.gu(4), 64.0f); |
460 | + QCOMPARE(units.gu(100000), 1600000.0f); |
461 | + QCOMPARE(units.gu(150.51983), 2408.0f); |
462 | + } |
463 | } |
464 | |
465 | void dpGridUnitEighteen() { |
466 | UCUnits units; |
467 | units.setGridUnit(18); |
468 | |
469 | - QCOMPARE(units.dp(1.0), 2.0f); |
470 | - QCOMPARE(units.dp(1.32), 3.0f); |
471 | - QCOMPARE(units.dp(1.72), 3.0f); |
472 | - QCOMPARE(units.dp(0.23), 0.0f); |
473 | - QCOMPARE(units.dp(0.51), 1.0f); |
474 | - QCOMPARE(units.dp(0.9999), 2.0f); |
475 | - QCOMPARE(units.dp(1000.01), 2250.0f); |
476 | + if (UCUnits::useDevicePixelRatio) { |
477 | + QCOMPARE(units.dp(1.0), 1.0f); |
478 | + QCOMPARE(units.dp(1.32), 1.0f); |
479 | + QCOMPARE(units.dp(1.72), 2.0f); |
480 | + QCOMPARE(units.dp(0.23), 0.0f); |
481 | + QCOMPARE(units.dp(0.51), 1.0f); |
482 | + QCOMPARE(units.dp(0.9999), 1.0f); |
483 | + QCOMPARE(units.dp(1000.01), 1000.0f); |
484 | + } else { |
485 | + QCOMPARE(units.dp(1.0), 2.0f); |
486 | + QCOMPARE(units.dp(1.32), 3.0f); |
487 | + QCOMPARE(units.dp(1.72), 3.0f); |
488 | + QCOMPARE(units.dp(0.23), 0.0f); |
489 | + QCOMPARE(units.dp(0.51), 1.0f); |
490 | + QCOMPARE(units.dp(0.9999), 2.0f); |
491 | + QCOMPARE(units.dp(1000.01), 2250.0f); |
492 | + } |
493 | } |
494 | |
495 | void dpGridUnitTwenty() { |
496 | UCUnits units; |
497 | units.setGridUnit(20); |
498 | |
499 | - QCOMPARE(units.dp(1.0), 2.0f); |
500 | - QCOMPARE(units.dp(1.32), 3.0f); |
501 | - QCOMPARE(units.dp(1.72), 3.0f); |
502 | - QCOMPARE(units.dp(0.23), 0.0f); |
503 | - QCOMPARE(units.dp(0.51), 1.0f); |
504 | - QCOMPARE(units.dp(0.9999), 2.0f); |
505 | - QCOMPARE(units.dp(1000.01), 2500.0f); |
506 | + if (UCUnits::useDevicePixelRatio) { |
507 | + QCOMPARE(units.dp(1.0), 1.0f); |
508 | + QCOMPARE(units.dp(1.32), 1.0f); |
509 | + QCOMPARE(units.dp(1.72), 2.0f); |
510 | + QCOMPARE(units.dp(0.23), 0.0f); |
511 | + QCOMPARE(units.dp(0.51), 1.0f); |
512 | + QCOMPARE(units.dp(0.9999), 1.0f); |
513 | + QCOMPARE(units.dp(1000.01), 1000.0f); |
514 | + } else { |
515 | + QCOMPARE(units.dp(1.0), 2.0f); |
516 | + QCOMPARE(units.dp(1.32), 3.0f); |
517 | + QCOMPARE(units.dp(1.72), 3.0f); |
518 | + QCOMPARE(units.dp(0.23), 0.0f); |
519 | + QCOMPARE(units.dp(0.51), 1.0f); |
520 | + QCOMPARE(units.dp(0.9999), 2.0f); |
521 | + QCOMPARE(units.dp(1000.01), 2500.0f); |
522 | + } |
523 | } |
524 | |
525 | void resolveEmpty() { |
The tests currently fail here:
FAIL! : qmltestrunner: :UCUnitsAPI: :test_gu( ) can use units.gu dmitry/ tests/ubuntu- ui-toolkit/ tests/unit/ tst_components/ tst_plugin_ ucunits. qml(40) ]
Actual (): 8
Expected (): 9
Loc: [/home/