Merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/dpr into lp:ubuntu-ui-toolkit/staging
- dpr
- Merge into staging
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Zsombor Egri | ||||||||||||
Approved revision: | 1205 | ||||||||||||
Merged at revision: | 1605 | ||||||||||||
Proposed branch: | lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/dpr | ||||||||||||
Merge into: | lp:ubuntu-ui-toolkit/staging | ||||||||||||
Diff against target: |
1044 lines (+747/-26) 22 files modified
debian/control (+5/-0) src/Ubuntu/Components/plugin/ucqquickimageextension.cpp (+23/-3) src/Ubuntu/Components/plugin/ucubuntushape.cpp (+17/-13) src/Ubuntu/Components/plugin/ucunits.cpp (+46/-5) src/Ubuntu/Components/plugin/ucunits.h (+1/-0) tests/unit/add_makecheck.pri (+12/-1) tests/unit/custom_qpa/README (+15/-0) tests/unit/custom_qpa/custom.json (+3/-0) tests/unit/custom_qpa/custom_qpa.pro (+15/-0) tests/unit/custom_qpa/main.cpp (+54/-0) tests/unit/custom_qpa/qcustombackingstore.cpp (+64/-0) tests/unit/custom_qpa/qcustombackingstore.h (+55/-0) tests/unit/custom_qpa/qcustomintegration.cpp (+112/-0) tests/unit/custom_qpa/qcustomintegration.h (+74/-0) tests/unit/runtest.sh (+2/-0) tests/unit/tst_units/dpr1/dpr1.pro (+3/-0) tests/unit/tst_units/dpr2/dpr2.pro (+3/-0) tests/unit/tst_units/dpr2/tst_units_dpr2.cpp (+143/-0) tests/unit/tst_units/dpr3/dpr3.pro (+3/-0) tests/unit/tst_units/dpr3/tst_units_dpr3.cpp (+88/-0) tests/unit/tst_units/tst_units.pro (+6/-3) tests/unit/unit.pro (+3/-1) |
||||||||||||
To merge this branch: | bzr merge lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/dpr | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Zsombor Egri | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Loïc Molinari (community) | Approve | ||
Gerry Boland (community) | Needs Information | ||
Review via email: mp+256470@code.launchpad.net |
This proposal supersedes a proposal from 2015-04-16.
Commit message
Compensate for Qt's device pixel ratio multiplier
Description of the change
Compensate for Qt's device pixel ratio multiplier
The UITK has flexible UI scaling support through the use of Grid Units, where one can set a grid unit to be an integer number of pixels, and the whole UI adopts to suit this. GRID_UNIT_PX=10 is the way to set this.
Qt however has its own scaling solution: QScreen:
This latter solution works for all Qt apps, whereas Grid units only apply to UITK-based apps. For a HighDPI desktop, we want to use both solutions.
However these two scaling solutions are cumulative. Should one set
QT_DEVICE_
then a box of height units.gu(1) will be drawn 32 physical pixels high.
The intention of this MR is to guarantee that GRID_UNIT_PX corresponds to physical pixels, no matter what QScreen:
To test, open the gallery with these 2 different envs:
QT_DEVICE_
QT_DEVICE_
Some visual inconsistencies at small GU values are due to exact font rendering sizes and some rounding issues causing off-by-one positioning errors. QT_DEVICE_
PS Jenkins bot (ps-jenkins) wrote : | # |
Gerry Boland (gerboland) wrote : | # |
Ok, think this is ready for review. I added tests where I could, but would appreciate feedback on how I could test more.
Gerry Boland (gerboland) wrote : | # |
+++ modules/
+ float devicePixelRatio() const;
should I worry about ABI breaking?
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1179
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
UNSTABLE: http://
deb: http://
FAILURE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1180
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
FAILURE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1180
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1180
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Loïc Molinari (loic.molinari) wrote : | # |
Just a quick comment before going deeper in the review, the ProgressBar is broken because ucubuntushapeov
Gerry Boland (gerboland) wrote : | # |
Thanks for the initial look, no idea how I missed that overlay issue, it's fixed now
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1182
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Loïc Molinari (loic.molinari) wrote : | # |
> +++ modules/
> + float devicePixelRatio() const;
> should I worry about ABI breaking?
No worries, it's not an ABI break. And actually we don't care about ABI breaks since we don't export the shared object as a lib.
Loïc Molinari (loic.molinari) wrote : | # |
> > +++ modules/
> > + float devicePixelRatio() const;
> > should I worry about ABI breaking?
>
> No worries, it's not an ABI break. And actually we don't care about ABI
> breaks since we don't export the shared object as a lib.
(Thinking about it the added floating-point value in the class would be an ABI break if we'd expose the lib)
Loïc Molinari (loic.molinari) wrote : | # |
Good stuff. Here is a bunch of questions and remarks.
1)
In the shape, storing the radius as device-independent pixel like that
- float radius = UCUnits:
- const float scaledDownRadius = qMin(itemSize.
+ float radius = UCUnits:
+ const float scaledDownRadius = qMin(itemSize.
would remove the need to multiply the item size by the dpr for the shape coordinates attributes in updateVertices() (for both UbuntuShape and UbuntuShapeOver
@@ -1217,16 +1218,18 @@
}
+ const float physicalRadius = UCUnits:
+
// Mapping of radius size range from [0, 4] to [0, 1] with clamping, plus quantization.
const float start = 0.0f + radiusSizeOffset;
const float end = 4.0f + radiusSizeOffset;
materialDa
- (radius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f;
+ (physicalRadius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f;
// When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is
// flagged so that a dedicated (statically flow controlled) shaved off shader can be used for
// optimal performance.
- if (radius > radiusSizeOffset) {
+ if (physicalRadius > radiusSizeOffset) {
const quint8 aspectFlags[] = {
2) The previous change would allow to move the devicePixelRatio retrieval in updateGeometryN
3)
- Q_INVOKABLE float dp(float value);
- Q_INVOKABLE float gu(float value);
+ Q_INVOKABLE float dp(const float value);
+ Q_INVOKABLE float gu(const float value);
Using const for value parameters (not for reference or pointer parameters) isn't a common practice in the toolkit (neither in Qt AFAIK). Is there a particular reason for it?
4) Wouldn't it be better (faster) to inline UCUnits:
5) Talking about UCUnits:
6) UCUnits::gu() and UCUnits:dp() returns "qRound(value * m_gridUnit) / m_devicePixelRa
7) It took me some time to figure out the logic because I didn't realize we had to support QtWidgets as well. I think we'd better explain the whole decision somewhere in the project, either in the README or in the UCUnits module. I'd tend to go for a good explanation in the ucunits.cpp module documentation maybe adding toolkit implementation...
Gerry Boland (gerboland) wrote : | # |
> Good stuff. Here is a bunch of questions and remarks.
>
> 1)
> In the shape, storing the radius as device-independent pixel like that
>
> - float radius = UCUnits:
> smallRadiusGU : mediumRadiusGU);
> - const float scaledDownRadius = qMin(itemSize.
> * dpr * 0.5f * 0.8f;
> + float radius = UCUnits:
> : mediumRadiusGU));
> + const float scaledDownRadius = qMin(itemSize.
> * 0.5f * 0.8f;
>
> would remove the need to multiply the item size by the dpr for the shape
> coordinates attributes in updateVertices() (for both UbuntuShape and
> UbuntuShapeOver
> but in a less intrusive way IMO:
<snip>
Done!
> 2) The previous change would allow to move the devicePixelRatio retrieval in
> updateGeometryN
Done
> 3)
> - Q_INVOKABLE float dp(float value);
> - Q_INVOKABLE float gu(float value);
> + Q_INVOKABLE float dp(const float value);
> + Q_INVOKABLE float gu(const float value);
>
> Using const for value parameters (not for reference or pointer parameters)
> isn't a common practice in the toolkit (neither in Qt AFAIK). Is there a
> particular reason for it?
I had thought compiler could optimize a little better with this, but I'm told it's of no use. Reverted.
> 4) Wouldn't it be better (faster) to inline UCUnits:
> definition in the header?
>
> 5) Talking about UCUnits:
> instead of using QGuiApplication
> QWindow:
> of QT_DEVICE_
Yeah I got rid of this. I had mainly added it to UCUnits to ease mocking it for testing. Instead I've added a custom minimal QPA plugin to mock the value of devicePixelRatio(). So UCUnits API has be left unchanged by this MR.
>
> 6) UCUnits::gu() and UCUnits:dp() returns "qRound(value * m_gridUnit) /
> m_devicePixelRa
> the rounding?
I left the division after the rounding as Qt will take this value, multiply it by devicePixelRatio to calculate the physical pixels. I.e.
physicalPixels = [qRound(value * m_gridUnit) / m_devicePixelRatio] * m_devicePixelRatio
should be more correct than
physicalPixels = qRound(value * m_gridUnit / m_devicePixelRatio) * m_devicePixelRatio
> 7) It took me some time to figure out the logic because I didn't realize we
> had to support QtWidgets as well. I think we'd better explain the whole
> decision somewhere in the project, either in the README or in the UCUnits
> module. I'd tend to go for a good explanation in the ucunits.cpp module
> documentation maybe adding toolkit implementation details in there in a "non-
> exposed" comment if needed. We should also agree on a better naming for the
> units, currently there are grid units, device pixels, value density
> independent pixels, actual pixels, physical pixels, etc, it's very confusing.
> I...
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1194
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1195. By Gerry Boland
-
Add missing build dependencies
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1195
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1196. By Gerry Boland
-
Bump version
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1196
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1197. By Gerry Boland
-
Merge staging and fix conflicts
- 1198. By Gerry Boland
-
Revert rev 1196
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1197
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1198
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1199. By Gerry Boland
-
Merge staging, fix a conflict
- 1200. By Gerry Boland
-
Undo changes to paths for gallery launcher
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1200
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 1201. By Gerry Boland
-
Merge staging
Zsombor Egri (zsombi) wrote : | # |
Small fixes, and we're good.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:1201
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Loïc Molinari (loic.molinari) wrote : | # |
I guess there's a merge problem, m_relativeRadius is defined two times in UCUbuntuShape initialisation list. Apart from that, everything looks good to me now.
Thanks for the changes and sorry for the delay to take a look back at that...
- 1202. By Gerry Boland
-
Fix build fail - variable inited twice
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1202
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 1203. By Gerry Boland
-
Merge staging again
- 1204. By Gerry Boland
-
Merge staging again
- 1205. By Gerry Boland
-
Revert accidental changes to examples/
ubuntu- ui-toolkit- gallery/ po/nl.po
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1205
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : | # |
Good to go now! Thanks allot!
Preview Diff
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2015-07-10 05:40:21 +0000 | |||
3 | +++ debian/control 2015-08-12 11:28:41 +0000 | |||
4 | @@ -45,6 +45,11 @@ | |||
5 | 45 | suru-icon-theme, | 45 | suru-icon-theme, |
6 | 46 | uuid-runtime, | 46 | uuid-runtime, |
7 | 47 | python3-sphinx, | 47 | python3-sphinx, |
8 | 48 | libfontconfig1-dev, | ||
9 | 49 | libfreetype6-dev, | ||
10 | 50 | libmtdev-dev, | ||
11 | 51 | libudev-dev, | ||
12 | 52 | libxrender-dev | ||
13 | 48 | Standards-Version: 3.9.4 | 53 | Standards-Version: 3.9.4 |
14 | 49 | Homepage: https://launchpad.net/ubuntu-ui-toolkit | 54 | Homepage: https://launchpad.net/ubuntu-ui-toolkit |
15 | 50 | # If you aren't a member of ~ubuntu-sdk-team but need to upload packaging | 55 | # If you aren't a member of ~ubuntu-sdk-team but need to upload packaging |
16 | 51 | 56 | ||
17 | === modified file 'src/Ubuntu/Components/plugin/ucqquickimageextension.cpp' | |||
18 | --- src/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2014-11-24 13:14:35 +0000 | |||
19 | +++ src/Ubuntu/Components/plugin/ucqquickimageextension.cpp 2015-08-12 11:28:41 +0000 | |||
20 | @@ -19,6 +19,7 @@ | |||
21 | 19 | #include <QtCore/QFile> | 19 | #include <QtCore/QFile> |
22 | 20 | #include <QtCore/QFileInfo> | 20 | #include <QtCore/QFileInfo> |
23 | 21 | #include <QtCore/QDir> | 21 | #include <QtCore/QDir> |
24 | 22 | #include <QtGui/QGuiApplication> | ||
25 | 22 | #include <QtQuick/private/qquickimagebase_p.h> | 23 | #include <QtQuick/private/qquickimagebase_p.h> |
26 | 23 | 24 | ||
27 | 24 | #include "ucqquickimageextension.h" | 25 | #include "ucqquickimageextension.h" |
28 | @@ -78,8 +79,18 @@ | |||
29 | 78 | QString selectedFilePath = resolved.mid(separatorPosition+1); | 79 | QString selectedFilePath = resolved.mid(separatorPosition+1); |
30 | 79 | 80 | ||
31 | 80 | if (scaleFactor == "1") { | 81 | if (scaleFactor == "1") { |
34 | 81 | // No scaling. Just pass the file as is. | 82 | if (qFuzzyCompare(qGuiApp->devicePixelRatio(), (qreal)1.0) |
35 | 82 | m_image->setSource(QUrl::fromLocalFile(selectedFilePath)); | 83 | || selectedFilePath.endsWith(".svg") || selectedFilePath.endsWith(".svgz")) { |
36 | 84 | // No scaling necessary. Just pass the file as is. | ||
37 | 85 | m_image->setSource(QUrl::fromLocalFile(selectedFilePath)); | ||
38 | 86 | } else { | ||
39 | 87 | // Need to scale the pixel-based image to suit the devicePixelRatio setting ourselves. | ||
40 | 88 | // If we let Qt do it, Qt will not choose the UITK-supported "@gu" scaled images. | ||
41 | 89 | m_image->setSource(QUrl("image://scaling/1/" + selectedFilePath)); | ||
42 | 90 | // explicitly set the source size in the QQuickImageBase, this persuades it that the | ||
43 | 91 | // supplied image is suitable for the current devicePixelRatio. | ||
44 | 92 | m_image->setSourceSize(m_image->sourceSize()); | ||
45 | 93 | } | ||
46 | 83 | } else { | 94 | } else { |
47 | 84 | // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider. | 95 | // Prepend "image://scaling" for the image to be loaded by UCScalingImageProvider. |
48 | 85 | if (!m_source.path().endsWith(".sci")) { | 96 | if (!m_source.path().endsWith(".sci")) { |
49 | @@ -100,7 +111,13 @@ | |||
50 | 100 | rewrittenSciFile->setFileTemplate(QDir::tempPath() + QDir::separator() + "XXXXXX.sci"); | 111 | rewrittenSciFile->setFileTemplate(QDir::tempPath() + QDir::separator() + "XXXXXX.sci"); |
51 | 101 | rewrittenSciFile->open(); | 112 | rewrittenSciFile->open(); |
52 | 102 | QTextStream output(rewrittenSciFile); | 113 | QTextStream output(rewrittenSciFile); |
54 | 103 | rewritten = rewriteSciFile(selectedFilePath, scaleFactor, output); | 114 | |
55 | 115 | if (qFuzzyCompare(qGuiApp->devicePixelRatio(), (qreal)1.0)) { | ||
56 | 116 | rewritten = rewriteSciFile(selectedFilePath, scaleFactor, output); | ||
57 | 117 | } else { | ||
58 | 118 | QString scaleFactorInDevicePixels = QString::number(scaleFactor.toFloat() / qGuiApp->devicePixelRatio()); | ||
59 | 119 | rewritten = rewriteSciFile(selectedFilePath, scaleFactorInDevicePixels, output); | ||
60 | 120 | } | ||
61 | 104 | rewrittenSciFile->close(); | 121 | rewrittenSciFile->close(); |
62 | 105 | 122 | ||
63 | 106 | s_rewrittenSciFiles.insert(m_source, QSharedPointer<QTemporaryFile>(rewrittenSciFile)); | 123 | s_rewrittenSciFiles.insert(m_source, QSharedPointer<QTemporaryFile>(rewrittenSciFile)); |
64 | @@ -112,6 +129,9 @@ | |||
65 | 112 | m_image->setSource(m_source); | 129 | m_image->setSource(m_source); |
66 | 113 | } | 130 | } |
67 | 114 | } | 131 | } |
68 | 132 | // explicitly set the source size in the QQuickImageBase, this persuades it that the | ||
69 | 133 | // supplied image is suitable for the current devicePixelRatio. | ||
70 | 134 | m_image->setSourceSize(m_image->sourceSize()); | ||
71 | 115 | } | 135 | } |
72 | 116 | } | 136 | } |
73 | 117 | 137 | ||
74 | 118 | 138 | ||
75 | === modified file 'src/Ubuntu/Components/plugin/ucubuntushape.cpp' | |||
76 | --- src/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-08-06 13:16:24 +0000 | |||
77 | +++ src/Ubuntu/Components/plugin/ucubuntushape.cpp 2015-08-12 11:28:41 +0000 | |||
78 | @@ -308,10 +308,7 @@ | |||
79 | 308 | setFlag(ItemHasContents); | 308 | setFlag(ItemHasContents); |
80 | 309 | QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this, | 309 | QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), this, |
81 | 310 | SLOT(_q_gridUnitChanged())); | 310 | SLOT(_q_gridUnitChanged())); |
86 | 311 | const float gridUnit = UCUnits::instance().gridUnit(); | 311 | _q_gridUnitChanged(); |
83 | 312 | setImplicitWidth(implicitWidthGU * gridUnit); | ||
84 | 313 | setImplicitHeight(implicitHeightGU * gridUnit); | ||
85 | 314 | update(); | ||
87 | 315 | } | 312 | } |
88 | 316 | 313 | ||
89 | 317 | /*! \qmlproperty string UbuntuShape::radius | 314 | /*! \qmlproperty string UbuntuShape::radius |
90 | @@ -998,9 +995,9 @@ | |||
91 | 998 | 995 | ||
92 | 999 | void UCUbuntuShape::_q_gridUnitChanged() | 996 | void UCUbuntuShape::_q_gridUnitChanged() |
93 | 1000 | { | 997 | { |
97 | 1001 | const float gridUnit = UCUnits::instance().gridUnit(); | 998 | const float gridUnitInDevicePixels = UCUnits::instance().gridUnit() / qGuiApp->devicePixelRatio(); |
98 | 1002 | setImplicitWidth(implicitWidthGU * gridUnit); | 999 | setImplicitWidth(implicitWidthGU * gridUnitInDevicePixels); |
99 | 1003 | setImplicitHeight(implicitHeightGU * gridUnit); | 1000 | setImplicitHeight(implicitHeightGU * gridUnitInDevicePixels); |
100 | 1004 | update(); | 1001 | update(); |
101 | 1005 | } | 1002 | } |
102 | 1006 | 1003 | ||
103 | @@ -1162,13 +1159,15 @@ | |||
104 | 1162 | sourceTextureRect = sourceTexture->normalizedTextureSubRect(); | 1159 | sourceTextureRect = sourceTexture->normalizedTextureSubRect(); |
105 | 1163 | } | 1160 | } |
106 | 1164 | if (m_flags & DirtySourceTransform) { | 1161 | if (m_flags & DirtySourceTransform) { |
107 | 1162 | const float dpr = qGuiApp->devicePixelRatio(); | ||
108 | 1163 | |||
109 | 1165 | if (m_flags & SourceApiSet) { | 1164 | if (m_flags & SourceApiSet) { |
111 | 1166 | updateSourceTransform(itemSize.width(), itemSize.height(), m_sourceFillMode, | 1165 | updateSourceTransform(itemSize.width() * dpr, itemSize.height() * dpr, m_sourceFillMode, |
112 | 1167 | m_sourceHorizontalAlignment, m_sourceVerticalAlignment, | 1166 | m_sourceHorizontalAlignment, m_sourceVerticalAlignment, |
113 | 1168 | sourceTexture->textureSize()); | 1167 | sourceTexture->textureSize()); |
114 | 1169 | } else { | 1168 | } else { |
115 | 1170 | FillMode imageFillMode = (m_flags & Stretched) ? Stretch : PreserveAspectCrop; | 1169 | FillMode imageFillMode = (m_flags & Stretched) ? Stretch : PreserveAspectCrop; |
117 | 1171 | updateSourceTransform(itemSize.width(), itemSize.height(), imageFillMode, | 1170 | updateSourceTransform(itemSize.width() * dpr, itemSize.height() * dpr, imageFillMode, |
118 | 1172 | m_imageHorizontalAlignment, m_imageVerticalAlignment, | 1171 | m_imageHorizontalAlignment, m_imageVerticalAlignment, |
119 | 1173 | sourceTexture->textureSize()); | 1172 | sourceTexture->textureSize()); |
120 | 1174 | } | 1173 | } |
121 | @@ -1198,13 +1197,15 @@ | |||
122 | 1198 | // accordingly. The shape was using a fixed image for the corner before switching to a | 1197 | // accordingly. The shape was using a fixed image for the corner before switching to a |
123 | 1199 | // distance field, since the corner wasn't taking the whole image (ending at ~80%) we need | 1198 | // distance field, since the corner wasn't taking the whole image (ending at ~80%) we need |
124 | 1200 | // to take that into account when the size is scaled down. | 1199 | // to take that into account when the size is scaled down. |
126 | 1201 | radius = UCUnits::instance().gridUnit() * radiusGuMap[m_radius]; | 1200 | radius = UCUnits::instance().gridUnit() * radiusGuMap[m_radius] |
127 | 1201 | / qGuiApp->devicePixelRatio(); | ||
128 | 1202 | const float scaledDownRadius = qMin(itemSize.width(), itemSize.height()) * 0.5f * 0.8f; | 1202 | const float scaledDownRadius = qMin(itemSize.width(), itemSize.height()) * 0.5f * 0.8f; |
129 | 1203 | if (radius > scaledDownRadius) { | 1203 | if (radius > scaledDownRadius) { |
130 | 1204 | radius = scaledDownRadius; | 1204 | radius = scaledDownRadius; |
131 | 1205 | } | 1205 | } |
132 | 1206 | } else { | 1206 | } else { |
134 | 1207 | radius = qMin(itemSize.width(), itemSize.height()) * 0.5f * (m_relativeRadius * 0.01f); | 1207 | radius = qMin(itemSize.width(), itemSize.height()) * 0.5f * (m_relativeRadius * 0.01f) |
135 | 1208 | / qGuiApp->devicePixelRatio(); | ||
136 | 1208 | } | 1209 | } |
137 | 1209 | 1210 | ||
138 | 1210 | updateMaterial(node, radius, shapeTextureId, sourceTexture && m_sourceOpacity); | 1211 | updateMaterial(node, radius, shapeTextureId, sourceTexture && m_sourceOpacity); |
139 | @@ -1284,16 +1285,19 @@ | |||
140 | 1284 | materialData->sourceOpacity = 0; | 1285 | materialData->sourceOpacity = 0; |
141 | 1285 | } | 1286 | } |
142 | 1286 | 1287 | ||
143 | 1288 | const float physicalRadius = radius * qGuiApp->devicePixelRatio(); | ||
144 | 1289 | |||
145 | 1287 | // Mapping of radius size range from [0, 4] to [0, 1] with clamping, plus quantization. | 1290 | // Mapping of radius size range from [0, 4] to [0, 1] with clamping, plus quantization. |
146 | 1288 | const float start = 0.0f + radiusSizeOffset; | 1291 | const float start = 0.0f + radiusSizeOffset; |
147 | 1289 | const float end = 4.0f + radiusSizeOffset; | 1292 | const float end = 4.0f + radiusSizeOffset; |
148 | 1293 | |||
149 | 1290 | materialData->distanceAAFactor = | 1294 | materialData->distanceAAFactor = |
151 | 1291 | qMin((radius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f; | 1295 | qMin((physicalRadius / (end - start)) - (start / (end - start)), 1.0f) * 255.0f; |
152 | 1292 | 1296 | ||
153 | 1293 | // When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is | 1297 | // When the radius is equal to radiusSizeOffset (which means radius size is 0), no aspect is |
154 | 1294 | // flagged so that a dedicated (statically flow controlled) shaved off shader can be used for | 1298 | // flagged so that a dedicated (statically flow controlled) shaved off shader can be used for |
155 | 1295 | // optimal performance. | 1299 | // optimal performance. |
157 | 1296 | if (radius > radiusSizeOffset) { | 1300 | if (physicalRadius > radiusSizeOffset) { |
158 | 1297 | const quint8 aspectFlags[] = { | 1301 | const quint8 aspectFlags[] = { |
159 | 1298 | ShapeMaterial::Data::Flat, ShapeMaterial::Data::Inset, ShapeMaterial::Data::DropShadow, | 1302 | ShapeMaterial::Data::Flat, ShapeMaterial::Data::Inset, ShapeMaterial::Data::DropShadow, |
160 | 1299 | ShapeMaterial::Data::Inset | ShapeMaterial::Data::Pressed | 1303 | ShapeMaterial::Data::Inset | ShapeMaterial::Data::Pressed |
161 | 1300 | 1304 | ||
162 | === modified file 'src/Ubuntu/Components/plugin/ucunits.cpp' | |||
163 | --- src/Ubuntu/Components/plugin/ucunits.cpp 2015-03-03 13:47:48 +0000 | |||
164 | +++ src/Ubuntu/Components/plugin/ucunits.cpp 2015-08-12 11:28:41 +0000 | |||
165 | @@ -24,6 +24,8 @@ | |||
166 | 24 | #include <QtCore/QDir> | 24 | #include <QtCore/QDir> |
167 | 25 | #include <QtCore/QRegularExpression> | 25 | #include <QtCore/QRegularExpression> |
168 | 26 | #include <QtCore/qmath.h> | 26 | #include <QtCore/qmath.h> |
169 | 27 | #include <QtGui/QGuiApplication> | ||
170 | 28 | #include <QtGui/QScreen> | ||
171 | 27 | 29 | ||
172 | 28 | #define ENV_GRID_UNIT_PX "GRID_UNIT_PX" | 30 | #define ENV_GRID_UNIT_PX "GRID_UNIT_PX" |
173 | 29 | #define DEFAULT_GRID_UNIT_PX 8 | 31 | #define DEFAULT_GRID_UNIT_PX 8 |
174 | @@ -62,10 +64,46 @@ | |||
175 | 62 | 64 | ||
176 | 63 | \sa {Resolution Independence} | 65 | \sa {Resolution Independence} |
177 | 64 | */ | 66 | */ |
178 | 67 | |||
179 | 68 | /* | ||
180 | 69 | * Note on the interaction between GRID_UNIT_PX and QT_DEVICE_PIXEL_RATIO | ||
181 | 70 | * | ||
182 | 71 | * In Qt5.4 there is a single means to scale the UI: the QT_DEVICE_PIXEL_RATIO environment | ||
183 | 72 | * variable. This accepts only integer values, thus allowing a x2 or x3 scaling of any | ||
184 | 73 | * Qt-based UI, that includes QWidget as well as any QML UI. | ||
185 | 74 | * | ||
186 | 75 | * Setting QT_DEVICE_PIXEL_RATIO=2 implies one density-independent pixel corresponds to 2 | ||
187 | 76 | * physical pixels. Developers describe their UI in terms of density-independent pixels. | ||
188 | 77 | * Qt scales accordingly. | ||
189 | 78 | * | ||
190 | 79 | * The Ubuntu UI Toolkit has solved the scaling problem with the GRID_UNIT_PX variable. | ||
191 | 80 | * It offers more flexibility, but only scales QML applications written to use the UITK | ||
192 | 81 | * (since it uses this Units class) as it is built on top of QML. | ||
193 | 82 | * | ||
194 | 83 | * There are additional areas in Qt where QT_DEVICE_PIXEL_RATIO causes correct scaling which | ||
195 | 84 | * GRID_UNIT_PX cannot, for example: | ||
196 | 85 | * 1. cacheBuffer for ListView/GridViews - specified in density-independent pixels | ||
197 | 86 | * 2. gesture recognition matches what is on screen better, as it is density-independent | ||
198 | 87 | * pixel aware | ||
199 | 88 | * | ||
200 | 89 | * In order to get the best of both worlds, Ubuntu will set both GRID_UNIT_PX and | ||
201 | 90 | * QT_DEVICE_PIXEL_RATIO. Thus all Qt apps will scale reasonably well, with UITK-based apps | ||
202 | 91 | * scaling perfectly for any desired scale (i.e. non-integer scales). | ||
203 | 92 | * | ||
204 | 93 | * However UITK developers can just use this Units class as usual, and will be almost totally | ||
205 | 94 | * isolated from Qt's own scaling concept. | ||
206 | 95 | */ | ||
207 | 96 | |||
208 | 65 | UCUnits::UCUnits(QObject *parent) : | 97 | UCUnits::UCUnits(QObject *parent) : |
210 | 66 | QObject(parent) | 98 | QObject(parent), |
211 | 99 | m_devicePixelRatio(qGuiApp->devicePixelRatio()) | ||
212 | 67 | { | 100 | { |
214 | 68 | m_gridUnit = getenvFloat(ENV_GRID_UNIT_PX, DEFAULT_GRID_UNIT_PX); | 101 | // If GRID_UNIT_PX set, always use it. If not, 1GU := DEFAULT_GRID_UNIT_PX * m_devicePixelRatio |
215 | 102 | if (qEnvironmentVariableIsSet(ENV_GRID_UNIT_PX)) { | ||
216 | 103 | m_gridUnit = getenvFloat(ENV_GRID_UNIT_PX, DEFAULT_GRID_UNIT_PX); | ||
217 | 104 | } else { | ||
218 | 105 | m_gridUnit = DEFAULT_GRID_UNIT_PX * m_devicePixelRatio; | ||
219 | 106 | } | ||
220 | 69 | } | 107 | } |
221 | 70 | 108 | ||
222 | 71 | /*! | 109 | /*! |
223 | @@ -89,14 +127,15 @@ | |||
224 | 89 | 127 | ||
225 | 90 | Returns the number of pixels \a value density independent pixels correspond to. | 128 | Returns the number of pixels \a value density independent pixels correspond to. |
226 | 91 | */ | 129 | */ |
227 | 130 | // Density-independent pixels (and not physical pixels) because Qt sizes in terms of density-independent pixels. | ||
228 | 92 | float UCUnits::dp(float value) | 131 | float UCUnits::dp(float value) |
229 | 93 | { | 132 | { |
230 | 94 | const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX; | 133 | const float ratio = m_gridUnit / DEFAULT_GRID_UNIT_PX; |
231 | 95 | if (value <= 2.0) { | 134 | if (value <= 2.0) { |
232 | 96 | // for values under 2dp, return only multiples of the value | 135 | // for values under 2dp, return only multiples of the value |
234 | 97 | return qRound(value * qFloor(ratio)); | 136 | return qRound(value * qFloor(ratio)) / m_devicePixelRatio; |
235 | 98 | } else { | 137 | } else { |
237 | 99 | return qRound(value * ratio); | 138 | return qRound(value * ratio) / m_devicePixelRatio; |
238 | 100 | } | 139 | } |
239 | 101 | } | 140 | } |
240 | 102 | 141 | ||
241 | @@ -105,9 +144,11 @@ | |||
242 | 105 | 144 | ||
243 | 106 | Returns the number of pixels \a value grid units correspond to. | 145 | Returns the number of pixels \a value grid units correspond to. |
244 | 107 | */ | 146 | */ |
245 | 147 | // Density-independent pixels (and not physical pixels) because Qt sizes in terms of density-independent pixels. | ||
246 | 148 | |||
247 | 108 | float UCUnits::gu(float value) | 149 | float UCUnits::gu(float value) |
248 | 109 | { | 150 | { |
250 | 110 | return qRound(value * m_gridUnit); | 151 | return qRound(value * m_gridUnit) / m_devicePixelRatio; |
251 | 111 | } | 152 | } |
252 | 112 | 153 | ||
253 | 113 | QString UCUnits::resolveResource(const QUrl& url) | 154 | QString UCUnits::resolveResource(const QUrl& url) |
254 | 114 | 155 | ||
255 | === modified file 'src/Ubuntu/Components/plugin/ucunits.h' | |||
256 | --- src/Ubuntu/Components/plugin/ucunits.h 2013-10-18 08:56:39 +0000 | |||
257 | +++ src/Ubuntu/Components/plugin/ucunits.h 2015-08-12 11:28:41 +0000 | |||
258 | @@ -53,6 +53,7 @@ | |||
259 | 53 | float gridUnitSuffixFromFileName(const QString &fileName); | 53 | float gridUnitSuffixFromFileName(const QString &fileName); |
260 | 54 | 54 | ||
261 | 55 | private: | 55 | private: |
262 | 56 | float m_devicePixelRatio; | ||
263 | 56 | float m_gridUnit; | 57 | float m_gridUnit; |
264 | 57 | }; | 58 | }; |
265 | 58 | 59 | ||
266 | 59 | 60 | ||
267 | === modified file 'tests/unit/add_makecheck.pri' | |||
268 | --- tests/unit/add_makecheck.pri 2015-05-19 07:55:27 +0000 | |||
269 | +++ tests/unit/add_makecheck.pri 2015-08-12 11:28:41 +0000 | |||
270 | @@ -5,4 +5,15 @@ | |||
271 | 5 | check.target = check | 5 | check.target = check |
272 | 6 | check.commands += cd $$_PRO_FILE_PWD_; | 6 | check.commands += cd $$_PRO_FILE_PWD_; |
273 | 7 | check.commands += env LD_LIBRARY_PATH=$${ROOT_BUILD_DIR}/qml/Ubuntu/Components:$${ROOT_BUILD_DIR}/qml/Ubuntu/Layouts:$${ROOT_BUILD_DIR}/qml/Ubuntu/PerformanceMetrics:$${ROOT_BUILD_DIR}/qml/Ubuntu/Test UITK_TEST_KEEP_RUNNING=1 | 7 | check.commands += env LD_LIBRARY_PATH=$${ROOT_BUILD_DIR}/qml/Ubuntu/Components:$${ROOT_BUILD_DIR}/qml/Ubuntu/Layouts:$${ROOT_BUILD_DIR}/qml/Ubuntu/PerformanceMetrics:$${ROOT_BUILD_DIR}/qml/Ubuntu/Test UITK_TEST_KEEP_RUNNING=1 |
275 | 8 | check.commands += '$${ROOT_SOURCE_DIR}/tests/unit/runtest.sh "$$shadowed($$_PRO_FILE_PWD_)/$${TARGET}" "$$shadowed($$_PRO_FILE_PWD_)/$${TARGET}" minimal'; | 8 | |
276 | 9 | TEST_COMMAND = '$${ROOT_SOURCE_DIR}/tests/unit/runtest.sh "$$shadowed($$_PRO_FILE_PWD_)/$${TARGET}" "$$shadowed($$_PRO_FILE_PWD_)/$${TARGET}"' | ||
277 | 10 | |||
278 | 11 | message($$TEST_COMMAND) | ||
279 | 12 | |||
280 | 13 | # if "CONFIG += custom_qpa" is set, use our custom QPA plugin for the test | ||
281 | 14 | custom_qpa { | ||
282 | 15 | check.commands += env QT_QPA_PLATFORM_PLUGIN_PATH=$${ROOT_BUILD_DIR}/tests/unit/custom_qpa | ||
283 | 16 | check.commands += '$$TEST_COMMAND custom'; | ||
284 | 17 | } else { | ||
285 | 18 | check.commands += '$$TEST_COMMAND minimal'; | ||
286 | 19 | } | ||
287 | 9 | 20 | ||
288 | === added directory 'tests/unit/custom_qpa' | |||
289 | === added file 'tests/unit/custom_qpa/README' | |||
290 | --- tests/unit/custom_qpa/README 1970-01-01 00:00:00 +0000 | |||
291 | +++ tests/unit/custom_qpa/README 2015-08-12 11:28:41 +0000 | |||
292 | @@ -0,0 +1,15 @@ | |||
293 | 1 | In order to correctly test Qt's Device Pixel Ratio system in a | ||
294 | 2 | unit test, one needs to have the QPA plugin for the platform | ||
295 | 3 | support reading the DEVICE_PIXEL_RATIO environment variable. | ||
296 | 4 | |||
297 | 5 | These unit tests use the "minimal" QPA plugin, which | ||
298 | 6 | unfortunately does not support that variable. | ||
299 | 7 | |||
300 | 8 | The contents of this directory is a near-complete duplicate of | ||
301 | 9 | "minimal" QPA plugin source from Qt, with added support for the | ||
302 | 10 | DEVICE_PIXEL_RATIO environment variable. | ||
303 | 11 | |||
304 | 12 | One can use this plugin as follows: | ||
305 | 13 | |||
306 | 14 | DEVICE_PIXEL_RATIO=2 QT_QPA_PLATFORM_PLUGIN_PATH=$PWD \ | ||
307 | 15 | QT_QPA_PLATFORM=custom qmlscene ~/tmp.qml | ||
308 | 0 | 16 | ||
309 | === added file 'tests/unit/custom_qpa/custom.json' | |||
310 | --- tests/unit/custom_qpa/custom.json 1970-01-01 00:00:00 +0000 | |||
311 | +++ tests/unit/custom_qpa/custom.json 2015-08-12 11:28:41 +0000 | |||
312 | @@ -0,0 +1,3 @@ | |||
313 | 1 | { | ||
314 | 2 | "Keys": [ "custom" ] | ||
315 | 3 | } | ||
316 | 0 | 4 | ||
317 | === added file 'tests/unit/custom_qpa/custom_qpa.pro' | |||
318 | --- tests/unit/custom_qpa/custom_qpa.pro 1970-01-01 00:00:00 +0000 | |||
319 | +++ tests/unit/custom_qpa/custom_qpa.pro 2015-08-12 11:28:41 +0000 | |||
320 | @@ -0,0 +1,15 @@ | |||
321 | 1 | TARGET = qcustom | ||
322 | 2 | TEMPLATE = lib | ||
323 | 3 | |||
324 | 4 | CONFIG += plugin no_keywords c++11 | ||
325 | 5 | |||
326 | 6 | QT -= gui | ||
327 | 7 | QT += core-private gui-private platformsupport-private | ||
328 | 8 | |||
329 | 9 | SOURCES = main.cpp \ | ||
330 | 10 | qcustomintegration.cpp \ | ||
331 | 11 | qcustombackingstore.cpp | ||
332 | 12 | HEADERS = qcustomintegration.h \ | ||
333 | 13 | qcustombackingstore.h | ||
334 | 14 | |||
335 | 15 | OTHER_FILES += custom.json | ||
336 | 0 | 16 | ||
337 | === added file 'tests/unit/custom_qpa/main.cpp' | |||
338 | --- tests/unit/custom_qpa/main.cpp 1970-01-01 00:00:00 +0000 | |||
339 | +++ tests/unit/custom_qpa/main.cpp 2015-08-12 11:28:41 +0000 | |||
340 | @@ -0,0 +1,54 @@ | |||
341 | 1 | /**************************************************************************** | ||
342 | 2 | ** | ||
343 | 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | ||
344 | 4 | ** Contact: http://www.qt-project.org/legal | ||
345 | 5 | ** | ||
346 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
347 | 7 | ** | ||
348 | 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | ||
349 | 9 | ** Commercial License Usage | ||
350 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
351 | 11 | ** accordance with the commercial license agreement provided with the | ||
352 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
353 | 13 | ** a written agreement between you and Digia. For licensing terms and | ||
354 | 14 | ** conditions see http://qt.digia.com/licensing. For further information | ||
355 | 15 | ** use the contact form at http://qt.digia.com/contact-us. | ||
356 | 16 | ** | ||
357 | 17 | ** GNU Lesser General Public License Usage | ||
358 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
359 | 19 | ** General Public License version 2.1 or version 3 as published by the Free | ||
360 | 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | ||
361 | 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | ||
362 | 22 | ** following information to ensure the GNU Lesser General Public License | ||
363 | 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | ||
364 | 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
365 | 25 | ** | ||
366 | 26 | ** In addition, as a special exception, Digia gives you certain additional | ||
367 | 27 | ** rights. These rights are described in the Digia Qt LGPL Exception | ||
368 | 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
369 | 29 | ** | ||
370 | 30 | ** $QT_END_LICENSE$ | ||
371 | 31 | ** | ||
372 | 32 | ****************************************************************************/ | ||
373 | 33 | |||
374 | 34 | |||
375 | 35 | #include <qpa/qplatformintegrationplugin.h> | ||
376 | 36 | #include "qcustomintegration.h" | ||
377 | 37 | |||
378 | 38 | class QCustomIntegrationPlugin : public QPlatformIntegrationPlugin | ||
379 | 39 | { | ||
380 | 40 | Q_OBJECT | ||
381 | 41 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2" FILE "custom.json") | ||
382 | 42 | public: | ||
383 | 43 | QPlatformIntegration *create(const QString&, const QStringList&); | ||
384 | 44 | }; | ||
385 | 45 | |||
386 | 46 | QPlatformIntegration *QCustomIntegrationPlugin::create(const QString& system, const QStringList& /*paramList*/) | ||
387 | 47 | { | ||
388 | 48 | if (!system.compare(QLatin1String("custom"), Qt::CaseInsensitive)) | ||
389 | 49 | return new QCustomIntegration(); | ||
390 | 50 | |||
391 | 51 | return 0; | ||
392 | 52 | } | ||
393 | 53 | |||
394 | 54 | #include "main.moc" | ||
395 | 0 | 55 | ||
396 | === added file 'tests/unit/custom_qpa/qcustombackingstore.cpp' | |||
397 | --- tests/unit/custom_qpa/qcustombackingstore.cpp 1970-01-01 00:00:00 +0000 | |||
398 | +++ tests/unit/custom_qpa/qcustombackingstore.cpp 2015-08-12 11:28:41 +0000 | |||
399 | @@ -0,0 +1,64 @@ | |||
400 | 1 | /**************************************************************************** | ||
401 | 2 | ** | ||
402 | 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | ||
403 | 4 | ** Contact: http://www.qt-project.org/legal | ||
404 | 5 | ** | ||
405 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
406 | 7 | ** | ||
407 | 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | ||
408 | 9 | ** Commercial License Usage | ||
409 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
410 | 11 | ** accordance with the commercial license agreement provided with the | ||
411 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
412 | 13 | ** a written agreement between you and Digia. For licensing terms and | ||
413 | 14 | ** conditions see http://qt.digia.com/licensing. For further information | ||
414 | 15 | ** use the contact form at http://qt.digia.com/contact-us. | ||
415 | 16 | ** | ||
416 | 17 | ** GNU Lesser General Public License Usage | ||
417 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
418 | 19 | ** General Public License version 2.1 or version 3 as published by the Free | ||
419 | 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | ||
420 | 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | ||
421 | 22 | ** following information to ensure the GNU Lesser General Public License | ||
422 | 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | ||
423 | 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
424 | 25 | ** | ||
425 | 26 | ** In addition, as a special exception, Digia gives you certain additional | ||
426 | 27 | ** rights. These rights are described in the Digia Qt LGPL Exception | ||
427 | 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
428 | 29 | ** | ||
429 | 30 | ** $QT_END_LICENSE$ | ||
430 | 31 | ** | ||
431 | 32 | ****************************************************************************/ | ||
432 | 33 | |||
433 | 34 | |||
434 | 35 | #include "qcustombackingstore.h" | ||
435 | 36 | #include "qcustomintegration.h" | ||
436 | 37 | #include "qscreen.h" | ||
437 | 38 | #include <qpa/qplatformscreen.h> | ||
438 | 39 | #include <private/qguiapplication_p.h> | ||
439 | 40 | |||
440 | 41 | |||
441 | 42 | QCustomBackingStore::QCustomBackingStore(QWindow *window) | ||
442 | 43 | : QPlatformBackingStore(window) | ||
443 | 44 | { | ||
444 | 45 | } | ||
445 | 46 | |||
446 | 47 | QPaintDevice *QCustomBackingStore::paintDevice() | ||
447 | 48 | { | ||
448 | 49 | return &mImage; | ||
449 | 50 | } | ||
450 | 51 | |||
451 | 52 | void QCustomBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) | ||
452 | 53 | { | ||
453 | 54 | Q_UNUSED(window); | ||
454 | 55 | Q_UNUSED(region); | ||
455 | 56 | Q_UNUSED(offset); | ||
456 | 57 | } | ||
457 | 58 | |||
458 | 59 | void QCustomBackingStore::resize(const QSize &size, const QRegion &) | ||
459 | 60 | { | ||
460 | 61 | QImage::Format format = QGuiApplication::primaryScreen()->handle()->format(); | ||
461 | 62 | if (mImage.size() != size) | ||
462 | 63 | mImage = QImage(size, format); | ||
463 | 64 | } | ||
464 | 0 | 65 | ||
465 | === added file 'tests/unit/custom_qpa/qcustombackingstore.h' | |||
466 | --- tests/unit/custom_qpa/qcustombackingstore.h 1970-01-01 00:00:00 +0000 | |||
467 | +++ tests/unit/custom_qpa/qcustombackingstore.h 2015-08-12 11:28:41 +0000 | |||
468 | @@ -0,0 +1,55 @@ | |||
469 | 1 | /**************************************************************************** | ||
470 | 2 | ** | ||
471 | 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | ||
472 | 4 | ** Contact: http://www.qt-project.org/legal | ||
473 | 5 | ** | ||
474 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
475 | 7 | ** | ||
476 | 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | ||
477 | 9 | ** Commercial License Usage | ||
478 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
479 | 11 | ** accordance with the commercial license agreement provided with the | ||
480 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
481 | 13 | ** a written agreement between you and Digia. For licensing terms and | ||
482 | 14 | ** conditions see http://qt.digia.com/licensing. For further information | ||
483 | 15 | ** use the contact form at http://qt.digia.com/contact-us. | ||
484 | 16 | ** | ||
485 | 17 | ** GNU Lesser General Public License Usage | ||
486 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
487 | 19 | ** General Public License version 2.1 or version 3 as published by the Free | ||
488 | 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | ||
489 | 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | ||
490 | 22 | ** following information to ensure the GNU Lesser General Public License | ||
491 | 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | ||
492 | 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
493 | 25 | ** | ||
494 | 26 | ** In addition, as a special exception, Digia gives you certain additional | ||
495 | 27 | ** rights. These rights are described in the Digia Qt LGPL Exception | ||
496 | 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
497 | 29 | ** | ||
498 | 30 | ** $QT_END_LICENSE$ | ||
499 | 31 | ** | ||
500 | 32 | ****************************************************************************/ | ||
501 | 33 | |||
502 | 34 | #ifndef QBACKINGSTORE_MINIMAL_H | ||
503 | 35 | #define QBACKINGSTORE_MINIMAL_H | ||
504 | 36 | |||
505 | 37 | #include <qpa/qplatformbackingstore.h> | ||
506 | 38 | #include <qpa/qplatformwindow.h> | ||
507 | 39 | #include <QtGui/QImage> | ||
508 | 40 | |||
509 | 41 | class QCustomBackingStore : public QPlatformBackingStore | ||
510 | 42 | { | ||
511 | 43 | public: | ||
512 | 44 | QCustomBackingStore(QWindow *window); | ||
513 | 45 | ~QCustomBackingStore() = default; | ||
514 | 46 | |||
515 | 47 | QPaintDevice *paintDevice(); | ||
516 | 48 | void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); | ||
517 | 49 | void resize(const QSize &size, const QRegion &staticContents); | ||
518 | 50 | |||
519 | 51 | private: | ||
520 | 52 | QImage mImage; | ||
521 | 53 | }; | ||
522 | 54 | |||
523 | 55 | #endif | ||
524 | 0 | 56 | ||
525 | === added file 'tests/unit/custom_qpa/qcustomintegration.cpp' | |||
526 | --- tests/unit/custom_qpa/qcustomintegration.cpp 1970-01-01 00:00:00 +0000 | |||
527 | +++ tests/unit/custom_qpa/qcustomintegration.cpp 2015-08-12 11:28:41 +0000 | |||
528 | @@ -0,0 +1,112 @@ | |||
529 | 1 | /**************************************************************************** | ||
530 | 2 | ** | ||
531 | 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | ||
532 | 4 | ** Contact: http://www.qt-project.org/legal | ||
533 | 5 | ** | ||
534 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
535 | 7 | ** | ||
536 | 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | ||
537 | 9 | ** Commercial License Usage | ||
538 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
539 | 11 | ** accordance with the commercial license agreement provided with the | ||
540 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
541 | 13 | ** a written agreement between you and Digia. For licensing terms and | ||
542 | 14 | ** conditions see http://qt.digia.com/licensing. For further information | ||
543 | 15 | ** use the contact form at http://qt.digia.com/contact-us. | ||
544 | 16 | ** | ||
545 | 17 | ** GNU Lesser General Public License Usage | ||
546 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
547 | 19 | ** General Public License version 2.1 or version 3 as published by the Free | ||
548 | 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | ||
549 | 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | ||
550 | 22 | ** following information to ensure the GNU Lesser General Public License | ||
551 | 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | ||
552 | 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
553 | 25 | ** | ||
554 | 26 | ** In addition, as a special exception, Digia gives you certain additional | ||
555 | 27 | ** rights. These rights are described in the Digia Qt LGPL Exception | ||
556 | 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
557 | 29 | ** | ||
558 | 30 | ** $QT_END_LICENSE$ | ||
559 | 31 | ** | ||
560 | 32 | ****************************************************************************/ | ||
561 | 33 | |||
562 | 34 | #include "qcustomintegration.h" | ||
563 | 35 | #include "qcustombackingstore.h" | ||
564 | 36 | |||
565 | 37 | #include <QtGui/private/qguiapplication_p.h> | ||
566 | 38 | #include <qpa/qplatformwindow.h> | ||
567 | 39 | #include <qpa/qplatformfontdatabase.h> | ||
568 | 40 | |||
569 | 41 | #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> | ||
570 | 42 | |||
571 | 43 | static const char devicePixelRatioEnvironmentVariable[] = "QT_DEVICE_PIXEL_RATIO"; | ||
572 | 44 | |||
573 | 45 | QCustomScreen::QCustomScreen() | ||
574 | 46 | : mDepth(32), mFormat(QImage::Format_ARGB32_Premultiplied), mDpr(1.0) | ||
575 | 47 | { | ||
576 | 48 | if (qEnvironmentVariableIsSet(devicePixelRatioEnvironmentVariable)) { | ||
577 | 49 | bool ok = false; | ||
578 | 50 | const float dpr = qgetenv(devicePixelRatioEnvironmentVariable).toFloat(&ok); | ||
579 | 51 | if (ok && dpr > 0) { | ||
580 | 52 | mDpr = dpr; | ||
581 | 53 | } | ||
582 | 54 | } | ||
583 | 55 | } | ||
584 | 56 | |||
585 | 57 | QCustomIntegration::QCustomIntegration() | ||
586 | 58 | { | ||
587 | 59 | QCustomScreen *mPrimaryScreen = new QCustomScreen(); | ||
588 | 60 | |||
589 | 61 | mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320); | ||
590 | 62 | mPrimaryScreen->mDepth = 32; | ||
591 | 63 | mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; | ||
592 | 64 | |||
593 | 65 | screenAdded(mPrimaryScreen); | ||
594 | 66 | } | ||
595 | 67 | |||
596 | 68 | bool QCustomIntegration::hasCapability(QPlatformIntegration::Capability cap) const | ||
597 | 69 | { | ||
598 | 70 | switch (cap) { | ||
599 | 71 | case ThreadedPixmaps: return true; | ||
600 | 72 | case MultipleWindows: return true; | ||
601 | 73 | default: return QPlatformIntegration::hasCapability(cap); | ||
602 | 74 | } | ||
603 | 75 | } | ||
604 | 76 | |||
605 | 77 | // Dummy font database that does not scan the fonts directory to be | ||
606 | 78 | // used for command line tools like qmlplugindump that do not create windows | ||
607 | 79 | // unless DebugBackingStore is activated. | ||
608 | 80 | class DummyFontDatabase : public QPlatformFontDatabase | ||
609 | 81 | { | ||
610 | 82 | public: | ||
611 | 83 | void populateFontDatabase() override {} | ||
612 | 84 | }; | ||
613 | 85 | |||
614 | 86 | QPlatformFontDatabase *QCustomIntegration::fontDatabase() const | ||
615 | 87 | { | ||
616 | 88 | return new DummyFontDatabase; | ||
617 | 89 | } | ||
618 | 90 | |||
619 | 91 | |||
620 | 92 | QPlatformWindow *QCustomIntegration::createPlatformWindow(QWindow *window) const | ||
621 | 93 | { | ||
622 | 94 | QPlatformWindow *w = new QPlatformWindow(window); | ||
623 | 95 | w->requestActivateWindow(); | ||
624 | 96 | return w; | ||
625 | 97 | } | ||
626 | 98 | |||
627 | 99 | QPlatformBackingStore *QCustomIntegration::createPlatformBackingStore(QWindow *window) const | ||
628 | 100 | { | ||
629 | 101 | return new QCustomBackingStore(window); | ||
630 | 102 | } | ||
631 | 103 | |||
632 | 104 | QAbstractEventDispatcher *QCustomIntegration::createEventDispatcher() const | ||
633 | 105 | { | ||
634 | 106 | return createUnixEventDispatcher(); | ||
635 | 107 | } | ||
636 | 108 | |||
637 | 109 | QCustomIntegration *QCustomIntegration::instance() | ||
638 | 110 | { | ||
639 | 111 | return static_cast<QCustomIntegration *>(QGuiApplicationPrivate::platformIntegration()); | ||
640 | 112 | } | ||
641 | 0 | 113 | ||
642 | === added file 'tests/unit/custom_qpa/qcustomintegration.h' | |||
643 | --- tests/unit/custom_qpa/qcustomintegration.h 1970-01-01 00:00:00 +0000 | |||
644 | +++ tests/unit/custom_qpa/qcustomintegration.h 2015-08-12 11:28:41 +0000 | |||
645 | @@ -0,0 +1,74 @@ | |||
646 | 1 | /**************************************************************************** | ||
647 | 2 | ** | ||
648 | 3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). | ||
649 | 4 | ** Contact: http://www.qt-project.org/legal | ||
650 | 5 | ** | ||
651 | 6 | ** This file is part of the plugins of the Qt Toolkit. | ||
652 | 7 | ** | ||
653 | 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | ||
654 | 9 | ** Commercial License Usage | ||
655 | 10 | ** Licensees holding valid commercial Qt licenses may use this file in | ||
656 | 11 | ** accordance with the commercial license agreement provided with the | ||
657 | 12 | ** Software or, alternatively, in accordance with the terms contained in | ||
658 | 13 | ** a written agreement between you and Digia. For licensing terms and | ||
659 | 14 | ** conditions see http://qt.digia.com/licensing. For further information | ||
660 | 15 | ** use the contact form at http://qt.digia.com/contact-us. | ||
661 | 16 | ** | ||
662 | 17 | ** GNU Lesser General Public License Usage | ||
663 | 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | ||
664 | 19 | ** General Public License version 2.1 or version 3 as published by the Free | ||
665 | 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | ||
666 | 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | ||
667 | 22 | ** following information to ensure the GNU Lesser General Public License | ||
668 | 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | ||
669 | 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | ||
670 | 25 | ** | ||
671 | 26 | ** In addition, as a special exception, Digia gives you certain additional | ||
672 | 27 | ** rights. These rights are described in the Digia Qt LGPL Exception | ||
673 | 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | ||
674 | 29 | ** | ||
675 | 30 | ** $QT_END_LICENSE$ | ||
676 | 31 | ** | ||
677 | 32 | ****************************************************************************/ | ||
678 | 33 | |||
679 | 34 | #ifndef QPLATFORMINTEGRATION_MINIMAL_H | ||
680 | 35 | #define QPLATFORMINTEGRATION_MINIMAL_H | ||
681 | 36 | |||
682 | 37 | #include <qpa/qplatformintegration.h> | ||
683 | 38 | #include <qpa/qplatformscreen.h> | ||
684 | 39 | |||
685 | 40 | class QCustomScreen : public QPlatformScreen | ||
686 | 41 | { | ||
687 | 42 | public: | ||
688 | 43 | QCustomScreen(); | ||
689 | 44 | |||
690 | 45 | QRect geometry() const override { return mGeometry; } | ||
691 | 46 | int depth() const override { return mDepth; } | ||
692 | 47 | QImage::Format format() const override { return mFormat; } | ||
693 | 48 | qreal devicePixelRatio() const override { return mDpr; } | ||
694 | 49 | |||
695 | 50 | public: | ||
696 | 51 | QRect mGeometry; | ||
697 | 52 | int mDepth; | ||
698 | 53 | QImage::Format mFormat; | ||
699 | 54 | QSize mPhysicalSize; | ||
700 | 55 | qreal mDpr; | ||
701 | 56 | }; | ||
702 | 57 | |||
703 | 58 | class QCustomIntegration : public QPlatformIntegration | ||
704 | 59 | { | ||
705 | 60 | public: | ||
706 | 61 | explicit QCustomIntegration(); | ||
707 | 62 | ~QCustomIntegration() = default; | ||
708 | 63 | |||
709 | 64 | bool hasCapability(QPlatformIntegration::Capability cap) const override; | ||
710 | 65 | QPlatformFontDatabase *fontDatabase() const override; | ||
711 | 66 | |||
712 | 67 | QPlatformWindow *createPlatformWindow(QWindow *window) const override; | ||
713 | 68 | QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override; | ||
714 | 69 | QAbstractEventDispatcher *createEventDispatcher() const override; | ||
715 | 70 | |||
716 | 71 | static QCustomIntegration *instance(); | ||
717 | 72 | }; | ||
718 | 73 | |||
719 | 74 | #endif | ||
720 | 0 | 75 | ||
721 | === modified file 'tests/unit/runtest.sh' | |||
722 | --- tests/unit/runtest.sh 2015-06-17 18:18:04 +0000 | |||
723 | +++ tests/unit/runtest.sh 2015-08-12 11:28:41 +0000 | |||
724 | @@ -43,6 +43,8 @@ | |||
725 | 43 | 43 | ||
726 | 44 | if [ "$_MINIMAL" = "minimal" ]; then | 44 | if [ "$_MINIMAL" = "minimal" ]; then |
727 | 45 | _CMD="$_CMD -p -platform -p minimal" | 45 | _CMD="$_CMD -p -platform -p minimal" |
728 | 46 | elif [ "$_MINIMAL" = "custom" ]; then | ||
729 | 47 | _CMD="$_CMD -p -platform -p custom" | ||
730 | 46 | fi | 48 | fi |
731 | 47 | 49 | ||
732 | 48 | if [ $_TARGETPATH != $_TESTFILEPATH ]; then | 50 | if [ $_TARGETPATH != $_TESTFILEPATH ]; then |
733 | 49 | 51 | ||
734 | === added directory 'tests/unit/tst_units/dpr1' | |||
735 | === added file 'tests/unit/tst_units/dpr1/dpr1.pro' | |||
736 | --- tests/unit/tst_units/dpr1/dpr1.pro 1970-01-01 00:00:00 +0000 | |||
737 | +++ tests/unit/tst_units/dpr1/dpr1.pro 2015-08-12 11:28:41 +0000 | |||
738 | @@ -0,0 +1,3 @@ | |||
739 | 1 | include(../../test-include.pri) | ||
740 | 2 | SOURCES += tst_units.cpp | ||
741 | 3 | RESOURCES += dpr1.qrc | ||
742 | 0 | 4 | ||
743 | === renamed file 'tests/unit/tst_units/tst_units.qrc' => 'tests/unit/tst_units/dpr1/dpr1.qrc' | |||
744 | === renamed file 'tests/unit/tst_units/exact_match@8.png' => 'tests/unit/tst_units/dpr1/exact_match@8.png' | |||
745 | === renamed file 'tests/unit/tst_units/exact_match_no_suffix.png' => 'tests/unit/tst_units/dpr1/exact_match_no_suffix.png' | |||
746 | === renamed file 'tests/unit/tst_units/higher_scale.png' => 'tests/unit/tst_units/dpr1/higher_scale.png' | |||
747 | === renamed file 'tests/unit/tst_units/lower_scale.png' => 'tests/unit/tst_units/dpr1/lower_scale.png' | |||
748 | === renamed file 'tests/unit/tst_units/resource@1.png' => 'tests/unit/tst_units/dpr1/resource@1.png' | |||
749 | === renamed file 'tests/unit/tst_units/resource@10.png' => 'tests/unit/tst_units/dpr1/resource@10.png' | |||
750 | === renamed file 'tests/unit/tst_units/resource@15.png' => 'tests/unit/tst_units/dpr1/resource@15.png' | |||
751 | === renamed file 'tests/unit/tst_units/resource@18.png' => 'tests/unit/tst_units/dpr1/resource@18.png' | |||
752 | === renamed file 'tests/unit/tst_units/resource@19.png' => 'tests/unit/tst_units/dpr1/resource@19.png' | |||
753 | === renamed file 'tests/unit/tst_units/resource@8.png' => 'tests/unit/tst_units/dpr1/resource@8.png' | |||
754 | === renamed file 'tests/unit/tst_units/resource_only_higher@13.png' => 'tests/unit/tst_units/dpr1/resource_only_higher@13.png' | |||
755 | === renamed file 'tests/unit/tst_units/resource_only_smaller@7.png' => 'tests/unit/tst_units/dpr1/resource_only_smaller@7.png' | |||
756 | === renamed file 'tests/unit/tst_units/resources_unit' => 'tests/unit/tst_units/dpr1/resources_unit' | |||
757 | === renamed file 'tests/unit/tst_units/tst_units.cpp' => 'tests/unit/tst_units/dpr1/tst_units.cpp' | |||
758 | === added directory 'tests/unit/tst_units/dpr2' | |||
759 | === added file 'tests/unit/tst_units/dpr2/dpr2.pro' | |||
760 | --- tests/unit/tst_units/dpr2/dpr2.pro 1970-01-01 00:00:00 +0000 | |||
761 | +++ tests/unit/tst_units/dpr2/dpr2.pro 2015-08-12 11:28:41 +0000 | |||
762 | @@ -0,0 +1,3 @@ | |||
763 | 1 | CONFIG += custom_qpa # needed by test to set device pixel ratio correctly | ||
764 | 2 | include(../../test-include.pri) | ||
765 | 3 | SOURCES += tst_units_dpr2.cpp | ||
766 | 0 | 4 | ||
767 | === added file 'tests/unit/tst_units/dpr2/tst_units_dpr2.cpp' | |||
768 | --- tests/unit/tst_units/dpr2/tst_units_dpr2.cpp 1970-01-01 00:00:00 +0000 | |||
769 | +++ tests/unit/tst_units/dpr2/tst_units_dpr2.cpp 2015-08-12 11:28:41 +0000 | |||
770 | @@ -0,0 +1,143 @@ | |||
771 | 1 | /* | ||
772 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
773 | 3 | * | ||
774 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
775 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
776 | 6 | * the Free Software Foundation. | ||
777 | 7 | * | ||
778 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
779 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
780 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
781 | 11 | * Lesser General Public License for more details. | ||
782 | 12 | * | ||
783 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
784 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
785 | 15 | */ | ||
786 | 16 | |||
787 | 17 | #include <QtTest/QtTest> | ||
788 | 18 | #include "ucunits.h" | ||
789 | 19 | |||
790 | 20 | class tst_UCUnitsDPR2: public QObject | ||
791 | 21 | { | ||
792 | 22 | Q_OBJECT | ||
793 | 23 | |||
794 | 24 | private Q_SLOTS: | ||
795 | 25 | |||
796 | 26 | void dpGridUnitDefaultWithDPR2() { | ||
797 | 27 | UCUnits units; | ||
798 | 28 | |||
799 | 29 | QCOMPARE(units.dp(1.0), 1.0f); | ||
800 | 30 | QCOMPARE(units.dp(1.32), 1.5f); | ||
801 | 31 | QCOMPARE(units.dp(1.72), 1.5f); | ||
802 | 32 | QCOMPARE(units.dp(0.23), 0.0f); | ||
803 | 33 | QCOMPARE(units.dp(0.51), 0.5f); | ||
804 | 34 | QCOMPARE(units.dp(0.9999), 1.0f); | ||
805 | 35 | QCOMPARE(units.dp(1000.01), 1000.0f); | ||
806 | 36 | } | ||
807 | 37 | |||
808 | 38 | void guGridUnitDefaultWithDPR2() { | ||
809 | 39 | UCUnits units; | ||
810 | 40 | |||
811 | 41 | QCOMPARE(units.gu(0.5), 4.0f); | ||
812 | 42 | QCOMPARE(units.gu(1), 8.0f); | ||
813 | 43 | QCOMPARE(units.gu(1.5), 12.0f); | ||
814 | 44 | QCOMPARE(units.gu(2), 16.0f); | ||
815 | 45 | QCOMPARE(units.gu(4), 32.0f); | ||
816 | 46 | QCOMPARE(units.gu(100000), 800000.0f); | ||
817 | 47 | QCOMPARE(units.gu(150.51983), 1204.0f); | ||
818 | 48 | } | ||
819 | 49 | |||
820 | 50 | void dpGridUnitEightWithDPR2() { | ||
821 | 51 | UCUnits units; | ||
822 | 52 | units.setGridUnit(8); | ||
823 | 53 | |||
824 | 54 | QCOMPARE(units.dp(1.0), 0.5f); | ||
825 | 55 | QCOMPARE(units.dp(1.32), 0.5f); | ||
826 | 56 | QCOMPARE(units.dp(1.72), 1.0f); | ||
827 | 57 | QCOMPARE(units.dp(0.23), 0.0f); | ||
828 | 58 | QCOMPARE(units.dp(0.51), 0.5f); | ||
829 | 59 | QCOMPARE(units.dp(0.9999), 0.5f); | ||
830 | 60 | QCOMPARE(units.dp(1000.01), 500.0f); | ||
831 | 61 | } | ||
832 | 62 | |||
833 | 63 | void guGridUnitEightWithDPR2() { | ||
834 | 64 | UCUnits units; | ||
835 | 65 | units.setGridUnit(8); | ||
836 | 66 | |||
837 | 67 | QCOMPARE(units.gu(0.5), 2.0f); | ||
838 | 68 | QCOMPARE(units.gu(1), 4.0f); | ||
839 | 69 | QCOMPARE(units.gu(1.5), 6.0f); | ||
840 | 70 | QCOMPARE(units.gu(2), 8.0f); | ||
841 | 71 | QCOMPARE(units.gu(4), 16.0f); | ||
842 | 72 | QCOMPARE(units.gu(100000), 400000.0f); | ||
843 | 73 | QCOMPARE(units.gu(150.51983), 602.0f); | ||
844 | 74 | } | ||
845 | 75 | |||
846 | 76 | void dpGridUnitSixteenWithDPR2() { | ||
847 | 77 | UCUnits units; | ||
848 | 78 | units.setGridUnit(16); | ||
849 | 79 | /* This testcase covers unit calculations when the Qt device pixel ratio is 2. | ||
850 | 80 | * | ||
851 | 81 | */ | ||
852 | 82 | |||
853 | 83 | QCOMPARE(units.dp(1.0), 1.0f); | ||
854 | 84 | QCOMPARE(units.dp(1.32), 1.5f); | ||
855 | 85 | QCOMPARE(units.dp(1.72), 1.5f); | ||
856 | 86 | QCOMPARE(units.dp(0.23), 0.0f); | ||
857 | 87 | QCOMPARE(units.dp(0.51), 0.5f); | ||
858 | 88 | QCOMPARE(units.dp(0.9999), 1.0f); | ||
859 | 89 | QCOMPARE(units.dp(1000.01), 1000.0f); | ||
860 | 90 | } | ||
861 | 91 | |||
862 | 92 | void guGridUnitSixteenWithDPR2() { | ||
863 | 93 | UCUnits units; | ||
864 | 94 | units.setGridUnit(16); | ||
865 | 95 | |||
866 | 96 | QCOMPARE(units.gu(0.5), 4.0f); | ||
867 | 97 | QCOMPARE(units.gu(1), 8.0f); | ||
868 | 98 | QCOMPARE(units.gu(1.5), 12.0f); | ||
869 | 99 | QCOMPARE(units.gu(2), 16.0f); | ||
870 | 100 | QCOMPARE(units.gu(4), 32.0f); | ||
871 | 101 | QCOMPARE(units.gu(100000), 800000.0f); | ||
872 | 102 | QCOMPARE(units.gu(150.51983), 1204.0f); | ||
873 | 103 | } | ||
874 | 104 | |||
875 | 105 | void dpGridUnitTwentyWithDPR2() { | ||
876 | 106 | UCUnits units; | ||
877 | 107 | units.setGridUnit(20); | ||
878 | 108 | |||
879 | 109 | QCOMPARE(units.dp(1.0), 1.0f); | ||
880 | 110 | QCOMPARE(units.dp(1.32), 1.5f); | ||
881 | 111 | QCOMPARE(units.dp(1.72), 1.5f); | ||
882 | 112 | QCOMPARE(units.dp(0.23), 0.0f); | ||
883 | 113 | QCOMPARE(units.dp(0.51), 0.5f); | ||
884 | 114 | QCOMPARE(units.dp(0.9999), 1.0f); | ||
885 | 115 | QCOMPARE(units.dp(1000.01), 1250.0f); | ||
886 | 116 | } | ||
887 | 117 | |||
888 | 118 | void guGridUnitTenWithDPR2() { | ||
889 | 119 | UCUnits units; | ||
890 | 120 | units.setGridUnit(10); | ||
891 | 121 | |||
892 | 122 | QCOMPARE(units.gu(0.5), 2.5f); | ||
893 | 123 | QCOMPARE(units.gu(1), 5.0f); | ||
894 | 124 | QCOMPARE(units.gu(1.5), 7.5f); | ||
895 | 125 | QCOMPARE(units.gu(2), 10.0f); | ||
896 | 126 | QCOMPARE(units.gu(4), 20.0f); | ||
897 | 127 | QCOMPARE(units.gu(100000), 500000.0f); | ||
898 | 128 | QCOMPARE(units.gu(150.51983), 752.5f); | ||
899 | 129 | } | ||
900 | 130 | }; | ||
901 | 131 | |||
902 | 132 | //QTEST_MAIN(tst_UCUnitsDPR2) - want to set custom env var, so need to use actual code: | ||
903 | 133 | int main(int argc, char *argv[]) | ||
904 | 134 | { | ||
905 | 135 | qputenv("QT_DEVICE_PIXEL_RATIO", "2"); | ||
906 | 136 | |||
907 | 137 | QGuiApplication app(argc, argv); | ||
908 | 138 | app.setAttribute(Qt::AA_Use96Dpi, true); | ||
909 | 139 | tst_UCUnitsDPR2 tc; | ||
910 | 140 | return QTest::qExec(&tc, argc, argv); | ||
911 | 141 | } | ||
912 | 142 | |||
913 | 143 | #include "tst_units_dpr2.moc" | ||
914 | 0 | 144 | ||
915 | === added directory 'tests/unit/tst_units/dpr3' | |||
916 | === added file 'tests/unit/tst_units/dpr3/dpr3.pro' | |||
917 | --- tests/unit/tst_units/dpr3/dpr3.pro 1970-01-01 00:00:00 +0000 | |||
918 | +++ tests/unit/tst_units/dpr3/dpr3.pro 2015-08-12 11:28:41 +0000 | |||
919 | @@ -0,0 +1,3 @@ | |||
920 | 1 | CONFIG += custom_qpa # needed by test to set device pixel ratio correctly | ||
921 | 2 | include(../../test-include.pri) | ||
922 | 3 | SOURCES += tst_units_dpr3.cpp | ||
923 | 0 | 4 | ||
924 | === added file 'tests/unit/tst_units/dpr3/tst_units_dpr3.cpp' | |||
925 | --- tests/unit/tst_units/dpr3/tst_units_dpr3.cpp 1970-01-01 00:00:00 +0000 | |||
926 | +++ tests/unit/tst_units/dpr3/tst_units_dpr3.cpp 2015-08-12 11:28:41 +0000 | |||
927 | @@ -0,0 +1,88 @@ | |||
928 | 1 | /* | ||
929 | 2 | * Copyright (C) 2015 Canonical, Ltd. | ||
930 | 3 | * | ||
931 | 4 | * This program is free software: you can redistribute it and/or modify it under | ||
932 | 5 | * the terms of the GNU Lesser General Public License version 3, as published by | ||
933 | 6 | * the Free Software Foundation. | ||
934 | 7 | * | ||
935 | 8 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||
936 | 9 | * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
937 | 10 | * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
938 | 11 | * Lesser General Public License for more details. | ||
939 | 12 | * | ||
940 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
941 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
942 | 15 | */ | ||
943 | 16 | |||
944 | 17 | #include <QtTest/QtTest> | ||
945 | 18 | #include "ucunits.h" | ||
946 | 19 | |||
947 | 20 | class tst_UCUnitsDPR3: public QObject | ||
948 | 21 | { | ||
949 | 22 | Q_OBJECT | ||
950 | 23 | |||
951 | 24 | private Q_SLOTS: | ||
952 | 25 | |||
953 | 26 | void dpGridUnitDefaultWithDPR3() { | ||
954 | 27 | UCUnits units; | ||
955 | 28 | |||
956 | 29 | QCOMPARE(units.dp(1.0), 1.0f); | ||
957 | 30 | QCOMPARE(units.dp(1.32), 1.33333f); | ||
958 | 31 | QCOMPARE(units.dp(1.72), 1.66666f); | ||
959 | 32 | QCOMPARE(units.dp(0.23), 0.333333f); | ||
960 | 33 | QCOMPARE(units.dp(0.51), 0.666666f); | ||
961 | 34 | QCOMPARE(units.dp(0.9999), 1.0f); | ||
962 | 35 | QCOMPARE(units.dp(1000.01), 1000.0f); | ||
963 | 36 | } | ||
964 | 37 | |||
965 | 38 | void guGridUnitDefaultWithDPR3() { | ||
966 | 39 | UCUnits units; | ||
967 | 40 | |||
968 | 41 | QCOMPARE(units.gu(0.5), 4.0f); | ||
969 | 42 | QCOMPARE(units.gu(1), 8.0f); | ||
970 | 43 | QCOMPARE(units.gu(1.5), 12.0f); | ||
971 | 44 | QCOMPARE(units.gu(2), 16.0f); | ||
972 | 45 | QCOMPARE(units.gu(4), 32.0f); | ||
973 | 46 | QCOMPARE(units.gu(100000), 800000.0f); | ||
974 | 47 | QCOMPARE(units.gu(150.51983), 1204.0f); | ||
975 | 48 | } | ||
976 | 49 | |||
977 | 50 | void dpGridUnitSixteenWithDPR3() { | ||
978 | 51 | UCUnits units; | ||
979 | 52 | units.setGridUnit(16); | ||
980 | 53 | |||
981 | 54 | QCOMPARE(units.dp(1.0), 0.666666f); | ||
982 | 55 | QCOMPARE(units.dp(1.32), 1.0f); | ||
983 | 56 | QCOMPARE(units.dp(1.72), 1.0f); | ||
984 | 57 | QCOMPARE(units.dp(0.23), 0.0f); | ||
985 | 58 | QCOMPARE(units.dp(0.51), 0.333333f); | ||
986 | 59 | QCOMPARE(units.dp(0.9999), 0.666666f); | ||
987 | 60 | QCOMPARE(units.dp(1000.01), 666.666666f); | ||
988 | 61 | } | ||
989 | 62 | |||
990 | 63 | void guGridUnitSixteenWithDPR3() { | ||
991 | 64 | UCUnits units; | ||
992 | 65 | units.setGridUnit(16); | ||
993 | 66 | |||
994 | 67 | QCOMPARE(units.gu(0.5), 2.666666f); | ||
995 | 68 | QCOMPARE(units.gu(1), 5.333333f); | ||
996 | 69 | QCOMPARE(units.gu(1.5), 8.0f); | ||
997 | 70 | QCOMPARE(units.gu(2), 10.666666f); | ||
998 | 71 | QCOMPARE(units.gu(4), 21.333333f); | ||
999 | 72 | QCOMPARE(units.gu(100000), 533333.333333f); | ||
1000 | 73 | QCOMPARE(units.gu(150.51983), 802.666666f); | ||
1001 | 74 | } | ||
1002 | 75 | }; | ||
1003 | 76 | |||
1004 | 77 | //QTEST_MAIN(tst_UCUnitsDPR3) - want to set custom env var, so need to use actual code: | ||
1005 | 78 | int main(int argc, char *argv[]) | ||
1006 | 79 | { | ||
1007 | 80 | qputenv("QT_DEVICE_PIXEL_RATIO", "3"); | ||
1008 | 81 | |||
1009 | 82 | QGuiApplication app(argc, argv); | ||
1010 | 83 | app.setAttribute(Qt::AA_Use96Dpi, true); | ||
1011 | 84 | tst_UCUnitsDPR3 tc; | ||
1012 | 85 | return QTest::qExec(&tc, argc, argv); | ||
1013 | 86 | } | ||
1014 | 87 | |||
1015 | 88 | #include "tst_units_dpr3.moc" | ||
1016 | 0 | 89 | ||
1017 | === modified file 'tests/unit/tst_units/tst_units.pro' | |||
1018 | --- tests/unit/tst_units/tst_units.pro 2012-10-09 17:54:43 +0000 | |||
1019 | +++ tests/unit/tst_units/tst_units.pro 2015-08-12 11:28:41 +0000 | |||
1020 | @@ -1,3 +1,6 @@ | |||
1024 | 1 | include(../test-include.pri) | 1 | TEMPLATE = subdirs |
1025 | 2 | SOURCES += tst_units.cpp | 2 | |
1026 | 3 | RESOURCES += tst_units.qrc | 3 | SUBDIRS += \ |
1027 | 4 | dpr1 \ | ||
1028 | 5 | dpr2 \ | ||
1029 | 6 | dpr3 | ||
1030 | 4 | 7 | ||
1031 | === modified file 'tests/unit/unit.pro' | |||
1032 | --- tests/unit/unit.pro 2015-03-10 11:49:27 +0000 | |||
1033 | +++ tests/unit/unit.pro 2015-08-12 11:28:41 +0000 | |||
1034 | @@ -14,7 +14,9 @@ | |||
1035 | 14 | tst_components_benchmark | 14 | tst_components_benchmark |
1036 | 15 | #} | 15 | #} |
1037 | 16 | 16 | ||
1039 | 17 | SUBDIRS += tst_units \ | 17 | SUBDIRS += \ |
1040 | 18 | custom_qpa \ | ||
1041 | 19 | tst_units \ | ||
1042 | 18 | tst_scaling_image_provider \ | 20 | tst_scaling_image_provider \ |
1043 | 19 | tst_qquick_image_extension \ | 21 | tst_qquick_image_extension \ |
1044 | 20 | tst_performance \ | 22 | tst_performance \ |
FAILED: Continuous integration, rev:1172 jenkins. qa.ubuntu. com/job/ ubuntu- sdk-team- ubuntu- ui-toolkit- staging- ci/1675/ jenkins. qa.ubuntu. com/job/ generic- deb-autopilot- vivid-touch/ 2275 jenkins. qa.ubuntu. com/job/ ubuntu- sdk-team- ubuntu- ui-toolkit- staging- vivid-amd64- ci/402 jenkins. qa.ubuntu. com/job/ ubuntu- sdk-team- ubuntu- ui-toolkit- staging- vivid-armhf- ci/405 jenkins. qa.ubuntu. com/job/ ubuntu- sdk-team- ubuntu- ui-toolkit- staging- vivid-armhf- ci/405/ artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ ubuntu- sdk-team- ubuntu- ui-toolkit- staging- vivid-i386- ci/402 jenkins. qa.ubuntu. com/job/ generic- deb-autopilot- runner- vivid-mako/ 1998 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- vivid-armhf/ 2273 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- vivid-armhf/ 2273/artifact/ work/output/ *zip*/output. zip s-jenkins. ubuntu- ci:8080/ job/touch- flash-device/ 19696
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/ubuntu- sdk-team- ubuntu- ui-toolkit- staging- ci/1675/ rebuild
http://