summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowsscreen.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-09-30 14:25:43 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-06 09:36:39 +0200
commit7d2cfbe5aa1e67d12010a66481625c9d40f0c174 (patch)
tree26734132827c40ba425d79481c2c4193bac5c5ea /src/plugins/platforms/windows/qwindowsscreen.cpp
parent29948e666583a26966ddb97faf4808099824b80d (diff)
Improved logical and physical DPI APIs.
Made physicalSize() return QSizeF instead, to prevent rounding errors. Added logicalSize() as the base to compute font pixel sizes instead, and added convenience functions in QScreen to access the logical and physical sizes and DPI metrics. Task-number: QTBUG-21736 Task-number: QTBUG-21737 Change-Id: Ic705dc98eb3632617659e65a0c9a552673dc0c65 Reviewed-on: http://codereview.qt-project.org/5888 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsscreen.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index cde9dec21b..c6784e5bf3 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -55,8 +55,6 @@
QT_BEGIN_NAMESPACE
-typedef QPair<int, int> DPI;
-
QWindowsScreenData::QWindowsScreenData() :
dpi(96, 96),
depth(32),
@@ -64,25 +62,25 @@ QWindowsScreenData::QWindowsScreenData() :
{
}
-static inline DPI deviceDPI(HDC hdc)
+static inline QDpi deviceDPI(HDC hdc)
{
- return DPI(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
+ return QDpi(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY));
}
-static inline QSize deviceSizeMM(const QSize &pixels, const DPI &dpi)
+static inline QSizeF deviceSizeMM(const QSize &pixels, const QDpi &dpi)
{
const qreal inchToMM = 25.4;
const qreal h = qreal(pixels.width()) / qreal(dpi.first) * inchToMM;
const qreal v = qreal(pixels.height()) / qreal(dpi.second) * inchToMM;
- return QSize(qRound(h), qRound(v));
+ return QSizeF(h, v);
}
-static inline DPI deviceDPI(const QSize &pixels, const QSize &physicalSizeMM)
+static inline QDpi deviceDPI(const QSize &pixels, const QSizeF &physicalSizeMM)
{
const qreal inchToMM = 25.4;
const qreal h = qreal(pixels.width()) / (qreal(physicalSizeMM.width()) / inchToMM);
const qreal v = qreal(pixels.height()) / (qreal(physicalSizeMM.height()) / inchToMM);
- return DPI(qRound(v), qRound(h));
+ return QDpi(h, v);
}
typedef QList<QWindowsScreenData> WindowsScreenDataList;
@@ -101,13 +99,13 @@ BOOL QT_WIN_CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM
data.geometry = QRect(QPoint(info.rcMonitor.left, info.rcMonitor.top), QPoint(info.rcMonitor.right - 1, info.rcMonitor.bottom - 1));
if (HDC hdc = CreateDC(info.szDevice, NULL, NULL, NULL)) {
data.dpi = deviceDPI(hdc);
+ data.physicalSizeMM = QSizeF(GetDeviceCaps(hdc, HORZSIZE), GetDeviceCaps(hdc, VERTSIZE));
DeleteDC(hdc);
} else {
qWarning("%s: Unable to obtain handle for monitor '%s', defaulting to %d DPI.",
__FUNCTION__, qPrintable(QString::fromWCharArray(info.szDevice)),
data.dpi.first);
}
- data.physicalSizeMM = deviceSizeMM(data.geometry.size(), data.dpi);
data.geometry = QRect(QPoint(info.rcMonitor.left, info.rcMonitor.top), QPoint(info.rcMonitor.right - 1, info.rcMonitor.bottom - 1));
data.availableGeometry = QRect(QPoint(info.rcWork.left, info.rcWork.top), QPoint(info.rcWork.right - 1, info.rcWork.bottom - 1));
data.primary = (info.dwFlags & MONITORINFOF_PRIMARY) != 0;