2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the $MODULE$ of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtGui>
|
2011-09-16 12:07:05 +00:00
|
|
|
#include <QtWidgets>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtTest>
|
2020-03-27 16:06:11 +00:00
|
|
|
#include <QtGui/private/qevent_p.h>
|
2012-07-26 11:23:28 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
2012-07-26 16:48:56 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
// #include <QDebug>
|
|
|
|
|
|
|
|
class tst_QScrollerWidget : public QWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
tst_QScrollerWidget()
|
|
|
|
: QWidget()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
receivedPrepare = false;
|
|
|
|
receivedScroll = false;
|
|
|
|
receivedFirst = false;
|
|
|
|
receivedLast = false;
|
|
|
|
receivedOvershoot = false;
|
|
|
|
}
|
|
|
|
|
2020-09-10 18:39:49 +00:00
|
|
|
bool event(QEvent *e) override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::Gesture:
|
|
|
|
e->setAccepted(false); // better reject the event or QGestureManager will make trouble
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case QEvent::ScrollPrepare:
|
|
|
|
{
|
|
|
|
receivedPrepare = true;
|
|
|
|
QScrollPrepareEvent *se = static_cast<QScrollPrepareEvent *>(e);
|
|
|
|
se->setViewportSize(QSizeF(100,100));
|
|
|
|
se->setContentPosRange(scrollArea);
|
|
|
|
se->setContentPos(scrollPosition);
|
|
|
|
se->accept();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case QEvent::Scroll:
|
|
|
|
{
|
|
|
|
receivedScroll = true;
|
|
|
|
QScrollEvent *se = static_cast<QScrollEvent *>(e);
|
|
|
|
// qDebug() << "Scroll for"<<this<<"pos"<<se->scrollPos()<<"ov"<<se->overshoot()<<"first"<<se->isFirst()<<"last"<<se->isLast();
|
|
|
|
|
|
|
|
if (se->scrollState() == QScrollEvent::ScrollStarted)
|
|
|
|
receivedFirst = true;
|
|
|
|
if (se->scrollState() == QScrollEvent::ScrollFinished)
|
|
|
|
receivedLast = true;
|
|
|
|
|
|
|
|
currentPos = se->contentPos();
|
|
|
|
overshoot = se->overshootDistance();
|
2020-04-01 15:51:59 +00:00
|
|
|
if (!qFuzzyCompare(overshoot.x() + 1.0, 1.0) ||
|
|
|
|
!qFuzzyCompare(overshoot.y() + 1.0, 1.0))
|
2011-04-27 10:05:43 +00:00
|
|
|
receivedOvershoot = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QObject::event(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF scrollArea;
|
|
|
|
QPointF scrollPosition;
|
|
|
|
|
|
|
|
bool receivedPrepare;
|
|
|
|
bool receivedScroll;
|
|
|
|
bool receivedFirst;
|
|
|
|
bool receivedLast;
|
|
|
|
bool receivedOvershoot;
|
|
|
|
|
|
|
|
QPointF currentPos;
|
|
|
|
QPointF overshoot;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class tst_QScroller : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_QScroller() { }
|
|
|
|
~tst_QScroller() { }
|
|
|
|
|
|
|
|
private:
|
2020-04-01 15:51:59 +00:00
|
|
|
void kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd);
|
|
|
|
void kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void staticScrollers();
|
|
|
|
void scrollerProperties();
|
|
|
|
void scrollTo();
|
|
|
|
void scroll();
|
|
|
|
void overshoot();
|
2018-11-27 09:47:52 +00:00
|
|
|
void multipleWindows();
|
2016-05-03 16:27:12 +00:00
|
|
|
|
|
|
|
private:
|
Introduce QInputDevice hierarchy; replace QTouchDevice
We have seen during the Qt 5 series that QMouseEvent::source() does
not provide enough information: if it is synthesized, it could have
come from any device for which mouse events are synthesized, not only
from a touchscreen. By providing in every QInputEvent as complete
information about the actual source device as possible, we will enable
very fine-tuned behavior in the object that handles each event.
Further, we would like to support multiple keyboards, pointing devices,
and named groups of devices that are known as "seats" in Wayland.
In Qt 5, QPA plugins registered each touchscreen as it was discovered.
Now we extend this pattern to all input devices. This new requirement
can be implemented gradually; for now, if a QTWSI input event is
received wtihout a device pointer, a default "core" device will be
created on-the-fly, and a warning emitted.
In Qt 5, QTouchEvent::TouchPoint::id() was forced to be unique even when
multiple devices were in use simultaneously. Now that each event
identifies the device it came from, this hack is no longer needed.
A stub of the new QPointerEvent is added; it will be developed further
in subsequent patches.
[ChangeLog][QtGui][QInputEvent] Every QInputEvent now carries a pointer
to an instance of QInputDevice, or the subclass QPointingDevice in case
of mouse, touch and tablet events. Each platform plugin is expected to
create the device instances, register them, and provide valid pointers
with all input events. If this is not done, warnings are emitted and
default devices are created as necessary. When the device has accurate
information, it provides the opportunity to fine-tune behavior depending
on device type and capabilities: for example if a QMouseEvent is
synthesized from a touchscreen, the recipient can see which touchscreen
it came from. Each device also has a seatName to distinguish users on
multi-user windowing systems. Touchpoint IDs are no longer unique on
their own, but the combination of ID and device is.
Fixes: QTBUG-46412
Fixes: QTBUG-72167
Task-number: QTBUG-69433
Task-number: QTBUG-52430
Change-Id: I933fb2b86182efa722037b7a33e404c5daf5292a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2019-05-31 06:38:16 +00:00
|
|
|
QPointingDevice *m_touchScreen = QTest::createTouchDevice();
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! \internal
|
|
|
|
Generates touchBegin, touchUpdate and touchEnd events to trigger scrolling.
|
|
|
|
Tests some in between states but does not wait until scrolling is finished.
|
|
|
|
*/
|
2020-04-01 15:51:59 +00:00
|
|
|
void tst_QScroller::kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
sw->scrollPosition = from;
|
|
|
|
sw->currentPos= from;
|
|
|
|
|
|
|
|
QScroller *s1 = QScroller::scroller(sw);
|
2020-04-01 15:51:59 +00:00
|
|
|
QCOMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QScrollerProperties sp1 = QScroller::scroller(sw)->scrollerProperties();
|
|
|
|
|
|
|
|
// send the touch begin event
|
2020-03-27 16:06:11 +00:00
|
|
|
QMutableEventPoint touchPoint(0);
|
|
|
|
touchPoint.setState(QEventPoint::State::Pressed);
|
|
|
|
touchPoint.setPosition(touchStart);
|
|
|
|
touchPoint.setScenePosition(touchStart);
|
|
|
|
touchPoint.setGlobalPosition(touchStart);
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent1(QEvent::TouchBegin,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
|
|
|
(QList<QTouchEvent::TouchPoint>() << touchPoint));
|
2020-03-27 16:06:11 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent1);
|
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QCOMPARE(s1->state(), QScroller::Pressed);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// send the touch update far enough to trigger a scroll
|
|
|
|
QTest::qWait(200); // we need to wait a little or else the speed would be infinite. now we have around 500 pixel per second.
|
2020-03-27 16:06:11 +00:00
|
|
|
touchPoint.setPosition(touchUpdate);
|
|
|
|
touchPoint.setScenePosition(touchUpdate);
|
|
|
|
touchPoint.setGlobalPosition(touchUpdate);
|
|
|
|
touchPoint.setState(QEventPoint::State::Updated);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent2(QEvent::TouchUpdate,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
2020-03-27 16:06:11 +00:00
|
|
|
(QList<QEventPoint>() << touchPoint));
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent2);
|
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QCOMPARE(s1->state(), QScroller::Dragging);
|
|
|
|
QCOMPARE(sw->receivedPrepare, true);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QTRY_COMPARE(sw->receivedFirst, true);
|
|
|
|
QCOMPARE(sw->receivedScroll, true);
|
|
|
|
QCOMPARE(sw->receivedOvershoot, false);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// note that the scrolling goes in a different direction than the mouse move
|
|
|
|
QPoint calculatedPos = from.toPoint() - touchUpdate - touchStart;
|
|
|
|
QVERIFY(qAbs(sw->currentPos.x() - calculatedPos.x()) < 1.0);
|
|
|
|
QVERIFY(qAbs(sw->currentPos.y() - calculatedPos.y()) < 1.0);
|
|
|
|
|
|
|
|
// send the touch end
|
2020-03-27 16:06:11 +00:00
|
|
|
touchPoint.setPosition(touchEnd);
|
|
|
|
touchPoint.setScenePosition(touchEnd);
|
|
|
|
touchPoint.setGlobalPosition(touchEnd);
|
|
|
|
touchPoint.setState(QEventPoint::State::Released);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent5(QEvent::TouchEnd,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
2020-03-27 16:06:11 +00:00
|
|
|
(QList<QEventPoint>() << touchPoint));
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \internal
|
|
|
|
Generates touchBegin, touchUpdate and touchEnd events to trigger scrolling.
|
|
|
|
This function does not have any in between tests, it does not expect the scroller to actually scroll.
|
|
|
|
*/
|
2020-04-01 15:51:59 +00:00
|
|
|
void tst_QScroller::kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, QPoint touchStart, QPoint touchUpdate, QPoint touchEnd)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
sw->scrollPosition = from;
|
|
|
|
sw->currentPos = from;
|
|
|
|
|
|
|
|
QScroller *s1 = QScroller::scroller(sw);
|
2020-04-01 15:51:59 +00:00
|
|
|
QCOMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QScrollerProperties sp1 = s1->scrollerProperties();
|
|
|
|
int fps = 60;
|
|
|
|
|
|
|
|
// send the touch begin event
|
2020-03-27 16:06:11 +00:00
|
|
|
QMutableEventPoint touchPoint(0);
|
|
|
|
touchPoint.setState(QEventPoint::State::Pressed);
|
|
|
|
touchPoint.setPosition(touchStart);
|
|
|
|
touchPoint.setScenePosition(touchStart);
|
|
|
|
touchPoint.setGlobalPosition(touchStart);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent1(QEvent::TouchBegin,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
2020-03-27 16:06:11 +00:00
|
|
|
(QList<QEventPoint>() << touchPoint));
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent1);
|
|
|
|
|
|
|
|
// send the touch update far enough to trigger a scroll
|
|
|
|
QTest::qWait(200); // we need to wait a little or else the speed would be infinite. now we have around 500 pixel per second.
|
2020-03-27 16:06:11 +00:00
|
|
|
touchPoint.setState(QEventPoint::State::Updated);
|
|
|
|
touchPoint.setPosition(touchUpdate);
|
|
|
|
touchPoint.setScenePosition(touchUpdate);
|
|
|
|
touchPoint.setGlobalPosition(touchUpdate);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent2(QEvent::TouchUpdate,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
2020-03-27 16:06:11 +00:00
|
|
|
(QList<QEventPoint>() << touchPoint));
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent2);
|
|
|
|
|
|
|
|
QTest::qWait(1000 / fps * 2); // wait until the first scroll move
|
|
|
|
|
|
|
|
// send the touch end
|
2020-03-27 16:06:11 +00:00
|
|
|
touchPoint.setState(QEventPoint::State::Released);
|
|
|
|
touchPoint.setPosition(touchEnd);
|
|
|
|
touchPoint.setScenePosition(touchEnd);
|
|
|
|
touchPoint.setGlobalPosition(touchEnd);
|
2011-04-27 10:05:43 +00:00
|
|
|
QTouchEvent touchEvent5(QEvent::TouchEnd,
|
2016-05-03 16:27:12 +00:00
|
|
|
m_touchScreen,
|
2011-04-27 10:05:43 +00:00
|
|
|
Qt::NoModifier,
|
2020-03-27 16:06:11 +00:00
|
|
|
(QList<QEventPoint>() << touchPoint));
|
2011-04-27 10:05:43 +00:00
|
|
|
QApplication::sendEvent(sw, &touchEvent5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_QScroller::staticScrollers()
|
|
|
|
{
|
|
|
|
// scrollers
|
|
|
|
{
|
|
|
|
QObject *o1 = new QObject(this);
|
|
|
|
QObject *o2 = new QObject(this);
|
|
|
|
|
|
|
|
// get scroller for object
|
|
|
|
QScroller *s1 = QScroller::scroller(o1);
|
|
|
|
QScroller *s2 = QScroller::scroller(o2);
|
|
|
|
|
|
|
|
QVERIFY(s1);
|
|
|
|
QVERIFY(s2);
|
|
|
|
QVERIFY(s1 != s2);
|
|
|
|
|
|
|
|
QVERIFY(!QScroller::scroller(static_cast<const QObject*>(0)));
|
|
|
|
QCOMPARE(QScroller::scroller(o1), s1);
|
|
|
|
|
|
|
|
delete o1;
|
|
|
|
delete o2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the same for properties
|
|
|
|
{
|
|
|
|
QObject *o1 = new QObject(this);
|
|
|
|
QObject *o2 = new QObject(this);
|
|
|
|
|
|
|
|
// get scroller for object
|
|
|
|
QScrollerProperties sp1 = QScroller::scroller(o1)->scrollerProperties();
|
|
|
|
QScrollerProperties sp2 = QScroller::scroller(o2)->scrollerProperties();
|
|
|
|
|
|
|
|
// default properties should be the same
|
2015-07-30 13:16:36 +00:00
|
|
|
QCOMPARE(sp1, sp2);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(QScroller::scroller(o1)->scrollerProperties(), sp1);
|
|
|
|
|
|
|
|
delete o1;
|
|
|
|
delete o2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QScroller::scrollerProperties()
|
|
|
|
{
|
|
|
|
QObject *o1 = new QObject(this);
|
|
|
|
QScrollerProperties sp1 = QScroller::scroller(o1)->scrollerProperties();
|
|
|
|
|
|
|
|
QScrollerProperties::ScrollMetric metrics[] =
|
|
|
|
{
|
|
|
|
QScrollerProperties::MousePressEventDelay, // qreal [s]
|
|
|
|
QScrollerProperties::DragStartDistance, // qreal [m]
|
|
|
|
QScrollerProperties::DragVelocitySmoothingFactor, // qreal [0..1/s] (complex calculation involving time) v = v_new* DASF + v_old * (1-DASF)
|
|
|
|
QScrollerProperties::AxisLockThreshold, // qreal [0..1] atan(|min(dx,dy)|/|max(dx,dy)|)
|
|
|
|
|
|
|
|
QScrollerProperties::DecelerationFactor, // slope of the curve
|
|
|
|
|
|
|
|
QScrollerProperties::MinimumVelocity, // qreal [m/s]
|
|
|
|
QScrollerProperties::MaximumVelocity, // qreal [m/s]
|
|
|
|
QScrollerProperties::MaximumClickThroughVelocity, // qreal [m/s]
|
|
|
|
|
|
|
|
QScrollerProperties::AcceleratingFlickMaximumTime, // qreal [s]
|
|
|
|
QScrollerProperties::AcceleratingFlickSpeedupFactor, // qreal [1..]
|
|
|
|
|
|
|
|
QScrollerProperties::SnapPositionRatio, // qreal [0..1]
|
|
|
|
QScrollerProperties::SnapTime, // qreal [s]
|
|
|
|
|
|
|
|
QScrollerProperties::OvershootDragResistanceFactor, // qreal [0..1]
|
|
|
|
QScrollerProperties::OvershootDragDistanceFactor, // qreal [0..1]
|
|
|
|
QScrollerProperties::OvershootScrollDistanceFactor, // qreal [0..1]
|
|
|
|
QScrollerProperties::OvershootScrollTime, // qreal [s]
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < sizeof(metrics) / sizeof(metrics[0]); i++) {
|
|
|
|
sp1.setScrollMetric(metrics[i], 0.9);
|
|
|
|
QCOMPARE(sp1.scrollMetric(metrics[i]).toDouble(), 0.9);
|
|
|
|
}
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::ScrollingCurve, QEasingCurve(QEasingCurve::OutQuart));
|
|
|
|
QCOMPARE(sp1.scrollMetric(QScrollerProperties::ScrollingCurve).toEasingCurve().type(), QEasingCurve::OutQuart);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOff));
|
|
|
|
QCOMPARE(sp1.scrollMetric(QScrollerProperties::HorizontalOvershootPolicy).value<QScrollerProperties::OvershootPolicy>(), QScrollerProperties::OvershootAlwaysOff);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::VerticalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOn));
|
|
|
|
QCOMPARE(sp1.scrollMetric(QScrollerProperties::VerticalOvershootPolicy).value<QScrollerProperties::OvershootPolicy>(), QScrollerProperties::OvershootAlwaysOn);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::FrameRate, QVariant::fromValue(QScrollerProperties::Fps20));
|
|
|
|
QCOMPARE(sp1.scrollMetric(QScrollerProperties::FrameRate).value<QScrollerProperties::FrameRates>(), QScrollerProperties::Fps20);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QScroller::scrollTo()
|
|
|
|
{
|
2020-04-01 15:51:59 +00:00
|
|
|
QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget);
|
|
|
|
sw->show();
|
|
|
|
QApplication::setActiveWindow(sw.data());
|
|
|
|
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
|
|
|
|
QSKIP("Failed to show and activate window");
|
|
|
|
|
|
|
|
sw->scrollArea = QRectF(0, 0, 1000, 1000);
|
|
|
|
sw->scrollPosition = QPointF(500, 500);
|
|
|
|
|
|
|
|
QScroller *s1 = QScroller::scroller(sw.data());
|
|
|
|
QCOMPARE(s1->state(), QScroller::Inactive);
|
|
|
|
|
|
|
|
// a normal scroll
|
|
|
|
s1->scrollTo(QPointF(100,100), 100);
|
|
|
|
QTest::qWait(200);
|
|
|
|
|
|
|
|
QTRY_COMPARE(sw->receivedPrepare, true);
|
|
|
|
QCOMPARE(sw->receivedScroll, true);
|
|
|
|
QCOMPARE(sw->receivedFirst, true);
|
|
|
|
QCOMPARE(sw->receivedLast, true);
|
|
|
|
QCOMPARE(sw->receivedOvershoot, false);
|
|
|
|
QTRY_VERIFY(qFuzzyCompare(sw->currentPos.x(), 100));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 100));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QScroller::scroll()
|
|
|
|
{
|
2018-11-27 09:47:52 +00:00
|
|
|
#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
|
2011-04-27 10:05:43 +00:00
|
|
|
// -- good case. normal scroll
|
2020-04-01 15:51:59 +00:00
|
|
|
QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget());
|
2011-04-27 10:05:43 +00:00
|
|
|
sw->scrollArea = QRectF(0, 0, 1000, 1000);
|
2020-04-01 15:51:59 +00:00
|
|
|
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
|
2011-04-27 10:05:43 +00:00
|
|
|
sw->setGeometry(100, 100, 400, 300);
|
2020-04-01 15:51:59 +00:00
|
|
|
sw->show();
|
|
|
|
QApplication::setActiveWindow(sw.data());
|
|
|
|
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
|
|
|
|
QSKIP("Failed to show and activate window");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QScroller *s1 = QScroller::scroller(sw.data());
|
|
|
|
kineticScroll(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200));
|
2011-04-27 10:05:43 +00:00
|
|
|
// now we should be scrolling
|
2020-04-01 15:51:59 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Scrolling);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-03-07 21:40:54 +00:00
|
|
|
// wait until finished, check that no further first scroll is sent
|
2011-04-27 10:05:43 +00:00
|
|
|
sw->receivedFirst = false;
|
|
|
|
sw->receivedScroll = false;
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_VERIFY(s1->state() != QScroller::Scrolling);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QCOMPARE(sw->receivedFirst, false);
|
|
|
|
QCOMPARE(sw->receivedScroll, true);
|
|
|
|
QCOMPARE(sw->receivedLast, true);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(sw->currentPos.x() < 400);
|
|
|
|
QVERIFY(sw->currentPos.y() < 400);
|
|
|
|
|
|
|
|
// -- try to scroll when nothing to scroll
|
|
|
|
|
|
|
|
sw->reset();
|
|
|
|
sw->scrollArea = QRectF(0, 0, 0, 1000);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(100, 0), QPoint(200, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QCOMPARE(sw->currentPos.x(), 0.0);
|
|
|
|
QCOMPARE(sw->currentPos.y(), 500.0);
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-11-15 01:36:18 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
void tst_QScroller::overshoot()
|
|
|
|
{
|
2018-11-27 09:47:52 +00:00
|
|
|
#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
|
2020-04-01 15:51:59 +00:00
|
|
|
QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget);
|
2011-04-27 10:05:43 +00:00
|
|
|
sw->scrollArea = QRectF(0, 0, 1000, 1000);
|
2020-04-01 15:51:59 +00:00
|
|
|
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
|
2011-04-27 10:05:43 +00:00
|
|
|
sw->setGeometry(100, 100, 400, 300);
|
2020-04-01 15:51:59 +00:00
|
|
|
sw->show();
|
|
|
|
QApplication::setActiveWindow(sw.data());
|
|
|
|
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
|
|
|
|
QSKIP("Failed to show and activate window");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QScroller *s1 = QScroller::scroller(sw.data());
|
2011-04-27 10:05:43 +00:00
|
|
|
QScrollerProperties sp1 = s1->scrollerProperties();
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::OvershootDragResistanceFactor, 0.5);
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::OvershootDragDistanceFactor, 0.2);
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::OvershootScrollDistanceFactor, 0.2);
|
|
|
|
|
|
|
|
// -- try to scroll with overshoot (when scrollable good case)
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootWhenScrollable));
|
|
|
|
s1->setScrollerProperties(sp1);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//qDebug() << "Overshoot fuzzy: "<<sw->currentPos;
|
2020-04-01 15:51:59 +00:00
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500));
|
|
|
|
QCOMPARE(sw->receivedOvershoot, true);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// -- try to scroll with overshoot (when scrollable bad case)
|
|
|
|
sw->reset();
|
|
|
|
sw->scrollArea = QRectF(0, 0, 0, 1000);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootWhenScrollable));
|
|
|
|
s1->setScrollerProperties(sp1);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//qDebug() << "Overshoot fuzzy: "<<sw->currentPos;
|
2020-04-01 15:51:59 +00:00
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500));
|
|
|
|
QCOMPARE(sw->receivedOvershoot, false);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// -- try to scroll with overshoot (always on)
|
|
|
|
sw->reset();
|
|
|
|
sw->scrollArea = QRectF(0, 0, 0, 1000);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOn));
|
|
|
|
s1->setScrollerProperties(sp1);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(0, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//qDebug() << "Overshoot fuzzy: "<<sw->currentPos;
|
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500));
|
|
|
|
QCOMPARE(sw->receivedOvershoot, true);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// -- try to scroll with overshoot (always off)
|
|
|
|
sw->reset();
|
|
|
|
sw->scrollArea = QRectF(0, 0, 1000, 1000);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOff));
|
|
|
|
s1->setScrollerProperties(sp1);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500));
|
|
|
|
QCOMPARE(sw->receivedOvershoot, false);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// -- try to scroll with overshoot (always on but max overshoot = 0)
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::OvershootDragDistanceFactor, 0.0);
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::OvershootScrollDistanceFactor, 0.0);
|
|
|
|
sw->reset();
|
|
|
|
sw->scrollArea = QRectF(0, 0, 1000, 1000);
|
|
|
|
|
|
|
|
sp1.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QVariant::fromValue(QScrollerProperties::OvershootAlwaysOn));
|
|
|
|
s1->setScrollerProperties(sp1);
|
2020-04-01 15:51:59 +00:00
|
|
|
kineticScrollNoTest(sw.data(), QPointF(500, 500), QPoint(0, 0), QPoint(400, 0), QPoint(490, 0));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-04-04 06:50:22 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Inactive);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2020-04-01 15:51:59 +00:00
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.x(), 0));
|
|
|
|
QVERIFY(qFuzzyCompare(sw->currentPos.y(), 500));
|
|
|
|
QCOMPARE(sw->receivedOvershoot, false);
|
2011-10-04 03:23:23 +00:00
|
|
|
#endif
|
2011-11-15 01:36:18 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-11-27 09:47:52 +00:00
|
|
|
void tst_QScroller::multipleWindows()
|
|
|
|
{
|
|
|
|
#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
|
2020-04-01 15:51:59 +00:00
|
|
|
QScopedPointer<tst_QScrollerWidget> sw1(new tst_QScrollerWidget);
|
2018-11-27 09:47:52 +00:00
|
|
|
sw1->scrollArea = QRectF(0, 0, 1000, 1000);
|
|
|
|
QScroller::grabGesture(sw1.data(), QScroller::TouchGesture);
|
|
|
|
sw1->setGeometry(100, 100, 400, 300);
|
2020-04-01 15:51:59 +00:00
|
|
|
|
2018-11-27 09:47:52 +00:00
|
|
|
QScroller *s1 = QScroller::scroller(sw1.data());
|
|
|
|
kineticScroll(sw1.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200));
|
|
|
|
// now we should be scrolling
|
2020-04-01 15:51:59 +00:00
|
|
|
QTRY_COMPARE(s1->state(), QScroller::Scrolling);
|
2018-11-27 09:47:52 +00:00
|
|
|
|
|
|
|
// That was fun! Do it again!
|
|
|
|
QScopedPointer<tst_QScrollerWidget> sw2(new tst_QScrollerWidget());
|
|
|
|
sw2->scrollArea = QRectF(0, 0, 1000, 1000);
|
|
|
|
QScroller::grabGesture(sw2.data(), QScroller::TouchGesture);
|
|
|
|
sw2->setGeometry(100, 100, 400, 300);
|
2020-04-01 15:51:59 +00:00
|
|
|
|
2018-11-27 09:47:52 +00:00
|
|
|
QScroller *s2 = QScroller::scroller(sw2.data());
|
|
|
|
kineticScroll(sw2.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200));
|
|
|
|
// now we should be scrolling
|
2020-04-01 15:51:59 +00:00
|
|
|
QTRY_COMPARE(s2->state(), QScroller::Scrolling);
|
2018-11-27 09:47:52 +00:00
|
|
|
|
|
|
|
// wait for both to stop
|
|
|
|
QTRY_VERIFY(s1->state() != QScroller::Scrolling);
|
|
|
|
QTRY_VERIFY(s2->state() != QScroller::Scrolling);
|
|
|
|
|
|
|
|
sw1.reset(); // destroy one window
|
|
|
|
sw2->reset(); // reset the other scroller's internal state
|
|
|
|
// make sure we can still scroll the remaining one without crashing (QTBUG-71232)
|
|
|
|
kineticScroll(sw2.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_QScroller)
|
|
|
|
|
|
|
|
#include "tst_qscroller.moc"
|