WinRT: Fix physical size of screen
Currently, the physical size of the screen is calculated with the logicalSize and the logicalDpi of the screen. This doesn't work because logicalDpi has a user-defined multiplier and a strange value. The easiest and accuratest way is to take the raw dpi of the axis and the raw pixel size (logicalSize*scaleFactor). This all is needed for a correct value of Screen.pixelDensity in QtQuick. Change-Id: I8be0139d762364140043c3fa0d203298ca7ef293 Reviewed-by: Jochen Seemann <seemann.jochen@gmail.com> Reviewed-by: Andrew Knight <andrew.knight@digia.com>
This commit is contained in:
parent
42f681ea8d
commit
fcb8dc0cb9
@ -448,6 +448,7 @@ public:
|
||||
QSizeF logicalSize;
|
||||
QSurfaceFormat surfaceFormat;
|
||||
qreal logicalDpi;
|
||||
QDpi physicalDpi;
|
||||
qreal scaleFactor;
|
||||
Qt::ScreenOrientation nativeOrientation;
|
||||
Qt::ScreenOrientation orientation;
|
||||
@ -629,7 +630,8 @@ QSurfaceFormat QWinRTScreen::surfaceFormat() const
|
||||
QSizeF QWinRTScreen::physicalSize() const
|
||||
{
|
||||
Q_D(const QWinRTScreen);
|
||||
return d->logicalSize / d->logicalDpi * qreal(25.4);
|
||||
return QSizeF(d->logicalSize.width() * d->scaleFactor / d->physicalDpi.first * qreal(25.4),
|
||||
d->logicalSize.height() * d->scaleFactor / d->physicalDpi.second * qreal(25.4));
|
||||
}
|
||||
|
||||
QDpi QWinRTScreen::logicalDpi() const
|
||||
@ -1137,6 +1139,14 @@ HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *)
|
||||
RETURN_OK_IF_FAILED("Failed to get logical DPI.");
|
||||
d->logicalDpi = dpi;
|
||||
|
||||
hr = d->displayInformation->get_RawDpiX(&dpi);
|
||||
RETURN_OK_IF_FAILED("Failed to get x raw DPI.");
|
||||
d->physicalDpi.first = dpi ? dpi : 96.0;
|
||||
|
||||
hr = d->displayInformation->get_RawDpiY(&dpi);
|
||||
RETURN_OK_IF_FAILED("Failed to get y raw DPI.");
|
||||
d->physicalDpi.second = dpi ? dpi : 96.0;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user