diff options
author | Robert Griebl <robert.griebl@nokia.com> | 2010-12-15 17:22:15 (GMT) |
---|---|---|
committer | Robert Griebl <robert.griebl@nokia.com> | 2010-12-15 17:51:00 (GMT) |
commit | b78ffe51f9a4c4ac705e435d45fffe39864c032d (patch) | |
tree | 286fd0876aae4264e4ea602c276370541766e3b9 /src/gui/util | |
parent | 82bbc1c1611bde33680d22a1a3c6449e51d7b0b9 (diff) | |
download | Qt-b78ffe51f9a4c4ac705e435d45fffe39864c032d.zip Qt-b78ffe51f9a4c4ac705e435d45fffe39864c032d.tar.gz Qt-b78ffe51f9a4c4ac705e435d45fffe39864c032d.tar.bz2 |
Use XRandR to get the real DPI values for the screen.
This is needed for the Xomap server, but may also apply to others.
Reviewed-by: Ralf Engels
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qscroller.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/gui/util/qscroller.cpp b/src/gui/util/qscroller.cpp index 0955f58..f651a06 100644 --- a/src/gui/util/qscroller.cpp +++ b/src/gui/util/qscroller.cpp @@ -64,6 +64,10 @@ #include <QtDebug> +#if defined(Q_WS_X11) +# include "private/qt_x11_p.h" +#endif + QT_BEGIN_NAMESPACE @@ -986,38 +990,46 @@ bool QScroller::handleInput(Input input, const QPointF &position, qint64 timesta return false; } -#ifdef Q_WS_MAEMO_5 +#if !defined(Q_WS_MAC) +// the Mac version is implemented in qscroller_mac.mm QPointF QScrollerPrivate::realDpi(int screen) { +# ifdef Q_WS_MAEMO_5 Q_UNUSED(screen); + // The DPI value is hardcoded to 96 on Maemo5: // https://projects.maemo.org/bugzilla/show_bug.cgi?id=152525 // This value (260) is only correct for the N900 though, but // there's no way to get the real DPI at run time. return QPointF(260, 260); -} -#elif defined(Q_WS_MAC) - -// implemented in qscroller_mac.mm - -#else +# elif defined(Q_WS_X11) && !defined(QT_NO_XRANDR) + if (X11->use_xrandr && X11->ptrXRRSizes) { + int nsizes = 0; + XRRScreenSize *sizes = X11->ptrXRRSizes(X11->display, screen == -1 ? X11->defaultScreen : screen, &nsizes); + if (nsizes > 0 && sizes && sizes->width && sizes->height && sizes->mwidth && sizes->mheight) { + qScrollerDebug() << "XRandR DPI:" << QPointF(qreal(25.4) * qreal(sizes->width) / qreal(sizes->mwidth), + qreal(25.4) * qreal(sizes->height) / qreal(sizes->mheight)); + return QPointF(qreal(25.4) * qreal(sizes->width) / qreal(sizes->mwidth), + qreal(25.4) * qreal(sizes->height) / qreal(sizes->mheight)); + } + } +# endif -QPointF QScrollerPrivate::realDpi(int screen) -{ QWidget *w = QApplication::desktop()->screen(screen); return QPointF(w->physicalDpiX(), w->physicalDpiY()); } -#endif +#endif // !Q_WS_MAC + /*! \internal Returns the resolution of the used screen. */ QPointF QScrollerPrivate::dpi() const { - return pixelPerMeter / qreal(39.3700787); + return pixelPerMeter * qreal(0.0254); } /*! \internal @@ -1028,7 +1040,7 @@ QPointF QScrollerPrivate::dpi() const */ void QScrollerPrivate::setDpi(const QPointF &dpi) { - pixelPerMeter = dpi * qreal(39.3700787); + pixelPerMeter = dpi / qreal(0.0254); } /*! \internal |