summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-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
4 files changed, 46 insertions, 47 deletions
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