summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-12-15 18:16:02 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-12-15 18:16:02 (GMT)
commitbf6ddf2631fbad3b7f1bac6469771910451bf84d (patch)
tree24255cb47e664714bb10736e12fe5ecaf335e435
parent567bcd38dd7a749ac0bc3cdd2432798ab1af74fe (diff)
parentdf30d58de183d13c649ef7e0fbb8e2b3658e0862 (diff)
downloadQt-bf6ddf2631fbad3b7f1bac6469771910451bf84d.zip
Qt-bf6ddf2631fbad3b7f1bac6469771910451bf84d.tar.gz
Qt-bf6ddf2631fbad3b7f1bac6469771910451bf84d.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/qt-multimedia-staging: Removed obsolete Maemo 5 code QScroller: nicer Overshoot bounce back animation. Use XRandR to get the real DPI values for the screen. Resolve XRRSizes() from libxrandr for QScroller's DPI calculation. Fix drag velocity smoothing in QScroller. Make QScroller examples Qt-namespace safe.
-rw-r--r--examples/scroller/plot/plotwidget.h3
-rw-r--r--examples/scroller/plot/settingswidget.cpp2
-rw-r--r--examples/scroller/plot/settingswidget.h2
-rw-r--r--examples/scroller/wheel/wheelwidget.h2
-rw-r--r--src/gui/kernel/qapplication_x11.cpp3
-rw-r--r--src/gui/kernel/qt_x11_p.h2
-rw-r--r--src/gui/util/qscroller.cpp57
-rw-r--r--src/gui/util/qscrollerproperties.cpp31
8 files changed, 53 insertions, 49 deletions
diff --git a/examples/scroller/plot/plotwidget.h b/examples/scroller/plot/plotwidget.h
index 3b4d92d..4987ebc 100644
--- a/examples/scroller/plot/plotwidget.h
+++ b/examples/scroller/plot/plotwidget.h
@@ -45,10 +45,11 @@
#include <QWidget>
#include <QPointF>
+QT_BEGIN_NAMESPACE
class QPushButton;
class QLabel;
-
class QScroller;
+QT_END_NAMESPACE
class PlotWidget : public QWidget
{
diff --git a/examples/scroller/plot/settingswidget.cpp b/examples/scroller/plot/settingswidget.cpp
index af1e621..840e3fc 100644
--- a/examples/scroller/plot/settingswidget.cpp
+++ b/examples/scroller/plot/settingswidget.cpp
@@ -348,7 +348,7 @@ private:
MetricItem items[] = {
{ METRIC(MousePressEventDelay), 1000, "ms", qreal(0), qreal(2000), qreal(10) },
{ METRIC(DragStartDistance), 1000, "mm", qreal(1), qreal(20), qreal(0.1) },
- { METRIC(DragVelocitySmoothingFactor), 1, "", qreal(0), qreal(1), qreal(0.01) },
+ { METRIC(DragVelocitySmoothingFactor), 1, "", qreal(0), qreal(1), qreal(0.1) },
{ METRIC(AxisLockThreshold), 1, "", qreal(0), qreal(1), qreal(0.01) },
{ METRIC(ScrollingCurve), 1, "", QEasingCurve(), 0, 0 },
diff --git a/examples/scroller/plot/settingswidget.h b/examples/scroller/plot/settingswidget.h
index 2fb268c..0ea201d 100644
--- a/examples/scroller/plot/settingswidget.h
+++ b/examples/scroller/plot/settingswidget.h
@@ -44,12 +44,14 @@
#include <QScrollArea>
+QT_BEGIN_NAMESPACE
class QScroller;
class QGridLayout;
class QSpinBox;
class QComboBox;
class QCheckBox;
class QPlainTextEdit;
+QT_END_NAMESPACE
class MetricItemUpdater;
class SnapOverlay;
diff --git a/examples/scroller/wheel/wheelwidget.h b/examples/scroller/wheel/wheelwidget.h
index 818b6ab..c50f951 100644
--- a/examples/scroller/wheel/wheelwidget.h
+++ b/examples/scroller/wheel/wheelwidget.h
@@ -45,8 +45,10 @@
#include <QWidget>
#include <QStringList>
+QT_BEGIN_NAMESPACE
class QPainter;
class QRect;
+QT_END_NAMESPACE
class AbstractWheelWidget : public QWidget {
Q_OBJECT
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index ff98229..58ccda2 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -2015,12 +2015,15 @@ void qt_init(QApplicationPrivate *priv, int,
(PtrXRRRootToScreen) xrandrLib.resolve("XRRRootToScreen");
X11->ptrXRRQueryExtension =
(PtrXRRQueryExtension) xrandrLib.resolve("XRRQueryExtension");
+ X11->ptrXRRSizes =
+ (PtrXRRSizes) xrandrLib.resolve("XRRSizes");
}
# else
X11->ptrXRRSelectInput = XRRSelectInput;
X11->ptrXRRUpdateConfiguration = XRRUpdateConfiguration;
X11->ptrXRRRootToScreen = XRRRootToScreen;
X11->ptrXRRQueryExtension = XRRQueryExtension;
+ X11->ptrXRRSizes = XRRSizes;
# endif
if (X11->ptrXRRQueryExtension
diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h
index 56c8094..d97264c 100644
--- a/src/gui/kernel/qt_x11_p.h
+++ b/src/gui/kernel/qt_x11_p.h
@@ -226,6 +226,7 @@ typedef void (*PtrXRRSelectInput)(Display *, Window, int);
typedef int (*PtrXRRUpdateConfiguration)(XEvent *);
typedef int (*PtrXRRRootToScreen)(Display *, Window);
typedef Bool (*PtrXRRQueryExtension)(Display *, int *, int *);
+typedef XRRScreenSize *(*PtrXRRSizes)(Display *, int, int *);
#endif // QT_NO_XRANDR
#ifndef QT_NO_XINPUT
@@ -710,6 +711,7 @@ struct QX11Data
PtrXRRUpdateConfiguration ptrXRRUpdateConfiguration;
PtrXRRRootToScreen ptrXRRRootToScreen;
PtrXRRQueryExtension ptrXRRQueryExtension;
+ PtrXRRSizes ptrXRRSizes;
#endif // QT_NO_XRANDR
};
diff --git a/src/gui/util/qscroller.cpp b/src/gui/util/qscroller.cpp
index b7b5903..2ca4a6e 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
@@ -1046,6 +1058,9 @@ void QScrollerPrivate::setDpiFromWidget(QWidget *widget)
*/
void QScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint64 deltaTime)
{
+ if (deltaTime <= 0)
+ return;
+
Q_Q(QScroller);
QPointF ppm = q->pixelPerMeter();
const QScrollerPropertiesPrivate *sp = properties.d.data();
@@ -1057,14 +1072,12 @@ void QScrollerPrivate::updateVelocity(const QPointF &deltaPixelRaw, qint64 delta
if (((deltaPixelRaw / qreal(deltaTime)).manhattanLength() / ((ppm.x() + ppm.y()) / 2) * 1000) > qreal(2.5))
deltaPixel = deltaPixelRaw * qreal(2.5) * ppm / 1000 / (deltaPixelRaw / qreal(deltaTime)).manhattanLength();
- qreal inversSmoothingFactor = ((qreal(1) - sp->dragVelocitySmoothingFactor) * qreal(deltaTime) / qreal(1000));
QPointF newv = -deltaPixel / qreal(deltaTime) * qreal(1000) / ppm;
- newv = newv * (qreal(1) - inversSmoothingFactor) + releaseVelocity * inversSmoothingFactor;
+ if (releaseVelocity != QPointF(0, 0))
+ newv = newv * sp->dragVelocitySmoothingFactor + releaseVelocity * (qreal(1) - sp->dragVelocitySmoothingFactor);
- if (deltaPixel.x())
- releaseVelocity.setX(qBound(-sp->maximumVelocity, newv.x(), sp->maximumVelocity));
- if (deltaPixel.y())
- releaseVelocity.setY(qBound(-sp->maximumVelocity, newv.y(), sp->maximumVelocity));
+ releaseVelocity.setX(qBound(-sp->maximumVelocity, newv.x(), sp->maximumVelocity));
+ releaseVelocity.setY(qBound(-sp->maximumVelocity, newv.y(), sp->maximumVelocity));
qScrollerDebug() << " --> new velocity:" << releaseVelocity;
}
@@ -1354,9 +1367,8 @@ void QScrollerPrivate::createScrollingSegments(qreal v, qreal startPos, qreal pp
qreal oDistance = viewSize * sp->overshootScrollDistanceFactor * endV / sp->maximumVelocity;
qreal oDeltaTime = sp->overshootScrollTime;
- pushSegment(ScrollTypeOvershoot, oDeltaTime * 0.5, stopPos, stopPos + oDistance, sp->scrollingCurve.type(), orientation);
- pushSegment(ScrollTypeOvershoot, oDeltaTime * 0.3, stopPos + oDistance, stopPos + oDistance * 0.3, QEasingCurve::InQuad, orientation);
- pushSegment(ScrollTypeOvershoot, oDeltaTime * 0.2, stopPos + oDistance * 0.3, stopPos, QEasingCurve::OutQuad, orientation);
+ pushSegment(ScrollTypeOvershoot, oDeltaTime * 0.3, stopPos, stopPos + oDistance, sp->scrollingCurve.type(), orientation);
+ pushSegment(ScrollTypeOvershoot, oDeltaTime * 0.7, stopPos + oDistance, stopPos, sp->scrollingCurve.type(), orientation);
}
return;
}
@@ -1569,6 +1581,9 @@ bool QScrollerPrivate::releaseWhileDragging(const QPointF &position, qint64 time
Q_Q(QScroller);
const QScrollerPropertiesPrivate *sp = properties.d.data();
+ // handleDrag updates lastPosition, lastTimestamp and velocity
+ handleDrag(position, timestamp);
+
// check if we moved at all - this can happen if you stop a running
// scroller with a press and release shortly afterwards
QPointF deltaPixel = position - pressPosition;
diff --git a/src/gui/util/qscrollerproperties.cpp b/src/gui/util/qscrollerproperties.cpp
index d21f131..2e52959 100644
--- a/src/gui/util/qscrollerproperties.cpp
+++ b/src/gui/util/qscrollerproperties.cpp
@@ -58,31 +58,9 @@ QScrollerPropertiesPrivate *QScrollerPropertiesPrivate::defaults()
{
if (!systemDefaults) {
QScrollerPropertiesPrivate spp;
-#ifdef Q_WS_MAEMO_5
- spp.mousePressEventDelay = qreal(0);
- spp.dragStartDistance = qreal(2.5 / 1000);
- spp.dragVelocitySmoothingFactor = qreal(0.15);
- spp.axisLockThreshold = qreal(0);
- spp.scrollingCurve.setType(QEasingCurve::OutQuad);
- spp.decelerationFactor = 1.0;
- spp.minimumVelocity = qreal(0.0195);
- spp.maximumVelocity = qreal(6.84);
- spp.maximumClickThroughVelocity = qreal(0.0684);
- spp.acceleratingFlickMaximumTime = qreal(0.125);
- spp.acceleratingFlickSpeedupFactor = qreal(3.0);
- spp.snapPositionRatio = qreal(0.25);
- spp.snapTime = qreal(1);
- spp.overshootDragResistanceFactor = qreal(1);
- spp.overshootDragDistanceFactor = qreal(0.3);
- spp.overshootScrollDistanceFactor = qreal(0.3);
- spp.overshootScrollTime = qreal(0.5);
- spp.hOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;
- spp.vOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;
- spp.frameRate = QScrollerProperties::Fps30;
-#else
spp.mousePressEventDelay = qreal(0.25);
spp.dragStartDistance = qreal(5.0 / 1000);
- spp.dragVelocitySmoothingFactor = qreal(0.02);
+ spp.dragVelocitySmoothingFactor = qreal(0.8);
spp.axisLockThreshold = qreal(0);
spp.scrollingCurve.setType(QEasingCurve::OutQuad);
spp.decelerationFactor = qreal(0.125);
@@ -104,7 +82,7 @@ QScrollerPropertiesPrivate *QScrollerPropertiesPrivate::defaults()
spp.hOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;
spp.vOvershootPolicy = QScrollerProperties::OvershootWhenScrollable;
spp.frameRate = QScrollerProperties::Standard;
-#endif
+
systemDefaults = new QScrollerPropertiesPrivate(spp);
}
return new QScrollerPropertiesPrivate(userDefaults ? *userDefaults : *systemDefaults);
@@ -342,8 +320,9 @@ void QScrollerProperties::setScrollMetric(ScrollMetric metric, const QVariant &v
moved before the flick gesture is triggered in \c m.
\value DragVelocitySmoothingFactor A value that describes how much new drag velocities are
- included in the final scrolling velocity. This value should be in the range between \c 0 and \c
- 1. Low values meaning that the last dragging velocity is not very important.
+ included in the final scrolling velocity. This value should be in the range between \c 0 and
+ \c 1. The lower the value, the more smoothing will be applied to the dragging velocity. The
+ default value is \c 0.8.
\value AxisLockThreshold If greater than zero a scroll movement will be restricted to one axis
only if the movement is inside an angle about the axis. The threshold must be in the range \c 0