diff options
author | Ian Chen <ian.1.chen@nokia.com> | 2012-07-02 17:24:14 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-05 05:02:30 +0200 |
commit | 3e49bbe8a67f2b5524f7ac8aa2bf99a2ba2ec5ce (patch) | |
tree | c1ae42e7addefe5d004e95c35827323930b2e448 /tests/plugins | |
parent | 73e252e89cb11190430789952a0ccfb1bc64f1fb (diff) | |
download | qtlocation-3e49bbe8a67f2b5524f7ac8aa2bf99a2ba2ec5ce.tar.gz |
Fix PinchGenerator
Now use QTest::TouchEventSequence instead of
generating touch events and points itself.
Re-enable tests that rely on the pinch generator
Change-Id: If4dc3e05f244dd9dbf169a015e224219c087359d
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'tests/plugins')
3 files changed, 148 insertions, 314 deletions
diff --git a/tests/plugins/declarativetestplugin/declarativetestplugin.pro b/tests/plugins/declarativetestplugin/declarativetestplugin.pro index 9b244877..7d3c20f0 100644 --- a/tests/plugins/declarativetestplugin/declarativetestplugin.pro +++ b/tests/plugins/declarativetestplugin/declarativetestplugin.pro @@ -3,7 +3,7 @@ TARGETPATH = QtLocation/test include(../../../src/imports/location/qlocationimport.pri) -QT += qml quick location +QT += qml quick location testlib DESTDIR = $$QT.location.imports/$$TARGETPATH target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp index 382444d1..be2b9f9e 100644 --- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp +++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include <QtTest/QtTest> #include "qdeclarativepinchgenerator_p.h" #include <QtGui/QGuiApplication> @@ -50,24 +51,19 @@ QDeclarativePinchGenerator::QDeclarativePinchGenerator(): replayTimer_(-1), replayBookmark_(-1), masterSwipe_(-1), - touchPointId_(0), replaySpeedFactor_(1.0), enabled_(true) { setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton); swipeTimer_.invalidate(); + device_ = new QTouchDevice; + device_->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device_); } QDeclarativePinchGenerator::~QDeclarativePinchGenerator() { - if (!swipeList1_.isEmpty()) { - qDeleteAll(swipeList1_); - swipeList1_.clear(); - } - if (!swipeList2_.isEmpty()) { - qDeleteAll(swipeList2_); - swipeList2_.clear(); - } + clear(); } void QDeclarativePinchGenerator::componentComplete() @@ -84,70 +80,11 @@ void QDeclarativePinchGenerator::mousePressEvent(QMouseEvent *event) Q_ASSERT(!activeSwipe_); Q_ASSERT(!swipeTimer_.isValid()); // Start recording a pinch gesture. - QTouchEvent::TouchPoint touchPoint = mouseEventToTouchPoint(event); - if (touchPoint.state() == Qt::TouchPointPressed) { - activeSwipe_ = new Swipe; - //touchPointId_ = 0; - activeSwipe_->touchPoints.append(touchPoint); - activeSwipe_->totalDuration = 0; - activeSwipe_->touchPointDurations.append(0); - swipeTimer_.start(); - setState(Recording); - } else { - Q_ASSERT(false); // no! - } -} - -bool QDeclarativePinchGenerator::enabled() const -{ - return enabled_; -} - - -void QDeclarativePinchGenerator::setEnabled(bool enabled) -{ - if (enabled == enabled_) - return; - enabled_ = enabled; - if (!enabled_) { - stop(); - clear(); - } - emit enabledChanged(); -} - -QTouchEvent::TouchPoint QDeclarativePinchGenerator::mouseEventToTouchPoint(QMouseEvent *event) -{ - return createTouchPoint(event->type(), event->pos()); -} - -QTouchEvent::TouchPoint QDeclarativePinchGenerator::createTouchPoint(QEvent::Type type, QPoint pos) -{ - QTouchEvent::TouchPoint touchPoint; - switch (type) { - //case QEvent::GraphicsSceneMousePress: - case QEvent::MouseButtonPress: - touchPoint.setState(Qt::TouchPointPressed); - break; - //case QEvent::GraphicsSceneMouseMove: - case QEvent::MouseMove: - touchPoint.setState(Qt::TouchPointMoved); - break; - //case QEvent::GraphicsSceneMouseRelease: - case QEvent::MouseButtonRelease: - touchPoint.setState(Qt::TouchPointReleased); - break; - default: - break; - } - //touchPoint.setId(touchPointId_++); // running number - touchPoint.setId(0); - touchPoint.setPressure(0.75); - touchPoint.setPos(pos); - touchPoint.setLastPos(pos); - touchPoint.setScenePos(target_->mapToScene(pos)); - touchPoint.setLastScenePos(target_->mapToScene(pos)); - return touchPoint; + activeSwipe_ = new Swipe; + activeSwipe_->touchPoints << event->pos(); + activeSwipe_->durations << 0; + swipeTimer_.start(); + setState(Recording); } void QDeclarativePinchGenerator::mouseMoveEvent(QMouseEvent *event) @@ -158,15 +95,10 @@ void QDeclarativePinchGenerator::mouseMoveEvent(QMouseEvent *event) } Q_ASSERT(activeSwipe_); Q_ASSERT(swipeTimer_.isValid()); - QTouchEvent::TouchPoint touchPoint = mouseEventToTouchPoint(event); - if (touchPoint.state() == Qt::TouchPointMoved) { - activeSwipe_->touchPoints.append(touchPoint); - activeSwipe_->totalDuration += swipeTimer_.elapsed(); - activeSwipe_->touchPointDurations.append(swipeTimer_.elapsed()); - swipeTimer_.restart(); - } else { - Q_ASSERT(false); // no! - } + + activeSwipe_->touchPoints << event->pos(); + activeSwipe_->durations << swipeTimer_.elapsed(); + swipeTimer_.restart(); } void QDeclarativePinchGenerator::mouseReleaseEvent(QMouseEvent *event) @@ -177,59 +109,69 @@ void QDeclarativePinchGenerator::mouseReleaseEvent(QMouseEvent *event) } Q_ASSERT(activeSwipe_); Q_ASSERT(swipeTimer_.isValid()); - QTouchEvent::TouchPoint touchPoint = mouseEventToTouchPoint(event); - if (touchPoint.state() == Qt::TouchPointReleased) { - activeSwipe_->touchPoints.append(touchPoint); - activeSwipe_->totalDuration += swipeTimer_.elapsed(); - activeSwipe_->touchPointDurations.append(swipeTimer_.elapsed()); - } else { - Q_ASSERT(false); // no! - } + activeSwipe_->touchPoints << event->pos(); + activeSwipe_->durations << swipeTimer_.elapsed(); + if (swipes_.count() == SWIPES_REQUIRED) delete swipes_.takeFirst(); - swipes_.append(activeSwipe_); + swipes_ << activeSwipe_; activeSwipe_ = 0; swipeTimer_.invalidate(); if (canvas_ && target_) setState(Idle); else setState(Invalid); - emit swipesChanged(); } -QList<QObject*> QDeclarativePinchGenerator::swipe1() +void QDeclarativePinchGenerator::mouseDoubleClickEvent(QMouseEvent *event) { - if (swipes_.count() < 1) - return QList<QObject*>(); - if (!swipeList1_.isEmpty()) { - qDeleteAll(swipeList1_); - swipeList1_.clear(); - } - for (int i = 0; i < swipes_.at(0)->touchPoints.count(); ++i) { - TouchPoint* touchPoint = new TouchPoint( - swipes_.at(0)->touchPoints.at(i).scenePos().x(), - swipes_.at(0)->touchPoints.at(i).scenePos().y(), - static_cast<int>(swipes_.at(0)->touchPoints.at(i).state())); - swipeList1_.append(touchPoint); + Q_UNUSED(event); + if (!enabled_) { + event->ignore(); + return; } - return swipeList1_; + stop(); + clear(); + if (canvas_ && target_) setState(Idle); else setState(Invalid); } -QList<QObject*> QDeclarativePinchGenerator::swipe2() +void QDeclarativePinchGenerator::keyPressEvent(QKeyEvent *e) { - if (swipes_.count() < 2) - return QList<QObject*>(); - if (!swipeList2_.isEmpty()) { - qDeleteAll(swipeList2_); - swipeList2_.clear(); + if (!enabled_) { + e->ignore(); } - for (int i = 0; i < swipes_.at(1)->touchPoints.count(); ++i) { - TouchPoint* touchPoint = new TouchPoint( - static_cast<double>(swipes_.at(1)->touchPoints.at(i).scenePos().x()), - static_cast<double>(swipes_.at(1)->touchPoints.at(i).scenePos().y()), - static_cast<int>(swipes_.at(1)->touchPoints.at(i).state())); - swipeList2_.append(touchPoint); + + if (e->key() == Qt::Key_C) { + clear(); + } else if (e->key() == Qt::Key_R) { + replay(); + } else if (e->key() == Qt::Key_S) { + stop(); + } else if (e->key() == Qt::Key_Plus) { + setReplaySpeedFactor(replaySpeedFactor() + 0.1); + } else if (e->key() == Qt::Key_Minus) { + setReplaySpeedFactor(replaySpeedFactor() - 0.1); + } else { + qDebug() << metaObject()->className() << "Unsupported key event."; + } +} + +bool QDeclarativePinchGenerator::enabled() const +{ + return enabled_; +} + + +void QDeclarativePinchGenerator::setEnabled(bool enabled) +{ + if (enabled == enabled_) + return; + enabled_ = enabled; + if (!enabled_) { + stop(); + clear(); } - return swipeList2_; + emit enabledChanged(); } + qreal QDeclarativePinchGenerator::replaySpeedFactor() const { return replaySpeedFactor_; @@ -243,17 +185,6 @@ void QDeclarativePinchGenerator::setReplaySpeedFactor(qreal factor) emit replaySpeedFactorChanged(); } -void QDeclarativePinchGenerator::mouseDoubleClickEvent(QMouseEvent *event) -{ - Q_UNUSED(event); - if (!enabled_) { - event->ignore(); - return; - } - stop(); - clear(); - if (canvas_ && target_) setState(Idle); else setState(Invalid); -} QString QDeclarativePinchGenerator::state() const { @@ -275,31 +206,6 @@ QString QDeclarativePinchGenerator::state() const return "How emberassing"; } -int QDeclarativePinchGenerator::count() const -{ - return swipes_.count(); -} - -void QDeclarativePinchGenerator::keyPressEvent(QKeyEvent *e) -{ - if (!enabled_) { - e->ignore(); - } - - if (e->key() == Qt::Key_C) { - clear(); - } else if (e->key() == Qt::Key_R) { - replay(); - } else if (e->key() == Qt::Key_S) { - stop(); - } else if (e->key() == Qt::Key_Plus) { - setReplaySpeedFactor(replaySpeedFactor() + 0.1); - } else if (e->key() == Qt::Key_Minus) { - setReplaySpeedFactor(replaySpeedFactor() - 0.1); - } else { - qDebug() << metaObject()->className() << "Unsupported key event."; - } -} void QDeclarativePinchGenerator::setState(GeneratorState state) { if (state == state_) @@ -322,46 +228,41 @@ void QDeclarativePinchGenerator::timerEvent(QTimerEvent *event) Q_ASSERT(replayTimer_ == event->timerId()); Q_ASSERT(state_ == Replaying); - // Create touchevent. May have one or two touchpoints. - QTouchEvent* touchEvent = 0; - switch (swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_).state()) { - case (Qt::TouchPointPressed): - touchEvent = new QTouchEvent(QEvent::TouchBegin,NULL,Qt::NoModifier,Qt::TouchPointReleased); - break; - case (Qt::TouchPointMoved): - touchEvent = new QTouchEvent(QEvent::TouchUpdate,NULL,Qt::NoModifier,Qt::TouchPointReleased); - break; - case (Qt::TouchPointReleased): - touchEvent = new QTouchEvent(QEvent::TouchEnd,NULL,Qt::NoModifier,Qt::TouchPointReleased); - break; - default: - Q_ASSERT(false); - return; + int slaveSwipe = masterSwipe_ ^ 1; + + int masterCount = swipes_.at(masterSwipe_)->touchPoints.count(); + int slaveCount = swipes_.at(slaveSwipe)->touchPoints.count(); + + if (replayBookmark_ == 0) { + QTest::touchEvent(canvas_, device_) + .press(0, swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)) + .press(1, swipes_.at(slaveSwipe)->touchPoints.at(replayBookmark_)); + } else if (replayBookmark_ == (slaveCount - 1)) { + if (masterCount != slaveCount) { + QTest::touchEvent(canvas_, device_) + .move(0, swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)) + .release(1, swipes_.at(slaveSwipe)->touchPoints.at(replayBookmark_)); + } else { + QTest::touchEvent(canvas_, device_) + .release(0, swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)) + .release(1, swipes_.at(slaveSwipe)->touchPoints.at(replayBookmark_)); + } + } else if (replayBookmark_ == (masterCount - 1)) { + QTest::touchEvent(canvas_, device_) + .release(0, swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)); + } + else { + QTest::touchEvent(canvas_, device_) + .move(0, swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)) + .move(1, swipes_.at(slaveSwipe)->touchPoints.at(replayBookmark_)); } - // Set touch points. Master swipe has touchpoints as it was chosen to have more touchpoints. - // For the other swipe we need to check. - QList<QTouchEvent::TouchPoint> touchPoints; - // The first touch point generates also mouse events. Does not work at the moment because - // we dispatch the touch event via canvas rather than the qApp. However qApp dispatching - // seems to miss some events arbitrarily. - touchPoints.append(swipes_.at(masterSwipe_)->touchPoints.at(replayBookmark_)); - - int slaveSwipe(1); - if (masterSwipe_ == 1) - slaveSwipe = 0; - if (replayBookmark_ < swipes_.at(slaveSwipe)->touchPoints.count()) - touchPoints.append(swipes_.at(slaveSwipe)->touchPoints.at(replayBookmark_)); - touchEvent->setTouchPoints(touchPoints); - canvas_->sendEvent(target_, touchEvent); - delete touchEvent; replayBookmark_++; - if (replayBookmark_ >= swipes_.at(masterSwipe_)->touchPoints.count()) { - //qDebug() << "Pinch replay finished!"; + if (replayBookmark_ >= swipes_.at(masterSwipe_)->touchPoints.count()) stop(); - } else { + else { killTimer(replayTimer_); - replayTimer_ = startTimer((swipes_.at(masterSwipe_)->touchPointDurations.at(replayBookmark_) + 5) / replaySpeedFactor_ ); + replayTimer_ = startTimer((swipes_.at(masterSwipe_)->durations.at(replayBookmark_) + 5) / replaySpeedFactor_ ); } } @@ -384,43 +285,6 @@ void QDeclarativePinchGenerator::setTarget(QQuickItem* target) emit targetChanged(); } -Q_INVOKABLE void QDeclarativePinchGenerator::replay() -{ - if (state_ != Idle) { - qDebug() << "Wrong state, will not replay pinch, state: " << state_; - return; - } - if (swipes_.count() < SWIPES_REQUIRED) { - qDebug() << "Too few swipes, cannot replay, amount: " << swipes_.count(); - return; - } - if ((swipes_.at(0)->touchPoints.count() < 2) || (swipes_.at(1)->touchPoints.count() < 2)) { - qDebug() << "Too few touchpoints, won't replay, amount: " << swipes_.at(0)->touchPoints.count() << (swipes_.at(1)->touchPoints.count() < 2); - return; - } - if (swipes_.at(0)->touchPoints.back().state() != Qt::TouchPointReleased) { - qDebug() << "Swipe misses release event, won't replay."; - return; - } - if (swipes_.at(1)->touchPoints.back().state() != Qt::TouchPointReleased) { - qDebug() << "Swipe misses release event, won't replay."; - return; - } - - Q_ASSERT(swipes_.at(0)->touchPoints.count() == swipes_.at(0)->touchPointDurations.count()); - Q_ASSERT(swipes_.at(1)->touchPoints.count() == swipes_.at(1)->touchPointDurations.count()); - - // 'nuff checkin' already, start replay. let the one with more swipes dictate - if (swipes_.at(0)->touchPoints.count() >= swipes_.at(1)->touchPoints.count()) - masterSwipe_ = 0; - else - masterSwipe_ = 1; - - replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPointDurations.at(0) / replaySpeedFactor_); - replayBookmark_ = 0; - setState(Replaying); -} - void QDeclarativePinchGenerator::pinch(QPoint point1From, QPoint point1To, QPoint point2From, @@ -430,68 +294,70 @@ void QDeclarativePinchGenerator::pinch(QPoint point1From, int samples1, int samples2) { - //qDebug() << __FUNCTION__ << point1From << point1To << point2From << point2To << interval1 << interval2 << samples1 << samples2 << state_; - Q_ASSERT(state_ == Idle); - //Q_ASSERT(!point1From.isNull()); - //Q_ASSERT(!point1To.isNull()); - //Q_ASSERT(!point2From.isNull()); - //Q_ASSERT(!point2To.isNull()); Q_ASSERT(interval1 > 10); Q_ASSERT(interval2 > 10); Q_ASSERT(samples1 >= 2); // we need press and release events at minimum Q_ASSERT(samples2 >= 2); - // generate swipes based on the parameters - if (!swipes_.isEmpty()) { - qDeleteAll(swipes_); - swipes_.clear(); + clear(); + + Swipe* swipe1 = new Swipe; + Swipe* swipe2 = new Swipe; + for (int i = 0; i < samples1; ++i) { + swipe1->touchPoints << point1From + (point1To - point1From) / samples1 * i; + swipe1->durations << interval1; + } + for (int i = 0; i < samples2; ++i) { + swipe2->touchPoints << point2From + (point2To - point2From) / samples2 * i; + swipe2->durations << interval2; } - generateSwipe(point1From, point1To, interval1, samples1); - generateSwipe(point2From, point2To, interval2, samples2); + swipes_ << swipe1 << swipe2; Q_ASSERT(swipes_.at(0)); Q_ASSERT(swipes_.at(1)); - if (swipes_.at(0)->touchPoints.count() >= swipes_.at(1)->touchPoints.count()) - masterSwipe_ = 0; - else - masterSwipe_ = 1; - replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPointDurations.at(0) / replaySpeedFactor_); + masterSwipe_ = (samples1 >= samples2) ? 0 : 1; + + replayTimer_ = startTimer(swipes_.at(masterSwipe_)->durations.at(0) / replaySpeedFactor_); replayBookmark_ = 0; setState(Replaying); } -void QDeclarativePinchGenerator::generateSwipe(QPoint from, QPoint to, int interval, int samples) +void QDeclarativePinchGenerator::pinchPress(QPoint point1From, QPoint point2From) +{ + QTest::touchEvent(canvas_, device_).press(0, point1From).press(1, point2From); +} + +void QDeclarativePinchGenerator::pinchMoveTo(QPoint point1To, QPoint point2To) { - //qDebug() << __FUNCTION__ << "generate swipe from, to, interval, samplecount: " << from << to << interval << samples; - int deltaX = (to.x() - from.x()) / samples; - int deltaY = (to.y() - from.y()) / samples; - //qDebug() << __FUNCTION__ << "deltaX, deltaY: " << deltaX << deltaY; - Q_ASSERT(qAbs(deltaX) > 0 || qAbs(deltaY) > 0); + QTest::touchEvent(canvas_, device_).move(0, point1To).move(1, point2To); +} - activeSwipe_ = new Swipe; - // create press event - activeSwipe_->touchPointDurations.append(interval); - activeSwipe_->totalDuration += interval; - activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonPress, from)); - //qDebug() << __FUNCTION__ << "press X, Y: " << from.x() << from.y(); - - // create move events - for (int i = 1; i < samples - 1; ++i) { - activeSwipe_->touchPointDurations.append(interval); - activeSwipe_->totalDuration += interval; - int nextX = from.x() + (i * deltaX); - int nextY = from.y() + (i * deltaY); - //qDebug() << __FUNCTION__ << "move X, Y: " << nextX << nextY; - activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseMove, QPoint(nextX, nextY))); +void QDeclarativePinchGenerator::pinchRelease(QPoint point1To, QPoint point2To) +{ + QTest::touchEvent(canvas_, device_).release(0, point1To).release(1, point2To); +} + +Q_INVOKABLE void QDeclarativePinchGenerator::replay() +{ + if (state_ != Idle) { + qDebug() << "Wrong state, will not replay pinch, state: " << state_; + return; } - // create release event - activeSwipe_->touchPointDurations.append(interval); - activeSwipe_->totalDuration += interval; - activeSwipe_->touchPoints.append(createTouchPoint(QEvent::MouseButtonRelease, to)); - //qDebug() << __FUNCTION__ << "release X, Y: " << to.x() << to.y(); - - // append the swipe - swipes_.append(activeSwipe_); + if (swipes_.count() < SWIPES_REQUIRED) { + qDebug() << "Too few swipes, cannot replay, amount: " << swipes_.count(); + return; + } + if ((swipes_.at(0)->touchPoints.count() < 2) || (swipes_.at(1)->touchPoints.count() < 2)) { + qDebug() << "Too few touchpoints, won't replay, amount: " << + swipes_.at(0)->touchPoints.count() << (swipes_.at(1)->touchPoints.count() < 2); + return; + } + + masterSwipe_ = (swipes_.at(0)->touchPoints.count() >= swipes_.at(1)->touchPoints.count()) ? 0 : 1; + + replayTimer_ = startTimer(swipes_.at(masterSwipe_)->touchPoints.count() / replaySpeedFactor_); + replayBookmark_ = 0; + setState(Replaying); } Q_INVOKABLE void QDeclarativePinchGenerator::clear() @@ -502,8 +368,6 @@ Q_INVOKABLE void QDeclarativePinchGenerator::clear() if (!swipes_.isEmpty()) { qDeleteAll(swipes_); swipes_.clear(); - emit countChanged(); - emit swipesChanged(); } } diff --git a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h index 8fde7214..be73edb9 100644 --- a/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h +++ b/tests/plugins/declarativetestplugin/qdeclarativepinchgenerator_p.h @@ -52,45 +52,21 @@ #include <QtCore/QPoint> #include <QDebug> -// how many concurrent "swipes" should we have -// bit overkill here first I thought support random about of swipes (1..x) -// but thats for later #define SWIPES_REQUIRED 2 typedef struct { - int totalDuration; // not sure if needed - QList<QTouchEvent::TouchPoint> touchPoints; - QList<int> touchPointDurations; + QList<QPoint> touchPoints; + QList<int> durations; } Swipe; -// total overkill fixme -class TouchPoint: public QObject -{ - Q_OBJECT - Q_PROPERTY(double targetX READ targetX CONSTANT) - Q_PROPERTY(double targetY READ targetY CONSTANT) - Q_PROPERTY(int touchState READ touchState CONSTANT) -public: - TouchPoint(double x, double y, int state): targetX_(x), targetY_(y),touchState_(state) {} - double targetX() {return targetX_;} - double targetY() {return targetY_;} - double touchState() {return touchState_;} - double targetX_; - double targetY_; - int touchState_; -}; - class QDeclarativePinchGenerator : public QQuickItem { Q_OBJECT Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(QString state READ state NOTIFY stateChanged) - Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(qreal replaySpeedFactor READ replaySpeedFactor WRITE setReplaySpeedFactor NOTIFY replaySpeedFactorChanged) Q_PROPERTY(QQuickItem* target READ target WRITE setTarget NOTIFY targetChanged) - Q_PROPERTY(QList<QObject*> swipe1 READ swipe1 NOTIFY swipesChanged) - Q_PROPERTY(QList<QObject*> swipe2 READ swipe2 NOTIFY swipesChanged) Q_INTERFACES(QQmlParserStatus) public: @@ -98,7 +74,6 @@ public: ~QDeclarativePinchGenerator(); QString state() const; - int count() const; QQuickItem* target() const; void setTarget(QQuickItem* target); qreal replaySpeedFactor() const; @@ -106,9 +81,6 @@ public: bool enabled() const; void setEnabled(bool enabled); - QList<QObject*> swipe1(); - QList<QObject*> swipe2(); - Q_INVOKABLE void replay(); Q_INVOKABLE void clear(); Q_INVOKABLE void stop(); @@ -122,11 +94,14 @@ public: int interval2 = 20, int samples1 = 10, int samples2 = 10); + + Q_INVOKABLE void pinchPress(QPoint point1From, QPoint point2From); + Q_INVOKABLE void pinchMoveTo(QPoint point1To, QPoint point2To); + Q_INVOKABLE void pinchRelease(QPoint point1To, QPoint point2To); + signals: void stateChanged(); - void countChanged(); void targetChanged(); - void swipesChanged(); void replaySpeedFactorChanged(); void enabledChanged(); @@ -153,9 +128,6 @@ protected: private: void setState(GeneratorState state); - QTouchEvent::TouchPoint mouseEventToTouchPoint(QMouseEvent* event); - QTouchEvent::TouchPoint createTouchPoint(QEvent::Type type, QPoint pos); - void generateSwipe(QPoint from, QPoint to, int duration, int samples); private: QQuickItem* target_; @@ -167,11 +139,9 @@ private: int replayTimer_; int replayBookmark_; int masterSwipe_; - int touchPointId_; qreal replaySpeedFactor_; - QList<QObject*> swipeList1_; - QList<QObject*> swipeList2_; bool enabled_; + QTouchDevice* device_; }; #endif |