summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp29
-rw-r--r--src/gui/kernel/qguiapplication.h1
-rw-r--r--src/gui/kernel/qplatformscreen.cpp12
-rw-r--r--src/gui/kernel/qplatformscreen.h1
-rw-r--r--src/gui/kernel/qplatformwindow.cpp12
-rw-r--r--src/gui/kernel/qplatformwindow.h2
-rw-r--r--src/gui/kernel/qscreen.cpp14
-rw-r--r--src/gui/kernel/qscreen.h2
-rw-r--r--src/gui/kernel/qwindow.cpp18
-rw-r--r--src/gui/kernel/qwindow.h2
10 files changed, 92 insertions, 1 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 80e13227ee..fb14490a24 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -703,7 +703,34 @@ QList<QScreen *> QGuiApplication::screens()
/*!
- Returns the top level window at the given position \a pos, if any.
+ Returns the highest screen device pixel ratio found on
+ the system. This is the ratio between physical pixels and
+ device-independent pixels.
+
+ Use this function only when you don't know which window you are targeting.
+ If you do know the target window use QWindow::devicePixelRatio() instead.
+
+ \sa QWindow::devicePixelRatio();
+ \sa QGuiApplicaiton::devicePixelRatio();
+*/
+qreal QGuiApplication::devicePixelRatio() const
+{
+ // Cache topDevicePixelRatio, iterate through the screen list once only.
+ static qreal topDevicePixelRatio = 0.0;
+ if (!qFuzzyIsNull(topDevicePixelRatio)) {
+ return topDevicePixelRatio;
+ }
+
+ topDevicePixelRatio = 1.0; // make sure we never return 0.
+ foreach (QScreen *screen, QGuiApplicationPrivate::screen_list) {
+ topDevicePixelRatio = qMax(topDevicePixelRatio, screen->devicePixelRatio());
+ }
+
+ return topDevicePixelRatio;
+}
+
+/*!
+ Returns the top level window at the given position, if any.
*/
QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
{
diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h
index 27ea86ec6e..7c0dbbdcde 100644
--- a/src/gui/kernel/qguiapplication.h
+++ b/src/gui/kernel/qguiapplication.h
@@ -104,6 +104,7 @@ public:
static QScreen *primaryScreen();
static QList<QScreen *> screens();
+ qreal devicePixelRatio() const;
#ifndef QT_NO_CURSOR
static QCursor *overrideCursor();
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index 211a9650dc..ab2fdfa409 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -161,6 +161,18 @@ QDpi QPlatformScreen::logicalDpi() const
}
/*!
+ Reimplement this function in subclass to return the device pixel
+ ratio for the screen. This is the ratio between physical pixels
+ and device-independent pixels.
+
+ \sa QPlatformWindow::devicePixelRatio();
+*/
+qreal QPlatformScreen::devicePixelRatio() const
+{
+ return 1.0;
+}
+
+/*!
Reimplement this function in subclass to return the vertical refresh rate
of the screen, in Hz.
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index 493a1cedd0..91365b1cf0 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -98,6 +98,7 @@ public:
virtual QSizeF physicalSize() const;
virtual QDpi logicalDpi() const;
+ virtual qreal devicePixelRatio() const;
virtual qreal refreshRate() const;
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp
index 3bf06c6ab1..25b863c9a3 100644
--- a/src/gui/kernel/qplatformwindow.cpp
+++ b/src/gui/kernel/qplatformwindow.cpp
@@ -355,6 +355,18 @@ Qt::ScreenOrientation QPlatformWindow::requestWindowOrientation(Qt::ScreenOrient
return Qt::PrimaryOrientation;
}
+/*!
+ Reimplement this function in subclass to return the device pixel ratio
+ for the window. This is the ratio between physical pixels
+ and device-independent pixels.
+
+ \sa QPlatformWindow::devicePixelRatio();
+*/
+qreal QPlatformWindow::devicePixelRatio() const
+{
+ return 1.0;
+}
+
bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
{
Q_UNUSED(grab);
diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h
index 12650d6073..607c8e4035 100644
--- a/src/gui/kernel/qplatformwindow.h
+++ b/src/gui/kernel/qplatformwindow.h
@@ -117,6 +117,8 @@ public:
virtual void handleContentOrientationChange(Qt::ScreenOrientation orientation);
virtual Qt::ScreenOrientation requestWindowOrientation(Qt::ScreenOrientation orientation);
+ virtual qreal devicePixelRatio() const;
+
virtual bool setKeyboardGrabEnabled(bool grab);
virtual bool setMouseGrabEnabled(bool grab);
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 0c30de498c..f5467ab742 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -214,6 +214,20 @@ qreal QScreen::logicalDotsPerInch() const
return (dpi.first + dpi.second) * qreal(0.5);
}
+/*
+ Returns the ratio between physical pixels and device-independent pixels for the screen.
+
+ Common values are 1.0 on normal displays and 2.0 on Apple retina displays.
+
+ \sa QWindow::devicePixelRatio();
+ \sa QGuiApplicaiton::devicePixelRatio();
+*/
+qreal QScreen::devicePixelRatio() const
+{
+ Q_D(const QScreen);
+ return d->platformScreen->devicePixelRatio();
+}
+
/*!
\property QScreen::physicalSize
\brief the screen's physical size (in millimeters)
diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h
index 48eaad94f7..fbbd886755 100644
--- a/src/gui/kernel/qscreen.h
+++ b/src/gui/kernel/qscreen.h
@@ -109,6 +109,8 @@ public:
qreal logicalDotsPerInchY() const;
qreal logicalDotsPerInch() const;
+ qreal devicePixelRatio() const;
+
QSize availableSize() const;
QRect availableGeometry() const;
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index c24609e886..aaf2b25ad4 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -806,6 +806,24 @@ Qt::ScreenOrientation QWindow::orientation() const
}
/*!
+ Returns the ratio between physical pixels and device-independent pixels
+ for the window. This value is dependent on the screen the window is on,
+ and may change when the window is moved.
+
+ Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays.
+
+ \sa QWindow::devicePixelRatio();
+ \sa QGuiApplicaiton::devicePixelRatio();
+*/
+qreal QWindow::devicePixelRatio() const
+{
+ Q_D(const QWindow);
+ if (!d->platformWindow)
+ return 1.0;
+ return d->platformWindow->devicePixelRatio();
+}
+
+/*!
\brief set the screen-occupation state of the window
The window \a state represents whether the window appears in the
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index e6c9a3736f..229275d7c7 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -184,6 +184,8 @@ public:
void reportContentOrientationChange(Qt::ScreenOrientation orientation);
Qt::ScreenOrientation contentOrientation() const;
+ qreal devicePixelRatio() const;
+
bool requestOrientation(Qt::ScreenOrientation orientation);
Qt::ScreenOrientation orientation() const;