summaryrefslogtreecommitdiffstats
path: root/scroller
diff options
context:
space:
mode:
authorRobert Griebl <rgriebl@trolltech.com>2010-04-20 19:15:02 +0200
committerRobert Griebl <rgriebl@trolltech.com>2010-04-20 19:17:21 +0200
commita9fd40affd5aeedaf9224cb3583126308b078fa0 (patch)
tree9cad5e1583fb7e0da6af9263cd68cc0056610a29 /scroller
parentfe45b9c462461d3923b7eef8708a4112e95704ed (diff)
add nicer _real_ DPI getters for Mac and Maemo5
Diffstat (limited to 'scroller')
-rw-r--r--scroller/qkineticscroller.cpp28
-rw-r--r--scroller/qkineticscroller_mac.mm70
-rw-r--r--scroller/qkineticscroller_maemo5.cpp55
-rw-r--r--scroller/qkineticscroller_p.h2
-rw-r--r--scroller/scroller.pro3
5 files changed, 146 insertions, 12 deletions
diff --git a/scroller/qkineticscroller.cpp b/scroller/qkineticscroller.cpp
index b9c31a8..63ba4fc 100644
--- a/scroller/qkineticscroller.cpp
+++ b/scroller/qkineticscroller.cpp
@@ -480,22 +480,26 @@ void QKineticScroller::setDpi(qreal dpi)
d->pixelPerMeter = dpi * qreal(39.3700787);
}
-
void QKineticScroller::setDpiFromWidget(QWidget *widget)
{
-#ifdef Q_WS_MAEMO_5
- // 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.
- setDpi(qreal(260));
-#else
- if (!widget)
- widget = QApplication::desktop();
- setDpi(qreal(widget->physicalDpiX() + widget->physicalDpiY()) / qreal(2));
-#endif
+ Q_D(QKineticScroller);
+
+ QDesktopWidget *dw = QApplication::desktop();
+ QPointF dpi = d->realDpi(widget ? dw->screenNumber(widget) : dw->primaryScreen());
+ setDpi((dpi.x() + dpi.y()) / qreal(2));
}
+#if !defined(Q_WS_MAEMO_5) && !defined(Q_WS_MAC)
+
+QPointF QKineticScrollerPrivate::realDpi(int screen)
+{
+ QWidget *w = QApplication::desktop()->screen(screen);
+ return QPointF(w->physicalDpiX(), w->physicalDpiY());
+}
+
+#endif
+
+
void QKineticScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint64 deltaTime)
{
qKSDebug() << "QKS::updateVelocity(" << deltaPixelRaw << " [delta pix], " << deltaTime << " [delta ms])";
diff --git a/scroller/qkineticscroller_mac.mm b/scroller/qkineticscroller_mac.mm
new file mode 100644
index 0000000..50f76d0
--- /dev/null
+++ b/scroller/qkineticscroller_mac.mm
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+#include <QMacCocoaAutoReleasePool>
+
+#include "qkineticscroller_p.h"
+
+#ifdef Q_WS_MAC
+
+QPointF QKineticScrollerPrivate::realDpi(int screen)
+{
+ QMacCocoaAutoReleasePool pool;
+ NSArray *nsscreens = [NSScreen screens];
+
+ if (screen < 0 || screen >= [nsscreens count])
+ screen = 0;
+
+ NSScreen *nsscreen = [displays objectAtIndex:screen];
+ CGDirectDisplayID display = [[[nsscreen deviceDescription] objectForKey:@"NSScreenNumber"] pointerValue];
+
+ CGSize mmsize = CGDisplayScreenSize(display);
+ if (mmsize.width > 0 && mmsize.height > 0) {
+ return QPointF(CGDisplayPixelsWide(display) / mmsize.width,
+ CGDisplayPixelsHigh(display) / mmsize.height) * qreal(25.4);
+ } else {
+ return QPointF();
+ }
+}
+
+#endif
diff --git a/scroller/qkineticscroller_maemo5.cpp b/scroller/qkineticscroller_maemo5.cpp
new file mode 100644
index 0000000..4c6c9cc
--- /dev/null
+++ b/scroller/qkineticscroller_maemo5.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qkineticscroller_p.h"
+
+#ifdef Q_WS_MAEMO_5
+
+QPointF QKineticScrollerPrivate::realDpi(int 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);
+}
+
+#endif
diff --git a/scroller/qkineticscroller_p.h b/scroller/qkineticscroller_p.h
index 885f539..83fc48c 100644
--- a/scroller/qkineticscroller_p.h
+++ b/scroller/qkineticscroller_p.h
@@ -93,6 +93,8 @@ public:
QPointF calculateVelocity(qreal time);
void setContentPositionHelper(const QPointF &deltaPos);
+ QPointF realDpi(int screen);
+
static const char *stateName(QKineticScroller::State state);
static const char *inputName(QKineticScroller::Input input);
diff --git a/scroller/scroller.pro b/scroller/scroller.pro
index c815dad..a88d171 100644
--- a/scroller/scroller.pro
+++ b/scroller/scroller.pro
@@ -11,3 +11,6 @@ INCLUDEPATH += .
# Input
HEADERS += qkineticscroller.h qkineticscroller_p.h
SOURCES += qkineticscroller.cpp
+
+macx:SOURCES += qkineticscroller_mac.mm
+maemo5:SOURCES += qkineticscroller_maemo5.cpp