From 3a7804813d9dd4162e088bc19746abd20aaa7827 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 30 Oct 2009 13:23:27 +0100 Subject: Removed the margin in assistant on Mac. Change 9551b8c349ce4e15a57c24a2408ee1b73c2b7510 enabled documentMode on the tabbar in Assistant. To make it look more native we also remove the margin around the tabwidget. Reviewed-by: Prasanth --- tools/assistant/tools/assistant/centralwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 2722b2f4f0..62b4736a08 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -222,8 +222,8 @@ CentralWidget::CentralWidget(QHelpEngine *engine, MainWindow *parent) QVBoxLayout *vboxLayout = new QVBoxLayout(this); QString resourcePath = QLatin1String(":/trolltech/assistant/images/"); -#ifndef Q_OS_MAC vboxLayout->setMargin(0); +#ifndef Q_OS_MAC resourcePath.append(QLatin1String("win")); #else resourcePath.append(QLatin1String("mac")); -- cgit v1.2.3 From acb10eefab985a32a619e2a1d590c93659732c00 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Fri, 30 Oct 2009 12:42:23 +0100 Subject: Fix unit test and add autoCancel test for graphicsview --- tests/auto/gestures/tst_gestures.cpp | 98 ++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 26 deletions(-) diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 02c823264f..79de8239d3 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -116,7 +116,7 @@ public: return new CustomGesture; } - QGestureRecognizer::Result filterEvent(QGesture *state, QObject*, QEvent *event) + QGestureRecognizer::Result filterEvent(QGesture *state, QObject*o , QEvent *event) { if (event->type() == CustomEvent::EventType) { QGestureRecognizer::Result result = 0; @@ -332,6 +332,7 @@ private slots: void consumeEventHint(); void unregisterRecognizer(); void autoCancelGestures(); + void autoCancelGestures2(); }; tst_Gestures::tst_Gestures() @@ -1295,20 +1296,6 @@ void tst_Gestures::unregisterRecognizer() // a method on QApplication void tst_Gestures::autoCancelGestures() { - class MockRecognizer : public QGestureRecognizer { - public: - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event) - { - Q_UNUSED(gesture); - Q_UNUSED(watched); - if (event->type() == QEvent::MouseButtonPress) - return QGestureRecognizer::GestureTriggered; - if (event->type() == QEvent::MouseButtonRelease) - return QGestureRecognizer::GestureFinished; - return QGestureRecognizer::Ignore; - } - }; - class MockWidget : public GestureWidget { public: MockWidget(const char *name) : GestureWidget(name) { } @@ -1324,14 +1311,18 @@ void tst_Gestures::autoCancelGestures() } }; + const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext parent.resize(300, 100); + parent.setWindowFlags(Qt::X11BypassWindowManagerHint); GestureWidget *child = new GestureWidget("child", &parent); child->setGeometry(10, 10, 100, 80); - Qt::GestureType type = QApplication::registerGestureRecognizer(new MockRecognizer()); - parent.grabGesture(type, Qt::WidgetWithChildrenGesture); - child->grabGesture(type, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + parent.show(); + QTest::qWaitForWindowShown(&parent); /* An event is send to both the child and the parent, when the child gets it a gesture is triggered @@ -1340,18 +1331,73 @@ void tst_Gestures::autoCancelGestures() parent gets it he accepts it and that causes the cancel policy to activate. The cause of that is the gesture for the child is cancelled and send to the child as such. */ - QMouseEvent event(QEvent::MouseButtonPress, QPoint(20,20), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + CustomEvent event; + event.serial = CustomGesture::SerialStartedThreshold; QApplication::sendEvent(child, &event); + QCOMPARE(child->events.all.count(), 2); QCOMPARE(child->events.started.count(), 1); - QCOMPARE(child->events.all.count(), 1); - QCOMPARE(parent.events.all.count(), 0); - child->reset(); - QApplication::sendEvent(&parent, &event); + QCOMPARE(child->events.canceled.count(), 1); QCOMPARE(parent.events.all.count(), 1); - QCOMPARE(parent.events.started.count(), 1); - QCOMPARE(child->events.started.count(), 0); - QCOMPARE(child->events.all.count(), 1); + + // clean up, make the parent gesture finish + event.serial = CustomGesture::SerialFinishedThreshold; + QApplication::sendEvent(child, &event); + QCOMPARE(parent.events.all.count(), 2); +} + +void tst_Gestures::autoCancelGestures2() +{ + class MockItem : public GestureItem { + public: + MockItem(const char *name) : GestureItem(name) { } + + bool event(QEvent *event) { + if (event->type() == QEvent::Gesture) { + QGestureEvent *ge = static_cast(event); + Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here... + ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); + } + return GestureItem::event(event); + } + }; + + const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + + QGraphicsScene scene; + QGraphicsView view(&scene); + view.setWindowFlags(Qt::X11BypassWindowManagerHint); + + MockItem *parent = new MockItem("parent"); + GestureItem *child = new GestureItem("child"); + child->setParentItem(parent); + parent->setPos(0, 0); + child->setPos(10, 10); + scene.addItem(parent); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(secondGesture, Qt::WidgetGesture); + parent->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + + view.show(); + QTest::qWaitForWindowShown(&view); + view.ensureVisible(scene.sceneRect()); + + CustomEvent event; + event.serial = CustomGesture::SerialStartedThreshold; + event.hasHotSpot = true; + event.hotSpot = mapToGlobal(QPointF(5, 5), child, &view); + // qDebug() << event.hotSpot; + scene.sendEvent(child, &event); + //QEventLoop().exec(); + QCOMPARE(parent->events.all.count(), 1); + QCOMPARE(child->events.started.count(), 1); QCOMPARE(child->events.canceled.count(), 1); + QCOMPARE(child->events.all.count(), 2); + + // clean up, make the parent gesture finish + event.serial = CustomGesture::SerialFinishedThreshold; + scene.sendEvent(child, &event); + QCOMPARE(parent->events.all.count(), 2); } QTEST_MAIN(tst_Gestures) -- cgit v1.2.3 From da83365fbf7ff393f7dc99d28eda61b902081bb2 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Fri, 30 Oct 2009 12:42:49 +0100 Subject: Make GestureCancelPolicy work for graphicsview Reviewed-By: Denis --- src/gui/graphicsview/qgraphicsscene.cpp | 90 +++++++++++++++++++++++++++++++++ src/gui/graphicsview/qgraphicsscene_p.h | 1 + src/gui/kernel/qgesture.h | 1 + src/gui/kernel/qgesturemanager.cpp | 37 ++++++-------- src/gui/kernel/qgesturemanager_p.h | 2 + 5 files changed, 109 insertions(+), 22 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index c459d21f0f..9279fe36cc 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5941,6 +5941,13 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) continue; } } + foreach (QGesture *g, startedGestures) { + if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) { + DEBUG() << "lets try to cancel some"; + // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them + cancelGesturesForChildren(g, event->widget()); + } + } // forget about targets for gestures that have ended foreach (QGesture *g, allGestures) { @@ -5955,6 +5962,89 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) } } +void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidget *viewport) +{ + Q_ASSERT(original); + QGraphicsItem *originalItem = gestureTargets.value(original); + Q_ASSERT(originalItem); + + // iterate over all active gestures and for each find the owner + // if the owner is part of our sub-hierarchy, cancel it. + + QSet canceledGestures; + QHash::Iterator iter = gestureTargets.begin(); + while (iter != gestureTargets.end()) { + QGraphicsObject *item = iter.value(); + // note that we don't touch the gestures for our originalItem + if (item != originalItem && originalItem->isAncestorOf(item)) { + DEBUG() << " found a gesture to cancel" << iter.key(); + iter.key()->d_func()->state = Qt::GestureCanceled; + canceledGestures << iter.key(); + } + ++iter; + } + + // sort them per target item by cherry picking from almostCanceledGestures and delivering + QSet almostCanceledGestures = canceledGestures; + QSet::Iterator setIter; + while (!almostCanceledGestures.isEmpty()) { + QGraphicsObject *target = 0; + QSet gestures; + setIter = almostCanceledGestures.begin(); + // sort per target item + while (setIter != almostCanceledGestures.end()) { + QGraphicsObject *item = gestureTargets.value(*setIter); + if (target == 0) + target = item; + if (target == item) { + gestures << *setIter; + setIter = almostCanceledGestures.erase(setIter); + } else { + ++setIter; + } + } + Q_ASSERT(target); + + QList list = gestures.toList(); + QGestureEvent ev(list); + sendEvent(target, &ev); + + foreach (QGesture *g, list) { + if (ev.isAccepted() || ev.isAccepted(g)) + gestures.remove(g); + } + + foreach (QGesture *g, gestures) { + if (!g->hasHotSpot()) + continue; + + QPoint screenPos = g->hotSpot().toPoint(); + QList items = itemsAtPosition(screenPos, QPointF(), viewport); + for (int j = 0; j < items.size(); ++j) { + QGraphicsObject *item = items.at(j)->toGraphicsObject(); + if (!item) + continue; + QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); + if (d->gestureContext.contains(g->gestureType())) { + QList list; + list << g; + QGestureEvent ev(list); + sendEvent(item, &ev); + if (ev.isAccepted() || ev.isAccepted(g)) + break; // successfully delivered + } + } + } + } + + QGestureManager *gm = QApplicationPrivate::instance()->gestureManager; + Q_ASSERT(gm); // it would be very odd if we got called without a manager. + for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) { + gm->recycle(*setIter); + gestureTargets.remove(*setIter); + } +} + QT_END_NAMESPACE #include "moc_qgraphicsscene.cpp" diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index cd20fd038f..f8db08401e 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -288,6 +288,7 @@ public: QMap *conflictedGestures, QList > *conflictedItems, QHash *normalGestures); + void cancelGesturesForChildren(QGesture *original, QWidget *viewport); void updateInputMethodSensitivityInViews(); diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h index 524d26e1d2..8614ecbfca 100644 --- a/src/gui/kernel/qgesture.h +++ b/src/gui/kernel/qgesture.h @@ -97,6 +97,7 @@ private: friend class QGestureEvent; friend class QGestureRecognizer; friend class QGestureManager; + friend class QGraphicsScenePrivate; }; class QPanGesturePrivate; diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index f1abc895ac..1d33c84873 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -346,12 +346,7 @@ bool QGestureManager::filterEventThroughContexts(const QMultiHash endedGestures = finishedGestures + canceledGestures + undeliveredGestures; foreach (QGesture *gesture, endedGestures) { - if (QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0)) { - gesture->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(gesture); - } else { - cleanupGesturesForRemovedRecognizer(gesture); - } + recycle(gesture); m_gestureTargets.remove(gesture); } return ret; @@ -409,15 +404,8 @@ void QGestureManager::cancelGesturesForChildren(QGesture *original) deliverEvents(gestures, &undeliveredGestures); } - for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter) { - QGestureRecognizer *recognizer = m_gestureToRecognizer.value(*iter, 0); - if (recognizer) { - (*iter)->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(*iter); - } else { - cleanupGesturesForRemovedRecognizer(*iter); - } - } + for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter) + recycle(*iter); } void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) @@ -667,19 +655,24 @@ void QGestureManager::timerEvent(QTimerEvent *event) it = m_maybeGestures.erase(it); DEBUG() << "QGestureManager::timerEvent: gesture stopped due to timeout:" << gesture; - QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); - if (recognizer) { - gesture->setGestureCancelPolicy(QGesture::CancelNone); - recognizer->reset(gesture); - } else { - cleanupGesturesForRemovedRecognizer(gesture); - } + recycle(gesture); } else { ++it; } } } +void QGestureManager::recycle(QGesture *gesture) +{ + QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); + if (recognizer) { + gesture->setGestureCancelPolicy(QGesture::CancelNone); + recognizer->reset(gesture); + } else { + cleanupGesturesForRemovedRecognizer(gesture); + } +} + QT_END_NAMESPACE #include "moc_qgesturemanager_p.cpp" diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index 4958cdb9d0..d60aedc7e0 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -81,6 +81,8 @@ public: void cleanupCachedGestures(QObject *target, Qt::GestureType type); + void recycle(QGesture *gesture); + protected: void timerEvent(QTimerEvent *event); bool filterEventThroughContexts(const QMultiHash &contexts, -- cgit v1.2.3 From 157e218d90ba832b2846889e9f7c94c95ed2cfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 30 Oct 2009 14:18:43 +0100 Subject: Fix issue with wrong QMessagebox icons on Mac. Task: QTBUG-4988 68c0e6a8ba1e92bf0152adcaa86eebb83dcfd1d8 introduced a regression preventing the mac-spesific standardIcon code form being called. Call the Mac code if desktopSettingsAware is set. (QIcon::themeName() is only set on X11) --- src/gui/styles/qcommonstyle.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 70d130a66e..1564a3fcf7 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -5657,10 +5657,11 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons default: break; } - + } // if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) if (!icon.isNull()) return icon; #if defined(Q_WS_MAC) + if (QApplication::desktopSettingsAware()) { OSType iconType = 0; switch (standardIcon) { case QStyle::SP_MessageBoxQuestion: @@ -5751,8 +5752,8 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons ReleaseIconRef(overlayIcon); return retIcon; } + } // if (QApplication::desktopSettingsAware()) #endif // Q_WS_MAC - } switch (standardIcon) { #ifndef QT_NO_IMAGEFORMAT_PNG -- cgit v1.2.3 From 5cca60ad593cc5b8778d7be0b8137ffecd34b247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 30 Oct 2009 14:22:06 +0100 Subject: Fix indentation. --- src/gui/styles/qcommonstyle.cpp | 178 ++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp index 1564a3fcf7..84e046f207 100644 --- a/src/gui/styles/qcommonstyle.cpp +++ b/src/gui/styles/qcommonstyle.cpp @@ -5662,96 +5662,96 @@ QIcon QCommonStyle::standardIconImplementation(StandardPixmap standardIcon, cons return icon; #if defined(Q_WS_MAC) if (QApplication::desktopSettingsAware()) { - OSType iconType = 0; - switch (standardIcon) { - case QStyle::SP_MessageBoxQuestion: - case QStyle::SP_MessageBoxInformation: - case QStyle::SP_MessageBoxWarning: - case QStyle::SP_MessageBoxCritical: - iconType = kGenericApplicationIcon; - break; - case SP_DesktopIcon: - iconType = kDesktopIcon; - break; - case SP_TrashIcon: - iconType = kTrashIcon; - break; - case SP_ComputerIcon: - iconType = kComputerIcon; - break; - case SP_DriveFDIcon: - iconType = kGenericFloppyIcon; - break; - case SP_DriveHDIcon: - iconType = kGenericHardDiskIcon; - break; - case SP_DriveCDIcon: - case SP_DriveDVDIcon: - iconType = kGenericCDROMIcon; - break; - case SP_DriveNetIcon: - iconType = kGenericNetworkIcon; - break; - case SP_DirOpenIcon: - iconType = kOpenFolderIcon; - break; - case SP_DirClosedIcon: - case SP_DirLinkIcon: - iconType = kGenericFolderIcon; - break; - case SP_FileLinkIcon: - case SP_FileIcon: - iconType = kGenericDocumentIcon; - break; - case SP_DirIcon: { - // A rather special case - QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, option, widget); - QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, option, widget); - closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); - closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); - return closeIcon; - } - case SP_TitleBarNormalButton: - case SP_TitleBarCloseButton: { - QIcon titleBarIcon; - if (standardIcon == SP_TitleBarCloseButton) { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); - } else { - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); - titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + OSType iconType = 0; + switch (standardIcon) { + case QStyle::SP_MessageBoxQuestion: + case QStyle::SP_MessageBoxInformation: + case QStyle::SP_MessageBoxWarning: + case QStyle::SP_MessageBoxCritical: + iconType = kGenericApplicationIcon; + break; + case SP_DesktopIcon: + iconType = kDesktopIcon; + break; + case SP_TrashIcon: + iconType = kTrashIcon; + break; + case SP_ComputerIcon: + iconType = kComputerIcon; + break; + case SP_DriveFDIcon: + iconType = kGenericFloppyIcon; + break; + case SP_DriveHDIcon: + iconType = kGenericHardDiskIcon; + break; + case SP_DriveCDIcon: + case SP_DriveDVDIcon: + iconType = kGenericCDROMIcon; + break; + case SP_DriveNetIcon: + iconType = kGenericNetworkIcon; + break; + case SP_DirOpenIcon: + iconType = kOpenFolderIcon; + break; + case SP_DirClosedIcon: + case SP_DirLinkIcon: + iconType = kGenericFolderIcon; + break; + case SP_FileLinkIcon: + case SP_FileIcon: + iconType = kGenericDocumentIcon; + break; + case SP_DirIcon: { + // A rather special case + QIcon closeIcon = QStyle::standardIcon(SP_DirClosedIcon, option, widget); + QIcon openIcon = QStyle::standardIcon(SP_DirOpenIcon, option, widget); + closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On); + closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On); + return closeIcon; + } + case SP_TitleBarNormalButton: + case SP_TitleBarCloseButton: { + QIcon titleBarIcon; + if (standardIcon == SP_TitleBarCloseButton) { + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-16.png")); + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + } else { + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-16.png")); + titleBarIcon.addFile(QLatin1String(":/trolltech/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On); + } + return titleBarIcon; + } + default: + break; + } + if (iconType != 0) { + QIcon retIcon; + IconRef icon; + IconRef overlayIcon = 0; + if (iconType != kGenericApplicationIcon) { + GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); + } else { + FSRef fsRef; + ProcessSerialNumber psn = { 0, kCurrentProcess }; + GetProcessBundleLocation(&psn, &fsRef); + GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); + if (standardIcon == SP_MessageBoxCritical) { + overlayIcon = icon; + GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); + } + } + if (icon) { + qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); + ReleaseIconRef(icon); + } + if (overlayIcon) + ReleaseIconRef(overlayIcon); + return retIcon; } - return titleBarIcon; - } - default: - break; - } - if (iconType != 0) { - QIcon retIcon; - IconRef icon; - IconRef overlayIcon = 0; - if (iconType != kGenericApplicationIcon) { - GetIconRef(kOnSystemDisk, kSystemIconsCreator, iconType, &icon); - } else { - FSRef fsRef; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - GetProcessBundleLocation(&psn, &fsRef); - GetIconRefFromFileInfo(&fsRef, 0, 0, 0, 0, kIconServicesNormalUsageFlag, &icon, 0); - if (standardIcon == SP_MessageBoxCritical) { - overlayIcon = icon; - GetIconRef(kOnSystemDisk, kSystemIconsCreator, kAlertCautionIcon, &icon); - } - } - if (icon) { - qt_mac_constructQIconFromIconRef(icon, overlayIcon, &retIcon, standardIcon); - ReleaseIconRef(icon); - } - if (overlayIcon) - ReleaseIconRef(overlayIcon); - return retIcon; - } } // if (QApplication::desktopSettingsAware()) #endif // Q_WS_MAC -- cgit v1.2.3 From 4510c18ed3ffd2c01d11159fc2d2ec7f0eb48e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 30 Oct 2009 14:49:05 +0100 Subject: Fix QDesktopServices::DataLocation on Mac. DataLocation now behaves as on the other platforms, QCoreApplication::organizationName() and applicationName() is included in the returned path. --- dist/changes-4.6.0 | 4 ++++ src/gui/util/qdesktopservices.cpp | 9 --------- src/gui/util/qdesktopservices_mac.cpp | 9 ++++++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0 index 7f723dae67..abe44274d3 100644 --- a/dist/changes-4.6.0 +++ b/dist/changes-4.6.0 @@ -143,3 +143,7 @@ information about a particular change. function setFloatingPointPrecision(). Set Qt_4_5 as the version of the QDataStream to get the behavior of previous versions. + - On Mac OS X, QDesktopServices::storageLocation(DataLocation) now includes + QCoreApplication::organizationName() and QCoreApplication::applicationName() + if those are set. This matches the behavior on the other platforms. + \ No newline at end of file diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 1690d87ed3..85b539f20d 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -294,15 +294,6 @@ void QDesktopServices::unsetUrlHandler(const QString &scheme) Rest of the standard locations point to folder on same drive with executable, except that if executable is in ROM the folder from C drive is returned. - \note On Mac OS X, DataLocation does not include QCoreApplication::organizationName. - Use code like this to add it: - - \code - QString location = QDesktopServices::storageLocation(QDesktopServices::DataLocation); - #ifdef Q_WS_MAC - location.insert(location.count() - QCoreApplication::applicationName().count(), - QCoreApplication::organizationName() + "/"); - #endif \endcode */ diff --git a/src/gui/util/qdesktopservices_mac.cpp b/src/gui/util/qdesktopservices_mac.cpp index 0626e0a8b3..23f9e60d62 100644 --- a/src/gui/util/qdesktopservices_mac.cpp +++ b/src/gui/util/qdesktopservices_mac.cpp @@ -153,9 +153,12 @@ QString QDesktopServices::storageLocation(StandardLocation type) QString path = getFullPath(ref); - QString appName = QCoreApplication::applicationName(); - if (!appName.isEmpty() && (type == DataLocation || type == CacheLocation)) - path += QLatin1Char('/') + appName; + if (type == DataLocation || type == CacheLocation) { + if (QCoreApplication::organizationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::organizationName(); + if (QCoreApplication::applicationName().isEmpty() == false) + path += QLatin1Char('/') + QCoreApplication::applicationName(); + } return path; } -- cgit v1.2.3 From f1132e60e0759d8be043a2c4312915b3103004ff Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Mon, 2 Nov 2009 15:34:15 +0100 Subject: Titlebar icon (for e.g. Assistant) not visible in Cocoa. standardWindowButton:NSWindowDocumentIconButton will not return a valid NSButton unless you call setRepresentedURL or setRepresentedFilename for the NSWindow. This patch makes sure that setWindowIcon_sys() sets the icon using a valid NSButton. Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qcocoawindowdelegate_mac.mm | 23 +++++++++++++++++++++++ src/gui/kernel/qcocoawindowdelegate_mac_p.h | 2 ++ src/gui/kernel/qwidget_mac.mm | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm index 95c89e5b5e..803a1b1c83 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac.mm +++ b/src/gui/kernel/qcocoawindowdelegate_mac.mm @@ -346,5 +346,28 @@ static void cleanupCocoaWindowDelegate() m_drawerHash->remove(drawer); } +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu +{ + Q_UNUSED(menu); + QWidget *qwidget = m_windowHash->value(window); + if (qwidget && !qwidget->windowFilePath().isEmpty()) { + return YES; + } + return NO; +} + +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event + from:(NSPoint)dragImageLocation + withPasteboard:(NSPasteboard *)pasteboard +{ + Q_UNUSED(event); + Q_UNUSED(dragImageLocation); + Q_UNUSED(pasteboard); + QWidget *qwidget = m_windowHash->value(window); + if (qwidget && !qwidget->windowFilePath().isEmpty()) { + return YES; + } + return NO; +} @end #endif// QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qcocoawindowdelegate_mac_p.h b/src/gui/kernel/qcocoawindowdelegate_mac_p.h index a06c516720..3728002fc4 100644 --- a/src/gui/kernel/qcocoawindowdelegate_mac_p.h +++ b/src/gui/kernel/qcocoawindowdelegate_mac_p.h @@ -76,6 +76,8 @@ QT_FORWARD_DECLARE_CLASS(QWidgetData) - (void)windowDidResignMain:(NSNotification*)notification; - (void)windowDidBecomeKey:(NSNotification*)notification; - (void)windowDidResignKey:(NSNotification*)notification; +- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu; +- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard; @end @protocol NSDrawerDelegate diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 58252ca354..79f55a101d 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3017,6 +3017,12 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset) #else QMacCocoaAutoReleasePool pool; NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; + if (iconButton == nil) { + QCFString string(q->windowTitle()); + const NSString *tmpString = reinterpret_cast((CFStringRef)string); + [qt_mac_window_for(q) setRepresentedURL:[NSURL fileURLWithPath:tmpString]]; + iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton]; + } if (icon.isNull()) { [iconButton setImage:nil]; } else { -- cgit v1.2.3 From 02b16c259cf268903823304e02d308cbbd043194 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 2 Nov 2009 15:46:53 +0100 Subject: Cocoa: fix double emit bug from file dialog For some reason, Cocoa tells us twize whenever a selection change occurs in the native file dialog. This patch inserts a check that the selection actually changed before emitting any signals Rev-By: Prasanth --- src/gui/dialogs/qfiledialog_mac.mm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui/dialogs/qfiledialog_mac.mm b/src/gui/dialogs/qfiledialog_mac.mm index d9bec27794..4af5688d5b 100644 --- a/src/gui/dialogs/qfiledialog_mac.mm +++ b/src/gui/dialogs/qfiledialog_mac.mm @@ -399,9 +399,13 @@ QT_USE_NAMESPACE - (void)panelSelectionDidChange:(id)sender { Q_UNUSED(sender); - *mCurrentSelection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString([mSavePanel filename])); - if (mPriv) - mPriv->QNSOpenSavePanelDelegate_selectionChanged(*mCurrentSelection); + if (mPriv) { + QString selection = QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString([mSavePanel filename])); + if (selection != mCurrentSelection) { + *mCurrentSelection = selection; + mPriv->QNSOpenSavePanelDelegate_selectionChanged(selection); + } + } } - (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo -- cgit v1.2.3 From 29ddc44a11e16347212fccd3d81c4e0c91bf61a1 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 2 Nov 2009 12:37:41 +0100 Subject: Documentation fixes related to gestures doc. Reviewed-by: David Boddie --- doc/src/frameworks-technologies/gestures.qdoc | 4 ++-- src/gui/kernel/qevent.cpp | 5 +++-- src/gui/kernel/qgesture.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/src/frameworks-technologies/gestures.qdoc b/doc/src/frameworks-technologies/gestures.qdoc index a619fe8f16..f64e301725 100644 --- a/doc/src/frameworks-technologies/gestures.qdoc +++ b/doc/src/frameworks-technologies/gestures.qdoc @@ -168,6 +168,6 @@ \section1 Further Reading - The \l{Image Gestures Example} shows how to enable gestures for a widget in - a simple image viewer application. + The \l{gestures/imagegestures}{Image Gestures Example} shows how to enable + gestures for a widget in a simple image viewer application. */ diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index ab43e795ac..6757fa27a4 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -4344,8 +4344,9 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const Sets the accept flag of the given \a gestureType object to the specified \a value. - Setting the accept flag indicates that the event receiver wants the \a gesture. - Unwanted gestures may be propagated to the parent widget. + Setting the accept flag indicates that the event receiver wants the gesture + of type \a gestureType. Unwanted gestures may be propagated to the parent + widget. By default, gestures in events of type QEvent::Gesture are accepted, and gestures in QEvent::GestureOverride events are ignored. diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index 850f22c6af..df9974601a 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -217,7 +217,7 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const */ /*! - \property QGesture::GestureCancelPolicy + \property QGesture::gestureCancelPolicy \brief the policy for deciding what happens on accepting a gesture On accepting one gesture Qt can automatically cancel other gestures -- cgit v1.2.3 From b112af4614dffcb230956bfa319c37fc00e6a13c Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 2 Nov 2009 14:13:17 +0100 Subject: Added QGraphicsObject::ungrabGesture() Oops, apparently we forgot to add a function for unsubscribing a graphics object from a gesture. Fixing it now. Reviewed-by: trustme --- src/gui/graphicsview/qgraphicsitem.cpp | 17 +++++++++++++++-- src/gui/graphicsview/qgraphicsitem.h | 1 + src/gui/kernel/qwidget.cpp | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 738c6e33f9..58d7e7dfbf 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7322,9 +7322,8 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent /*! Subscribes the graphics object to the given \a gesture for the specified \a context. - \sa QGestureEvent + \sa ungrabGesture(), QGestureEvent */ - void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) { QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); @@ -7332,6 +7331,20 @@ void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext co (void)QGestureManager::instance(); // create a gesture manager } +/*! + Unsubscribes the graphics object from the given \a gesture. + + \sa grabGesture(), QGestureEvent +*/ +void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) +{ + QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); + if (d->gestureContext.remove(gesture)) { + QGestureManager *manager = QGestureManager::instance(); + manager->cleanupCachedGestures(this, gesture); + } +} + /*! \property QGraphicsObject::parent \brief the parent of the item diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index f3fe99c18b..fc180f3f22 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -556,6 +556,7 @@ public: #endif void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture); + void ungrabGesture(Qt::GestureType type); Q_SIGNALS: void parentChanged(); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 14f3bfe4b2..ac2808c535 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11712,7 +11712,7 @@ QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const /*! Subscribes the widget to a given \a gesture with a \a context. - \sa QGestureEvent + \sa ungrabGesture(), QGestureEvent \since 4.6 */ void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) @@ -11725,7 +11725,7 @@ void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) /*! Unsubscribes the widget to a given \a gesture type - \sa QGestureEvent + \sa grabGesture(), QGestureEvent \since 4.6 */ void QWidget::ungrabGesture(Qt::GestureType gesture) -- cgit v1.2.3 From 0222f4f55d6af9ad4f4ca1ee07ae9810ff9256a2 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 30 Oct 2009 13:57:34 +0100 Subject: Improved gesture scrollarea manualtest. Reviewed-by: trustme --- tests/manual/gestures/scrollarea/main.cpp | 30 +++++++++++++++------- .../scrollarea/mousepangesturerecognizer.cpp | 14 ++++++++-- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp index f90f6c66e4..9a5eb02913 100644 --- a/tests/manual/gestures/scrollarea/main.cpp +++ b/tests/manual/gestures/scrollarea/main.cpp @@ -73,11 +73,11 @@ protected: QPanGesture *pan = static_cast(event->gesture(Qt::PanGesture)); if (pan) { switch(pan->state()) { - case Qt::GestureStarted: qDebug("area: Pan: started"); break; - case Qt::GestureFinished: qDebug("area: Pan: finished"); break; - case Qt::GestureCanceled: qDebug("area: Pan: canceled"); break; + case Qt::GestureStarted: qDebug() << this << "Pan: started"; break; + case Qt::GestureFinished: qDebug() << this << "Pan: finished"; break; + case Qt::GestureCanceled: qDebug() << this << "Pan: canceled"; break; case Qt::GestureUpdated: break; - default: qDebug("area: Pan: "); break; + default: qDebug() << this << "Pan: "; break; } if (pan->state() == Qt::GestureStarted) @@ -134,11 +134,11 @@ protected: QPanGesture *pan = static_cast(event->gesture(Qt::PanGesture)); if (pan) { switch (pan->state()) { - case Qt::GestureStarted: qDebug("slider: Pan: started"); break; - case Qt::GestureFinished: qDebug("slider: Pan: finished"); break; - case Qt::GestureCanceled: qDebug("slider: Pan: canceled"); break; + case Qt::GestureStarted: qDebug() << this << "Pan: started"; break; + case Qt::GestureFinished: qDebug() << this << "Pan: finished"; break; + case Qt::GestureCanceled: qDebug() << this << "Pan: canceled"; break; case Qt::GestureUpdated: break; - default: qDebug("slider: Pan: "); break; + default: qDebug() << this << "Pan: "; break; } if (pan->state() == Qt::GestureStarted) @@ -186,6 +186,7 @@ public: MainWindow() { rootScrollArea = new ScrollArea; + rootScrollArea->setObjectName(QLatin1String("rootScrollArea")); setCentralWidget(rootScrollArea); QWidget *root = new QWidget; @@ -193,14 +194,17 @@ public: rootScrollArea->setWidget(root); Slider *verticalSlider = new Slider(Qt::Vertical, root); + verticalSlider->setObjectName(QLatin1String("verticalSlider")); verticalSlider ->move(650, 1100); Slider *horizontalSlider = new Slider(Qt::Horizontal, root); + horizontalSlider->setObjectName(QLatin1String("horizontalSlider")); horizontalSlider ->move(600, 1000); childScrollArea = new ScrollArea(root); + childScrollArea->setObjectName(QLatin1String("childScrollArea")); childScrollArea->move(500, 500); QWidget *w = new QWidget; - w->setMinimumWidth(400); + w->setMinimumWidth(700); QVBoxLayout *l = new QVBoxLayout(w); l->setMargin(20); for (int i = 0; i < 100; ++i) { @@ -211,6 +215,14 @@ public: l->addWidget(w); } childScrollArea->setWidget(w); +#if defined(Q_OS_WIN) + // Windows can force Qt to create a native window handle for an + // intermediate widget and that will block gesture to get touch events. + // So this hack to make sure gestures get all touch events they need. + foreach (QObject *w, children()) + if (w->isWidgetType()) + static_cast(w)->setAttribute(Qt::WA_AcceptTouchEvents); +#endif } private: ScrollArea *rootScrollArea; diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp index 63d3e76bd6..ce5ef570c2 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp @@ -57,8 +57,16 @@ QGesture* MousePanGestureRecognizer::createGesture(QObject *) QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast(state); + if (event->type() == QEvent::TouchBegin) { + // ignore the following mousepress event + g->setProperty("ignoreMousePress", QVariant::fromValue(true)); + } else if (event->type() == QEvent::TouchEnd) { + g->setProperty("ignoreMousePress", QVariant::fromValue(false)); + } QMouseEvent *me = static_cast(event); - if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) { + if (event->type() == QEvent::MouseButtonPress) { + if (g->property("ignoreMousePress").toBool()) + return QGestureRecognizer::Ignore; g->setHotSpot(me->globalPos()); g->setProperty("lastPos", me->globalPos()); g->setProperty("pressed", QVariant::fromValue(true)); @@ -76,7 +84,8 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat } return QGestureRecognizer::NotGesture; } else if (event->type() == QEvent::MouseButtonRelease) { - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; + if (g->property("pressed").toBool()) + return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; } return QGestureRecognizer::Ignore; } @@ -90,5 +99,6 @@ void MousePanGestureRecognizer::reset(QGesture *state) g->setAcceleration(0); g->setProperty("lastPos", QVariant()); g->setProperty("pressed", QVariant::fromValue(false)); + g->setProperty("ignoreMousePress", QVariant::fromValue(false)); QGestureRecognizer::reset(state); } -- cgit v1.2.3 From b7b4df9c87805be372fa6f74422e0f4648a5d520 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 30 Oct 2009 14:01:41 +0100 Subject: Fixed the imagegestures project file. Reviewed-by: trustme --- examples/gestures/imagegestures/imagegestures.pro | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/gestures/imagegestures/imagegestures.pro b/examples/gestures/imagegestures/imagegestures.pro index 7780ad9cec..8c947e41bd 100644 --- a/examples/gestures/imagegestures/imagegestures.pro +++ b/examples/gestures/imagegestures/imagegestures.pro @@ -5,12 +5,12 @@ SOURCES = imagewidget.cpp \ mainwidget.cpp # install -target.path = $$[QT_INSTALL_EXAMPLES]/gestures/imageviewer +target.path = $$[QT_INSTALL_EXAMPLES]/gestures/imagegestures sources.files = $$SOURCES \ $$HEADERS \ $$RESOURCES \ $$FORMS \ - imageviewer.pro -sources.path = $$[QT_INSTALL_EXAMPLES]/gestures/imageviewer + imagegestures.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/gestures/imagegestures INSTALLS += target \ sources -- cgit v1.2.3 From 54db3afc9797a3adf5a38f35f6338960924e9e1a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 30 Oct 2009 17:14:53 +0100 Subject: Implemented pinch gesture recognizer. Reviewed-by: trustme --- examples/gestures/imagegestures/imagewidget.cpp | 18 +-- src/gui/kernel/qgesture_p.h | 3 + src/gui/kernel/qgesturemanager.cpp | 1 + src/gui/kernel/qstandardgestures.cpp | 177 ++++++++++++--------- src/gui/kernel/qstandardgestures_p.h | 11 ++ src/gui/kernel/qwidget.cpp | 1 + src/gui/kernel/qwidget_win.cpp | 11 -- .../kernel/qwinnativepangesturerecognizer_win.cpp | 8 +- .../kernel/qwinnativepangesturerecognizer_win_p.h | 2 +- 9 files changed, 130 insertions(+), 102 deletions(-) diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp index 28de6da270..c798fcc479 100644 --- a/examples/gestures/imagegestures/imagewidget.cpp +++ b/examples/gestures/imagegestures/imagewidget.cpp @@ -102,17 +102,13 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *) //! [gesture event handler] bool ImageWidget::gestureEvent(QGestureEvent *event) { - if (QGesture *pan = event->gesture(Qt::PanGesture)) { - panTriggered(static_cast(pan)); - return true; - } else if (QGesture *pinch = event->gesture(Qt::PinchGesture)) { - pinchTriggered(static_cast(pinch)); - return true; - } else if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) { - swipeTriggered(static_cast(swipe)); - return true; - } - return false; + if (QGesture *pan = event->gesture(Qt::PanGesture)) + panTriggered(static_cast(pan)); + if (QGesture *pinch = event->gesture(Qt::PinchGesture)) + pinchTriggered(static_cast(pinch)); + if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) + swipeTriggered(static_cast(swipe)); + return true; } //! [gesture event handler] diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 34fbb26c87..73a6bcf0f4 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -121,6 +121,9 @@ public: qreal totalRotationAngle; qreal lastRotationAngle; qreal rotationAngle; + + bool isNewSequence; + QPointF startPosition[2]; }; class QSwipeGesturePrivate : public QGesturePrivate diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 1d33c84873..6ea350ba15 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -77,6 +77,7 @@ QGestureManager::QGestureManager(QObject *parent) #endif #else registerGestureRecognizer(new QPanGestureRecognizer); + registerGestureRecognizer(new QPinchGestureRecognizer); #endif } diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index dec2311da2..57cf12d966 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -44,6 +44,7 @@ #include "qgesture_p.h" #include "qevent.h" #include "qwidget.h" +#include "qabstractscrollarea.h" QT_BEGIN_NAMESPACE @@ -54,7 +55,13 @@ QPanGestureRecognizer::QPanGestureRecognizer() QGesture *QPanGestureRecognizer::createGesture(QObject *target) { if (target && target->isWidgetType()) { +#if defined(Q_OS_WIN) + // for scroll areas on Windows we want to use native gestures instead + if (!qobject_cast(target->parent())) + static_cast(target)->setAttribute(Qt::WA_AcceptTouchEvents); +#else static_cast(target)->setAttribute(Qt::WA_AcceptTouchEvents); +#endif } return new QPanGesture; } @@ -132,104 +139,124 @@ void QPanGestureRecognizer::reset(QGesture *state) d->lastPosition = QPoint(); d->acceleration = 0; -//#if defined(QT_MAC_USE_COCOA) -// d->singleTouchPanTimer.stop(); -// d->prevMousePos = QPointF(0, 0); -//#endif - QGestureRecognizer::reset(state); } -/* -bool QPanGestureRecognizer::event(QEvent *event) + +// +// QPinchGestureRecognizer +// + +QPinchGestureRecognizer::QPinchGestureRecognizer() { -#if defined(QT_MAC_USE_COCOA) - Q_D(QPanGesture); - if (event->type() == QEvent::Timer) { - const QTimerEvent *te = static_cast(event); - if (te->timerId() == d->singleTouchPanTimer.timerId()) { - d->singleTouchPanTimer.stop(); - updateState(Qt::GestureStarted); - } +} + +QGesture *QPinchGestureRecognizer::createGesture(QObject *target) +{ + if (target && target->isWidgetType()) { + static_cast(target)->setAttribute(Qt::WA_AcceptTouchEvents); } -#endif + return new QPinchGesture; +} - bool consume = false; +QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +{ + QPinchGesture *q = static_cast(state); + QPinchGesturePrivate *d = q->d_func(); -#if defined(Q_WS_WIN) -#elif defined(QT_MAC_USE_COCOA) - // The following implements single touch - // panning on Mac: - const int panBeginDelay = 300; - const int panBeginRadius = 3; - const QTouchEvent *ev = static_cast(event); + const QTouchEvent *ev = static_cast(event); + + QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: { - if (ev->touchPoints().size() == 1) { - d->delayManager->setEnabled(true); - consume = d->delayManager->append(d->gestureTarget, *event); - d->lastPosition = QCursor::pos(); - d->singleTouchPanTimer.start(panBeginDelay, this); - } - break;} + result = QGestureRecognizer::MaybeGesture; + break; + } case QEvent::TouchEnd: { - d->delayManager->setEnabled(false); - if (state() != Qt::NoGesture) { - updateState(Qt::GestureFinished); - consume = true; - d->delayManager->clear(); + if (q->state() != Qt::NoGesture) { + result = QGestureRecognizer::GestureFinished; } else { - d->delayManager->replay(); + result = QGestureRecognizer::NotGesture; } - reset(); - break;} + break; + } case QEvent::TouchUpdate: { - consume = d->delayManager->append(d->gestureTarget, *event); - if (ev->touchPoints().size() == 1) { - if (state() == Qt::NoGesture) { - // INVARIANT: The singleTouchTimer has still not fired. - // Lets check if the user moved his finger so much from - // the starting point that it makes sense to cancel: - const QPointF startPos = ev->touchPoints().at(0).startPos().toPoint(); - const QPointF p = ev->touchPoints().at(0).pos().toPoint(); - if ((startPos - p).manhattanLength() > panBeginRadius) { - d->delayManager->replay(); - consume = false; - reset(); - } else { - d->lastPosition = QCursor::pos(); - } + d->whatChanged = 0; + if (ev->touchPoints().size() == 2) { + QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); + QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); + + d->hotSpot = p1.screenPos(); + d->isHotSpotSet = true; + + if (d->isNewSequence) { + d->startPosition[0] = p1.screenPos(); + d->startPosition[1] = p2.screenPos(); + } + QLineF line(p1.screenPos(), p2.screenPos()); + QLineF tmp(line); + tmp.setLength(line.length() / 2.); + QPointF centerPoint = tmp.p2(); + + d->lastCenterPoint = d->centerPoint; + d->centerPoint = centerPoint; + d->whatChanged |= QPinchGesture::CenterPointChanged; + + const qreal scaleFactor = QLineF(p1.pos(), p2.pos()).length() + / QLineF(d->startPosition[0], d->startPosition[1]).length(); + if (d->isNewSequence) { + d->lastScaleFactor = scaleFactor; } else { - d->delayManager->clear(); - QPointF mousePos = QCursor::pos(); - QPointF dist = mousePos - d->lastPosition; - d->lastPosition = mousePos; - d->lastOffset = d->offset; - d->offset = QSizeF(dist.x(), dist.y()); - d->totalOffset += d->offset; - updateState(Qt::GestureUpdated); + d->lastScaleFactor = d->scaleFactor; } - } else if (state() == Qt::NoGesture) { - d->delayManager->replay(); - consume = false; - reset(); + d->scaleFactor = scaleFactor; + d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor; + d->whatChanged |= QPinchGesture::ScaleFactorChanged; + + const qreal rotationAngle = -line.angle(); + if (d->isNewSequence) + d->lastRotationAngle = rotationAngle; + else + d->lastRotationAngle = d->rotationAngle; + d->rotationAngle = rotationAngle; + d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle; + d->whatChanged |= QPinchGesture::RotationAngleChanged; + + d->isNewSequence = false; + result = QGestureRecognizer::GestureTriggered; + } else { + d->isNewSequence = true; + result = QGestureRecognizer::MaybeGesture; } - break;} + break; + } case QEvent::MouseButtonPress: case QEvent::MouseMove: case QEvent::MouseButtonRelease: - if (d->delayManager->isEnabled()) - consume = d->delayManager->append(d->gestureTarget, *event); + result = QGestureRecognizer::Ignore; break; default: - return false; + result = QGestureRecognizer::Ignore; + break; } -#else - Q_UNUSED(event); -#endif - return QGestureRecognizer::Ignore; + return result; +} + +void QPinchGestureRecognizer::reset(QGesture *state) +{ + QPinchGesture *pinch = static_cast(state); + QPinchGesturePrivate *d = pinch->d_func(); + + d->whatChanged = 0; + + d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF(); + d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0; + d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0; + + d->isNewSequence = true; + + QGestureRecognizer::reset(state); } - */ QT_END_NAMESPACE diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index fec5c2fbd9..827b2a2615 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -69,6 +69,17 @@ public: void reset(QGesture *state); }; +class QPinchGestureRecognizer : public QGestureRecognizer +{ +public: + QPinchGestureRecognizer(); + + QGesture *createGesture(QObject *target); + + QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + void reset(QGesture *state); +}; + QT_END_NAMESPACE #endif // QSTANDARDGESTURES_P_H diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index ac2808c535..00d9a990a2 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -197,6 +197,7 @@ QWidgetPrivate::QWidgetPrivate(int version) , picture(0) #elif defined(Q_WS_WIN) , noPaintOnScreen(0) + , nativeGesturePanEnabled(0) #elif defined(Q_WS_MAC) , needWindowChange(0) , isGLWidget(0) diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 5bf7649198..3a92735e09 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -2071,17 +2071,6 @@ void QWidgetPrivate::winSetupGestures() gc[0].dwBlock = GC_PAN; } -// gc[1].dwID = GID_ZOOM; -// if (gestures.pinch) -// gc[1].dwWant = GC_ZOOM; -// else -// gc[1].dwBlock = GC_ZOOM; -// gc[2].dwID = GID_ROTATE; -// if (gestures.pinch) -// gc[2].dwWant = GC_ROTATE; -// else -// gc[2].dwBlock = GC_ROTATE; - qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0])); } } diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp index 12d3058188..c3c8a28cf6 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp @@ -56,16 +56,16 @@ QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer() { } -QGesture* QWinNativePanGestureRecognizer::createGesture(QObject *target) const +QGesture *QWinNativePanGestureRecognizer::createGesture(QObject *target) { if (!target) return new QPanGesture; // a special case - if (qobject_cast(target)) - return 0; if (!target->isWidgetType()) return 0; + if (qobject_cast(target)) + return 0; - QWidget *q = static_cast(target); + QWidget *q = static_cast(target); QWidgetPrivate *d = q->d_func(); d->nativeGesturePanEnabled = true; d->winSetupGestures(); diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h index a1e8511f66..1d723daa3e 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h @@ -62,7 +62,7 @@ class QWinNativePanGestureRecognizer : public QGestureRecognizer public: QWinNativePanGestureRecognizer(); - QGesture* createGesture(QObject *target) const; + QGesture *createGesture(QObject *target); QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); -- cgit v1.2.3 From 4843b437b90800d238f14e7a4558045ddc37cd4b Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 2 Nov 2009 11:13:39 +0100 Subject: Made native Pan gesture work on Windows. Reviewed-by: trustme --- src/gui/kernel/qapplication.cpp | 1 + src/gui/kernel/qapplication_p.h | 1 + src/gui/kernel/qapplication_win.cpp | 36 ++++++++++----------- src/gui/kernel/qgesturemanager.cpp | 6 ++++ src/gui/kernel/qwidget_win.cpp | 4 ++- src/gui/widgets/qabstractscrollarea.cpp | 55 +++++++++++++++++++-------------- src/gui/widgets/qplaintextedit.cpp | 53 ++++++++++++++++--------------- src/gui/widgets/qtextedit.cpp | 6 ++-- 8 files changed, 90 insertions(+), 72 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 1ec51dabe2..06787eb2bc 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -186,6 +186,7 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T #endif gestureManager = 0; + gestureWidget = 0; if (!self) self = this; diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 0fa726972a..2c57238c1a 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -511,6 +511,7 @@ public: #endif QGestureManager *gestureManager; + QWidget *gestureWidget; QMap widgetForTouchPointId; QMap appCurrentTouchPoints; diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index d98ecbb811..387c29b5d1 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -2499,24 +2499,24 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam if (qAppPriv->GetGestureInfo) bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi); if (bResult) { -// if (gi.dwID == GID_BEGIN) { -// // find the alien widget for the gesture position. -// // This might not be accurate as the position is the center -// // point of two fingers for multi-finger gestures. -// QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y); -// QWidget *w = widget->childAt(widget->mapFromGlobal(pt)); -// qAppPriv->gestureWidget = w ? w : widget; -// } -// if (qAppPriv->gestureWidget) -// static_cast(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi); -// if (qAppPriv->CloseGestureInfoHandle) -// qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); -// if (gi.dwID == GID_END) -// qAppPriv->gestureWidget = 0; -// } else { -// DWORD dwErr = GetLastError(); -// if (dwErr > 0) -// qWarning() << "translateGestureEvent: error = " << dwErr; + if (gi.dwID == GID_BEGIN) { + // find the alien widget for the gesture position. + // This might not be accurate as the position is the center + // point of two fingers for multi-finger gestures. + QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y); + QWidget *w = widget->childAt(widget->mapFromGlobal(pt)); + qAppPriv->gestureWidget = w ? w : widget; + } + if (qAppPriv->gestureWidget) + static_cast(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi); + if (qAppPriv->CloseGestureInfoHandle) + qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam); + if (gi.dwID == GID_END) + qAppPriv->gestureWidget = 0; + } else { + DWORD dwErr = GetLastError(); + if (dwErr > 0) + qWarning() << "translateGestureEvent: error = " << dwErr; } result = true; break; diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 6ea350ba15..318d4b5638 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -52,6 +52,9 @@ #ifdef Q_WS_MAC #include "qmacgesturerecognizer_mac_p.h" #endif +#if defined(Q_OS_WIN) +#include "qwinnativepangesturerecognizer_win_p.h" +#endif #include "qdebug.h" @@ -78,6 +81,9 @@ QGestureManager::QGestureManager(QObject *parent) #else registerGestureRecognizer(new QPanGestureRecognizer); registerGestureRecognizer(new QPinchGestureRecognizer); +#if defined(Q_OS_WIN) + registerGestureRecognizer(new QWinNativePanGestureRecognizer); +#endif #endif } diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp index 3a92735e09..22a94b92a8 100644 --- a/src/gui/kernel/qwidget_win.cpp +++ b/src/gui/kernel/qwidget_win.cpp @@ -2036,7 +2036,7 @@ void QWidgetPrivate::winSetupGestures() if (!q || !q->isVisible()) return; QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - WId winid = q->effectiveWinId(); + WId winid = q->internalWinId(); bool needh = false; bool needv = false; @@ -2052,6 +2052,8 @@ void QWidgetPrivate::winSetupGestures() needv = (vbarpolicy == Qt::ScrollBarAlwaysOn || (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum())); singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled; + if (!winid) + winid = q->winId(); // enforces the native winid on the viewport } if (winid && qAppPriv->SetGestureConfig) { GESTURECONFIG gc[1]; diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 08962567d2..7d81d5a4e2 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -293,13 +293,16 @@ void QAbstractScrollAreaPrivate::init() q->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); layoutChildren(); + viewport->grabGesture(Qt::PanGesture); } #ifdef Q_WS_WIN void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) { singleFingerPanEnabled = on; - winSetupGestures(); + QWidgetPrivate *dd = static_cast(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); } #endif // Q_WS_WIN @@ -539,6 +542,7 @@ void QAbstractScrollArea::setViewport(QWidget *widget) d->viewport->setParent(this); d->viewport->setFocusProxy(this); d->viewport->installEventFilter(d->viewportFilter.data()); + d->viewport->grabGesture(Qt::PanGesture); d->layoutChildren(); if (isVisible()) d->viewport->show(); @@ -935,6 +939,26 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::TouchUpdate: case QEvent::TouchEnd: return false; + case QEvent::Gesture: + { + QGestureEvent *ge = static_cast(e); + QPanGesture *g = static_cast(ge->gesture(Qt::PanGesture)); + if (g) { + QScrollBar *hBar = horizontalScrollBar(); + QScrollBar *vBar = verticalScrollBar(); + QPointF delta = g->lastOffset(); + if (!delta.isNull()) { + if (QApplication::isRightToLeft()) + delta.rx() *= -1; + int newX = hBar->value() - delta.x(); + int newY = vBar->value() - delta.y(); + hBar->setValue(newX); + vBar->setValue(newY); + } + return true; + } + return false; + } case QEvent::StyleChange: case QEvent::LayoutDirectionChange: case QEvent::ApplicationLayoutDirectionChange: @@ -990,6 +1014,8 @@ bool QAbstractScrollArea::viewportEvent(QEvent *e) #endif return QFrame::event(e); case QEvent::LayoutRequest: + case QEvent::Gesture: + case QEvent::GestureOverride: return event(e); default: break; @@ -1266,11 +1292,13 @@ void QAbstractScrollAreaPrivate::_q_vslide(int y) void QAbstractScrollAreaPrivate::_q_showOrHideScrollBars() { layoutChildren(); -#ifdef Q_OS_WIN +#ifdef Q_WS_WIN // Need to re-subscribe to gestures as the content changes to make sure we // enable/disable panning when needed. - winSetupGestures(); -#endif // Q_OS_WIN + QWidgetPrivate *dd = static_cast(QObjectPrivate::get(viewport)); + if (dd) + dd->winSetupGestures(); +#endif // Q_WS_WIN } QPoint QAbstractScrollAreaPrivate::contentsOffset() const @@ -1335,25 +1363,6 @@ void QAbstractScrollArea::setupViewport(QWidget *viewport) Q_UNUSED(viewport); } -//void QAbstractScrollAreaPrivate::_q_gestureTriggered() -//{ -// Q_Q(QAbstractScrollArea); -// QPanGesture *g = qobject_cast(q->sender()); -// if (!g) -// return; -// QScrollBar *hBar = q->horizontalScrollBar(); -// QScrollBar *vBar = q->verticalScrollBar(); -// QSizeF delta = g->lastOffset(); -// if (!delta.isNull()) { -// if (QApplication::isRightToLeft()) -// delta.rwidth() *= -1; -// int newX = hBar->value() - delta.width(); -// int newY = vBar->value() - delta.height(); -// hbar->setValue(newX); -// vbar->setValue(newY); -// } -//} - QT_END_NAMESPACE #include "moc_qabstractscrollarea.cpp" diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index fc618895d7..0e5ee46132 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -730,9 +730,6 @@ QPlainTextEditPrivate::QPlainTextEditPrivate() backgroundVisible = false; centerOnScroll = false; inDrag = false; -#ifdef Q_WS_WIN - singleFingerPanEnabled = true; -#endif } @@ -789,6 +786,9 @@ void QPlainTextEditPrivate::init(const QString &txt) viewport->setCursor(Qt::IBeamCursor); #endif originalOffsetY = 0; +#ifdef Q_WS_WIN + setSingleFingerPanEnabled(true); +#endif } void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) @@ -1450,6 +1450,29 @@ bool QPlainTextEdit::event(QEvent *e) d->sendControlEvent(e); } #endif + else if (e->type() == QEvent::Gesture) { + QGestureEvent *ge = static_cast(e); + QPanGesture *g = static_cast(ge->gesture(Qt::PanGesture)); + if (g) { + QScrollBar *hBar = horizontalScrollBar(); + QScrollBar *vBar = verticalScrollBar(); + if (g->state() == Qt::GestureStarted) + d->originalOffsetY = vBar->value(); + QPointF totalOffset = g->totalOffset(); + if (!totalOffset.isNull()) { + if (QApplication::isRightToLeft()) + totalOffset.rx() *= -1; + // QPlainTextEdit scrolls by lines only in vertical direction + QFontMetrics fm(document()->defaultFont()); + int lineHeight = fm.height(); + int newX = hBar->value() - g->lastOffset().x(); + int newY = d->originalOffsetY - totalOffset.y()/lineHeight; + hBar->setValue(newX); + vBar->setValue(newY); + } + } + return true; + } return QAbstractScrollArea::event(e); } @@ -2929,30 +2952,6 @@ QAbstractTextDocumentLayout::PaintContext QPlainTextEdit::getPaintContext() cons (\a available is true) or unavailable (\a available is false). */ -//void QPlainTextEditPrivate::_q_gestureTriggered() -//{ -// Q_Q(QPlainTextEdit); -// QPanGesture *g = qobject_cast(q->sender()); -// if (!g) -// return; -// QScrollBar *hBar = q->horizontalScrollBar(); -// QScrollBar *vBar = q->verticalScrollBar(); -// if (g->state() == Qt::GestureStarted) -// originalOffsetY = vBar->value(); -// QSizeF totalOffset = g->totalOffset(); -// if (!totalOffset.isNull()) { -// if (QApplication::isRightToLeft()) -// totalOffset.rwidth() *= -1; -// // QPlainTextEdit scrolls by lines only in vertical direction -// QFontMetrics fm(q->document()->defaultFont()); -// int lineHeight = fm.height(); -// int newX = hBar->value() - g->lastOffset().width(); -// int newY = originalOffsetY - totalOffset.height()/lineHeight; -// hbar->setValue(newX); -// vbar->setValue(newY); -// } -//} - QT_END_NAMESPACE #include "moc_qplaintextedit.cpp" diff --git a/src/gui/widgets/qtextedit.cpp b/src/gui/widgets/qtextedit.cpp index f477feeddc..355b678f97 100644 --- a/src/gui/widgets/qtextedit.cpp +++ b/src/gui/widgets/qtextedit.cpp @@ -116,9 +116,6 @@ QTextEditPrivate::QTextEditPrivate() preferRichText = false; showCursorOnInitialShow = true; inDrag = false; -#ifdef Q_WS_WIN - setSingleFingerPanEnabled(true); -#endif } void QTextEditPrivate::createAutoBulletList() @@ -186,6 +183,9 @@ void QTextEditPrivate::init(const QString &html) #ifndef QT_NO_CURSOR viewport->setCursor(Qt::IBeamCursor); #endif +#ifdef Q_WS_WIN + setSingleFingerPanEnabled(true); +#endif } void QTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) -- cgit v1.2.3 From cfcfae65778f2e1e7fc3936c66689e3685f1cc77 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Wed, 28 Oct 2009 21:40:14 +0100 Subject: Modified gesture events propagation. By default if the gesture is ignored, only gestures in the started state are propagated, and accepting a gesture in the started state adds an implicit grab meaning all the following events in the gesture sequence will be delivered to that widget. This is similar to the way QTouchEvent is propagated. Also added a hint, which specifies if gestures in any state can be propagated to the widget which has enabled the hint. Reviewed-by: Thomas Zander --- src/corelib/global/qnamespace.h | 12 +++- src/corelib/global/qnamespace.qdoc | 18 ++++- src/gui/graphicsview/qgraphicsscene.cpp | 13 +++- src/gui/kernel/qapplication.cpp | 7 +- src/gui/kernel/qgesturemanager.cpp | 16 ++++- tests/auto/gestures/tst_gestures.cpp | 121 +++++++++++++++++++++++++------- 6 files changed, 150 insertions(+), 37 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index aeaca54f71..561ffc1c51 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1715,14 +1715,19 @@ public: LastGestureType = ~0u }; - enum GestureContext + enum GestureContextFlag { WidgetGesture = 0, WidgetWithChildrenGesture = 3, - ItemGesture = WidgetGesture, - ItemWithChildrenGesture = WidgetWithChildrenGesture + ItemGesture = WidgetGesture, + ItemWithChildrenGesture = WidgetWithChildrenGesture, + + GestureContext_Mask = 0x00ff, + AcceptPartialGesturesHint = 0x0100, + GestureContextHint_Mask = 0xff00 }; + Q_DECLARE_FLAGS(GestureContext, GestureContextFlag) enum NavigationMode { @@ -1757,6 +1762,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MatchFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TextInteractionFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::InputMethodHints) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TouchPointStates) +Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::GestureContext) typedef bool (*qInternalCallback)(void **); diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 3fcbe57928..f2a8882855 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2917,11 +2917,11 @@ QApplication::registerGestureRecognizer() function which generates a custom gesture ID in the range of values from CustomGesture to LastGestureType. - \sa QGesture, QWidget::grabGesture() + \sa QGesture, QWidget::grabGesture(), QGraphicsObject::grabGesture() */ /*! - \enum Qt::GestureContext + \enum Qt::GestureContextFlag \since 4.6 This enum type describes the context of a gesture. @@ -2937,7 +2937,19 @@ \value ItemWithChildrenGesture Gestures can start on the item or over any of its children. - \sa QWidget::grabGesture() + \value AcceptPartialGesturesHint Allows any ignored gesture events to be + propagated to parent widgets which have specified this hint. By default + only gestures that are in the Qt::GestureStarted state are propagated and + the widget only gets the full gesture sequence starting with a gesture in + the Qt::GestureStarted state and ending with a gesture in the + Qt::GestureFinished or Qt::GestureCanceled states. + + \value GestureContext_Mask A mask for extracting the context type of the + context flags. + \value GestureContextHint_Mask A mask for extracting additional hints for + the context. + + \sa QWidget::grabGesture(), QGraphicsObject::grabGesture() */ /*! diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 9279fe36cc..f5bb408a7a 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5900,7 +5900,12 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func(); foreach(QGesture *g, alreadyIgnoredGestures) { - if (gid->gestureContext.contains(g->gestureType())) + QMap::iterator contextit = + gid->gestureContext.find(g->gestureType()); + bool deliver = contextit != gid->gestureContext.end() && + (g->state() == Qt::GestureStarted || + (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint); + if (deliver) gestures += g; } if (gestures.isEmpty()) @@ -5913,8 +5918,12 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) sendEvent(item, &ev); QSet ignoredGestures; foreach (QGesture *g, gestures) { - if (!ev.isAccepted() && !ev.isAccepted(g)) + if (!ev.isAccepted() && !ev.isAccepted(g)) { ignoredGestures.insert(g); + } else { + if (g->state() == Qt::GestureStarted) + gestureTargets[g] = item; + } } if (!ignoredGestures.isEmpty()) { // get a list of items under the (current) hotspot of each ignored diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 06787eb2bc..b9e7d527e7 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -4161,7 +4161,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e) for (int i = 0; i < allGestures.size();) { QGesture *g = allGestures.at(i); Qt::GestureType type = g->gestureType(); - if (wd->gestureContext.contains(type)) { + QMap::iterator contextit = + wd->gestureContext.find(type); + bool deliver = contextit != wd->gestureContext.end() && + (g->state() == Qt::GestureStarted || w == receiver || + (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint); + if (deliver) { allGestures.removeAt(i); gestures.append(g); } else { diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 318d4b5638..e4a1eb4630 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -448,7 +448,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) { for (ContextIterator it = w->d_func()->gestureContext.begin(), e = w->d_func()->gestureContext.end(); it != e; ++it) { - if (it.value() == Qt::WidgetWithChildrenGesture) { + if ((it.value() & Qt::GestureContext_Mask) == Qt::WidgetWithChildrenGesture) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(w, it.key()); @@ -482,7 +482,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) typedef QMap::const_iterator ContextIterator; for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { - if (it.value() == Qt::ItemWithChildrenGesture) { + if ((it.value() & Qt::GestureContext_Mask) == Qt::ItemWithChildrenGesture) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(item, it.key()); @@ -525,7 +525,7 @@ void QGestureManager::getGestureTargets(const QSet &gestures, = w->d_func()->gestureContext.find(type); if (it != w->d_func()->gestureContext.end()) { // i.e. 'w' listens to gesture 'type' - Qt::GestureContext context = it.value(); + Qt::GestureContext context = it.value() & Qt::GestureContext_Mask; if (context == Qt::WidgetWithChildrenGesture && w != widget) { // conflicting gesture! (*conflicts)[widget].append(gestures[widget]); @@ -645,6 +645,16 @@ void QGestureManager::deliverEvents(const QSet &gestures, << "gestures:" << it.value(); QGestureEvent event(it.value()); QApplication::sendEvent(it.key(), &event); + bool eventAccepted = event.isAccepted(); + foreach (QGesture *gesture, event.allGestures()) { + if (gesture->state() == Qt::GestureStarted && + (eventAccepted || event.isAccepted(gesture))) { + QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + Q_ASSERT(w); + DEBUG() << "started gesture was delivered and accepted by" << w; + m_gestureTargets[gesture] = w; + } + } } } } diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 79de8239d3..9b2bc577fe 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -543,7 +543,9 @@ void tst_Gestures::conflictingGestures() parent.reset(); child->reset(); - // nobody accepts the override, we will send normal events to the closest context (to the child) + // nobody accepts the override, we will send normal events to the closest + // context (i.e. to the child widget) and it will be propagated and + // accepted by the parent widget parent.acceptGestureOverride = false; child->acceptGestureOverride = false; child->ignoredGestures << CustomGesture::GestureType; @@ -551,6 +553,41 @@ void tst_Gestures::conflictingGestures() // sending events to the child and making sure there is no conflict sendCustomGesture(&event, child); + QCOMPARE(child->gestureOverrideEventsReceived, 1); + QCOMPARE(child->gestureEventsReceived, 1); + QCOMPARE(parent.gestureOverrideEventsReceived, 1); + QCOMPARE(parent.gestureEventsReceived, TotalGestureEventsCount); + + parent.reset(); + child->reset(); + + // nobody accepts the override, and nobody accepts the gesture event + parent.acceptGestureOverride = false; + child->acceptGestureOverride = false; + parent.ignoredGestures << CustomGesture::GestureType; + child->ignoredGestures << CustomGesture::GestureType; + + // sending events to the child and making sure there is no conflict + sendCustomGesture(&event, child); + + QCOMPARE(child->gestureOverrideEventsReceived, 1); + QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(parent.gestureOverrideEventsReceived, 1); + QCOMPARE(parent.gestureEventsReceived, 1); + + parent.reset(); + child->reset(); + + // we set an attribute to make sure all gesture events are propagated + parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + parent.acceptGestureOverride = false; + child->acceptGestureOverride = false; + parent.ignoredGestures << CustomGesture::GestureType; + child->ignoredGestures << CustomGesture::GestureType; + + // sending events to the child and making sure there is no conflict + sendCustomGesture(&event, child); + QCOMPARE(child->gestureOverrideEventsReceived, 1); QCOMPARE(child->gestureEventsReceived, TotalGestureEventsCount); QCOMPARE(parent.gestureOverrideEventsReceived, 1); @@ -851,7 +888,7 @@ void tst_Gestures::graphicsItemTreeGesture() QCOMPARE(item1_child2->gestureEventsReceived, 0); QCOMPARE(item1_child2->gestureOverrideEventsReceived, 0); QCOMPARE(item1->gestureOverrideEventsReceived, 1); - QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item1->gestureEventsReceived, 1); } void tst_Gestures::explicitGraphicsObjectTarget() @@ -966,7 +1003,39 @@ void tst_Gestures::gestureOverChildGraphicsItem() event.hasHotSpot = true; sendCustomGesture(&event, item0, &scene); - QCOMPARE(item0->customEventsReceived, TotalCustomEventsCount); + QCOMPARE(item2_child1->gestureEventsReceived, 0); + QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); + QCOMPARE(item2->gestureEventsReceived, 1); + QCOMPARE(item2->gestureOverrideEventsReceived, 1); + QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item1->gestureOverrideEventsReceived, 1); + + item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); + item2->grabGesture(CustomGesture::GestureType); + item2->ignoredGestures << CustomGesture::GestureType; + item1->ignoredGestures << CustomGesture::GestureType; + + event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); + event.hasHotSpot = true; + sendCustomGesture(&event, item0, &scene); + + QCOMPARE(item2_child1->gestureEventsReceived, 0); + QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); + QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); + QCOMPARE(item2->gestureOverrideEventsReceived, 1); + QCOMPARE(item1->gestureEventsReceived, 1); + QCOMPARE(item1->gestureOverrideEventsReceived, 1); + + item0->reset(); item1->reset(); item2->reset(); item2_child1->reset(); + item2->grabGesture(CustomGesture::GestureType); + item2->ignoredGestures << CustomGesture::GestureType; + item1->ignoredGestures << CustomGesture::GestureType; + item1->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + + event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); + event.hasHotSpot = true; + sendCustomGesture(&event, item0, &scene); + QCOMPARE(item2_child1->gestureEventsReceived, 0); QCOMPARE(item2_child1->gestureOverrideEventsReceived, 0); QCOMPARE(item2->gestureEventsReceived, TotalGestureEventsCount); @@ -1025,15 +1094,16 @@ void tst_Gestures::multipleGesturesInTree() Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - A->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); // A [1 3] - A->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); // | - B->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); // B [ 2 3] - B->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); // | - C->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); // C [1 2 3] - C->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); // | - C->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); // D [1 3] - D->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); - D->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); + Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; + A->grabGesture(FirstGesture, context); // A [1 3] + A->grabGesture(ThirdGesture, context); // | + B->grabGesture(SecondGesture, context); // B [ 2 3] + B->grabGesture(ThirdGesture, context); // | + C->grabGesture(FirstGesture, context); // C [1 2 3] + C->grabGesture(SecondGesture, context); // | + C->grabGesture(ThirdGesture, context); // D [1 3] + D->grabGesture(FirstGesture, context); + D->grabGesture(ThirdGesture, context); // make sure all widgets ignore events, so they get propagated. A->ignoredGestures << FirstGesture << ThirdGesture; @@ -1100,19 +1170,20 @@ void tst_Gestures::multipleGesturesInComplexTree() Qt::GestureType SixthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); Qt::GestureType SeventhGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - A->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); // A [1,3,4] - A->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); // | - A->grabGesture(FourthGesture, Qt::WidgetWithChildrenGesture); // B [2,3,5] - B->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); // | - B->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); // C [1,2,3,6] - B->grabGesture(FifthGesture, Qt::WidgetWithChildrenGesture); // | - C->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); // D [1,3,7] - C->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); - C->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); - C->grabGesture(SixthGesture, Qt::WidgetWithChildrenGesture); - D->grabGesture(FirstGesture, Qt::WidgetWithChildrenGesture); - D->grabGesture(ThirdGesture, Qt::WidgetWithChildrenGesture); - D->grabGesture(SeventhGesture, Qt::WidgetWithChildrenGesture); + Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; + A->grabGesture(FirstGesture, context); // A [1,3,4] + A->grabGesture(ThirdGesture, context); // | + A->grabGesture(FourthGesture, context); // B [2,3,5] + B->grabGesture(SecondGesture, context); // | + B->grabGesture(ThirdGesture, context); // C [1,2,3,6] + B->grabGesture(FifthGesture, context); // | + C->grabGesture(FirstGesture, context); // D [1,3,7] + C->grabGesture(SecondGesture, context); + C->grabGesture(ThirdGesture, context); + C->grabGesture(SixthGesture, context); + D->grabGesture(FirstGesture, context); + D->grabGesture(ThirdGesture, context); + D->grabGesture(SeventhGesture, context); // make sure all widgets ignore events, so they get propagated. QSet allGestureTypes; -- cgit v1.2.3 From 93e9bc06427c6a8e1b6d6f939cf53ae5c95e0827 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 2 Nov 2009 19:26:44 +0100 Subject: Gesture api review. Changes to the gesture api after the review. Reviewed-by: Jasmin Blanchette --- doc/src/frameworks-technologies/gestures.qdoc | 14 +- examples/gestures/imagegestures/imagewidget.cpp | 6 +- src/corelib/global/qnamespace.h | 17 +- src/corelib/global/qnamespace.qdoc | 36 ++-- src/gui/graphicsview/qgraphicsitem.cpp | 6 +- src/gui/graphicsview/qgraphicsitem.h | 2 +- src/gui/graphicsview/qgraphicsitem_p.h | 2 +- src/gui/graphicsview/qgraphicsscene.cpp | 16 +- src/gui/kernel/qapplication.cpp | 54 +----- src/gui/kernel/qapplication.h | 4 - src/gui/kernel/qapplication_p.h | 2 - src/gui/kernel/qevent.cpp | 22 ++- src/gui/kernel/qevent.h | 4 +- src/gui/kernel/qgesture.cpp | 89 +++++---- src/gui/kernel/qgesture.h | 21 +- src/gui/kernel/qgesture_p.h | 10 +- src/gui/kernel/qgesturemanager.cpp | 44 +++-- src/gui/kernel/qgesturemanager_p.h | 3 +- src/gui/kernel/qgesturerecognizer.cpp | 86 ++++++--- src/gui/kernel/qgesturerecognizer.h | 25 ++- src/gui/kernel/qstandardgestures.cpp | 63 +++--- src/gui/kernel/qstandardgestures_p.h | 9 +- src/gui/kernel/qwidget.cpp | 8 +- src/gui/kernel/qwidget.h | 2 +- src/gui/kernel/qwidget_p.h | 2 +- src/gui/widgets/qplaintextedit.cpp | 8 +- tests/auto/gestures/tst_gestures.cpp | 212 ++++++++++----------- tests/manual/gestures/graphicsview/gestures.cpp | 24 +-- tests/manual/gestures/graphicsview/gestures.h | 8 +- tests/manual/gestures/graphicsview/main.cpp | 10 +- .../graphicsview/mousepangesturerecognizer.cpp | 25 +-- .../graphicsview/mousepangesturerecognizer.h | 4 +- tests/manual/gestures/scrollarea/main.cpp | 20 +- .../scrollarea/mousepangesturerecognizer.cpp | 25 +-- .../scrollarea/mousepangesturerecognizer.h | 4 +- 35 files changed, 441 insertions(+), 446 deletions(-) diff --git a/doc/src/frameworks-technologies/gestures.qdoc b/doc/src/frameworks-technologies/gestures.qdoc index f64e301725..2fa8dabe9a 100644 --- a/doc/src/frameworks-technologies/gestures.qdoc +++ b/doc/src/frameworks-technologies/gestures.qdoc @@ -122,7 +122,7 @@ \section2 Filtering Input Events - The \l{QGestureRecognizer::}{filterEvent()} function must be reimplemented. + The \l{QGestureRecognizer::}{recognize()} function must be reimplemented. This function handles and filters the incoming input events for the target objects and determines whether or not they correspond to the gesture the recognizer is looking for. @@ -132,15 +132,15 @@ persistent information about the state of the recognition process in the QGesture object supplied. - Your \l{QGestureRecognizer::}{filterEvent()} function must return a value of - Qt::GestureState that indicates the state of recognition for a given gesture and + Your \l{QGestureRecognizer::}{recognize()} function must return a value of + QGestureRecognizer::Result that indicates the state of recognition for a given gesture and target object. This determines whether or not a gesture event will be delivered to a target object. \section2 Custom Gestures If you choose to represent a gesture by a custom QGesture subclass, you will need to - reimplement the \l{QGestureRecognizer::}{createGesture()} function to construct + reimplement the \l{QGestureRecognizer::}{create()} function to construct instances of your gesture class instead of standard QGesture instances. Alternatively, you may want to use standard QGesture instances, but add additional dynamic properties to them to express specific details of the gesture you want to handle. @@ -152,7 +152,7 @@ \l{QGestureRecognizer::}{reset()} function to perform these special tasks. Note that QGesture objects are only created once for each combination of target object - and gesture type, and they are reused every time the user attempts to perform the + and gesture type, and they might be reused every time the user attempts to perform the same gesture type on the target object. As a result, it can be useful to reimplement the \l{QGestureRecognizer::}{reset()} function to clean up after each previous attempt at recognizing a gesture. @@ -162,8 +162,8 @@ To use a gesture recognizer, construct an instance of your QGestureRecognizer subclass, and register it with the application with - QApplication::registerGestureRecognizer(). A recognizer for a given type of - gesture can be removed with QApplication::unregisterGestureRecognizer(). + QGestureRecognizer::registerRecognizer(). A recognizer for a given type of + gesture can be removed with QGestureRecognizer::unregisterRecognizer(). \section1 Further Reading diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp index c798fcc479..da9daaeb15 100644 --- a/examples/gestures/imagegestures/imagewidget.cpp +++ b/examples/gestures/imagegestures/imagewidget.cpp @@ -132,13 +132,13 @@ void ImageWidget::panTriggered(QPanGesture *gesture) void ImageWidget::pinchTriggered(QPinchGesture *gesture) { - QPinchGesture::WhatChanged whatChanged = gesture->whatChanged(); - if (whatChanged & QPinchGesture::RotationAngleChanged) { + QPinchGesture::ChangeFlags changeFlags = gesture->changeFlags(); + if (changeFlags & QPinchGesture::RotationAngleChanged) { qreal value = gesture->property("rotationAngle").toReal(); qreal lastValue = gesture->property("lastRotationAngle").toReal(); rotationAngle += value - lastValue; } - if (whatChanged & QPinchGesture::ScaleFactorChanged) { + if (changeFlags & QPinchGesture::ScaleFactorChanged) { qreal value = gesture->property("scaleFactor").toReal(); qreal lastValue = gesture->property("lastScaleFactor").toReal(); scaleFactor += value - lastValue; diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 561ffc1c51..efa6cc7345 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1715,19 +1715,12 @@ public: LastGestureType = ~0u }; - enum GestureContextFlag + enum GestureFlag { - WidgetGesture = 0, - WidgetWithChildrenGesture = 3, - - ItemGesture = WidgetGesture, - ItemWithChildrenGesture = WidgetWithChildrenGesture, - - GestureContext_Mask = 0x00ff, - AcceptPartialGesturesHint = 0x0100, - GestureContextHint_Mask = 0xff00 + DontStartGestureOnChildren = 0x01, + ReceivePartialGestures = 0x02 }; - Q_DECLARE_FLAGS(GestureContext, GestureContextFlag) + Q_DECLARE_FLAGS(GestureFlags, GestureFlag) enum NavigationMode { @@ -1762,7 +1755,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::MatchFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TextInteractionFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::InputMethodHints) Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TouchPointStates) -Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::GestureContext) +Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::GestureFlags) typedef bool (*qInternalCallback)(void **); diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index f2a8882855..a00a72ba1f 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2910,45 +2910,35 @@ \value PanGesture A Pan gesture. \value PinchGesture A Pinch gesture. \value SwipeGesture A Swipe gesture. - \value CustomGesture User-defined gesture ID. - \value LastGestureType Last user gesture ID. + \value CustomGesture A flag that can be used to test if the gesture is a + user-defined gesture ID. + \omitvalue LastGestureType User-defined gestures are registered with the - QApplication::registerGestureRecognizer() function which generates a custom gesture ID - in the range of values from CustomGesture to LastGestureType. + QGestureRecognizer::registerRecognizer() function which generates a custom + gesture ID with the Qt::CustomGesture flag set. \sa QGesture, QWidget::grabGesture(), QGraphicsObject::grabGesture() */ /*! - \enum Qt::GestureContextFlag + \enum Qt::GestureFlag \since 4.6 - This enum type describes the context of a gesture. + This enum type describes additional flags that can be used when subscribing + to a gesture. - For a QGesture to trigger, the gesture recognizer should filter events for - a widget tree. This enum describes for which widget the gesture recognizer - should filter events: + \value DontStartGestureOnChildren By default gestures can start on the + widget or over any of its children. Use this flag to disable this and allow + a gesture to start on the widget only. - \value WidgetGesture Gestures can only start over the widget itself. - \value WidgetWithChildrenGesture Gestures can start on the widget or over - any of its children. - \value ItemGesture Gestures can only start over the item itself. - \value ItemWithChildrenGesture Gestures can start on the item or over - any of its children. - - \value AcceptPartialGesturesHint Allows any ignored gesture events to be + \value ReceivePartialGestures Allows any ignored gesture events to be propagated to parent widgets which have specified this hint. By default only gestures that are in the Qt::GestureStarted state are propagated and - the widget only gets the full gesture sequence starting with a gesture in + the widget always gets the full gesture sequence starting with a gesture in the Qt::GestureStarted state and ending with a gesture in the Qt::GestureFinished or Qt::GestureCanceled states. - \value GestureContext_Mask A mask for extracting the context type of the - context flags. - \value GestureContextHint_Mask A mask for extracting additional hints for - the context. - \sa QWidget::grabGesture(), QGraphicsObject::grabGesture() */ diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 58d7e7dfbf..72f08d57e9 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7320,14 +7320,14 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent } /*! - Subscribes the graphics object to the given \a gesture for the specified \a context. + Subscribes the graphics object to the given \a gesture with specific \a flags. \sa ungrabGesture(), QGestureEvent */ -void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) +void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) { QGraphicsItemPrivate * const d = QGraphicsItem::d_func(); - d->gestureContext.insert(gesture, context); + d->gestureContext.insert(gesture, flags); (void)QGestureManager::instance(); // create a gesture manager } diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index fc180f3f22..f091e34a6a 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -555,7 +555,7 @@ public: using QObject::children; #endif - void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture); + void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags()); void ungrabGesture(Qt::GestureType type); Q_SIGNALS: diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 183e95be9f..90e4631780 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -453,7 +453,7 @@ public: QGraphicsItem *focusScopeItem; Qt::InputMethodHints imHints; QGraphicsItem::PanelModality panelModality; - QMap gestureContext; + QMap gestureContext; // Packed 32 bits quint32 acceptedMouseButtons : 5; diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index f5bb408a7a..aed2837550 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1060,9 +1060,8 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) { if (QGraphicsObject *object = item->toGraphicsObject()) { - QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); - if (qAppPriv->gestureManager) { - if (qAppPriv->gestureManager->filterEvent(object, event)) + if (qt_gestureManager) { + if (qt_gestureManager->filterEvent(object, event)) return true; } } @@ -5761,7 +5760,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QWidget *viewport = event->widget(); if (!viewport) return; - QList allGestures = event->allGestures(); + QList allGestures = event->gestures(); DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "Delivering gestures:" << allGestures; @@ -5900,11 +5899,11 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QGraphicsItemPrivate *gid = item->QGraphicsItem::d_func(); foreach(QGesture *g, alreadyIgnoredGestures) { - QMap::iterator contextit = + QMap::iterator contextit = gid->gestureContext.find(g->gestureType()); bool deliver = contextit != gid->gestureContext.end() && (g->state() == Qt::GestureStarted || - (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint); + (contextit.value() & Qt::ReceivePartialGestures)); if (deliver) gestures += g; } @@ -6046,10 +6045,9 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidge } } - QGestureManager *gm = QApplicationPrivate::instance()->gestureManager; - Q_ASSERT(gm); // it would be very odd if we got called without a manager. + Q_ASSERT(qt_gestureManager); // it would be very odd if we got called without a manager. for (setIter = canceledGestures.begin(); setIter != canceledGestures.end(); ++setIter) { - gm->recycle(*setIter); + qt_gestureManager->recycle(*setIter); gestureTargets.remove(*setIter); } } diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index b9e7d527e7..60ab05abf4 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -154,14 +154,6 @@ bool QApplicationPrivate::autoSipEnabled = false; bool QApplicationPrivate::autoSipEnabled = true; #endif -QGestureManager* QGestureManager::instance() -{ - QApplicationPrivate *d = qApp->d_func(); - if (!d->gestureManager) - d->gestureManager = new QGestureManager(qApp); - return d->gestureManager; -} - QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::Type type) : QCoreApplicationPrivate(argc, argv) { @@ -185,7 +177,6 @@ QApplicationPrivate::QApplicationPrivate(int &argc, char **argv, QApplication::T directPainters = 0; #endif - gestureManager = 0; gestureWidget = 0; if (!self) @@ -3632,12 +3623,12 @@ bool QApplication::notify(QObject *receiver, QEvent *e) } // walk through parents and check for gestures - if (d->gestureManager) { + if (qt_gestureManager) { if (receiver->isWidgetType()) { - if (d->gestureManager->filterEvent(static_cast(receiver), e)) + if (qt_gestureManager->filterEvent(static_cast(receiver), e)) return true; } else if (QGesture *gesture = qobject_cast(receiver)) { - if (d->gestureManager->filterEvent(gesture, e)) + if (qt_gestureManager->filterEvent(gesture, e)) return true; } } @@ -4150,7 +4141,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) if (receiver->isWidgetType()) { QWidget *w = static_cast(receiver); QGestureEvent *gestureEvent = static_cast(e); - QList allGestures = gestureEvent->allGestures(); + QList allGestures = gestureEvent->gestures(); bool eventAccepted = gestureEvent->isAccepted(); bool wasAccepted = eventAccepted; @@ -4161,11 +4152,11 @@ bool QApplication::notify(QObject *receiver, QEvent *e) for (int i = 0; i < allGestures.size();) { QGesture *g = allGestures.at(i); Qt::GestureType type = g->gestureType(); - QMap::iterator contextit = + QMap::iterator contextit = wd->gestureContext.find(type); bool deliver = contextit != wd->gestureContext.end() && (g->state() == Qt::GestureStarted || w == receiver || - (contextit.value() & Qt::GestureContextHint_Mask) & Qt::AcceptPartialGesturesHint); + (contextit.value() & Qt::ReceivePartialGestures)); if (deliver) { allGestures.removeAt(i); gestures.append(g); @@ -5616,39 +5607,6 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window, QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints); } -/*! - \since 4.6 - - Registers the given \a recognizer in the gesture framework and returns a gesture ID - for it. - - The application takes ownership of the \a recognizer and returns the gesture type - ID associated with it. For gesture recognizers which handle custom QGesture - objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType() - function) the return value is a gesture ID between Qt::CustomGesture and - Qt::LastGestureType, inclusive. - - \sa unregisterGestureRecognizer(), QGestureRecognizer::createGesture(), QGesture -*/ -Qt::GestureType QApplication::registerGestureRecognizer(QGestureRecognizer *recognizer) -{ - return QGestureManager::instance()->registerGestureRecognizer(recognizer); -} - -/*! - \since 4.6 - - Unregisters all gesture recognizers of the specified \a type. - - \sa registerGestureRecognizer() -*/ -void QApplication::unregisterGestureRecognizer(Qt::GestureType type) -{ - QApplicationPrivate *d = qApp->d_func(); - if (d->gestureManager) - d->gestureManager->unregisterGestureRecognizer(type); -} - QT_END_NAMESPACE #include "moc_qapplication.cpp" diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index 5877ba45ce..e8c1281591 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -86,7 +86,6 @@ class QSymbianEvent; class QApplication; class QApplicationPrivate; -class QGestureRecognizer; #if defined(qApp) #undef qApp #endif @@ -288,9 +287,6 @@ public: static Qt::NavigationMode navigationMode(); #endif - static Qt::GestureType registerGestureRecognizer(QGestureRecognizer *recognizer); - static void unregisterGestureRecognizer(Qt::GestureType type); - Q_SIGNALS: void lastWindowClosed(); void focusChanged(QWidget *old, QWidget *now); diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 2c57238c1a..8df4d081ff 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -84,7 +84,6 @@ class QInputContext; class QObject; class QWidget; class QSocketNotifier; -class QGestureManager; extern bool qt_is_gui_used; #ifndef QT_NO_CLIPBOARD @@ -510,7 +509,6 @@ public: void sendSyntheticEnterLeave(QWidget *widget); #endif - QGestureManager *gestureManager; QWidget *gestureWidget; QMap widgetForTouchPointId; diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 6757fa27a4..763b681bdc 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -4202,7 +4202,7 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T \brief The QGestureEvent class provides the description of triggered gestures. The QGestureEvent class contains a list of gestures, which can be obtained using the - allGestures() function. + gestures() function. The gestures are either active or canceled. A list of those that are currently being executed can be obtained using the activeGestures() function. A list of those which @@ -4211,10 +4211,11 @@ QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::T focus, for example, or because of a timeout, or for other reasons. If the event handler does not accept the event by calling the generic - QEvent::accept() function, all individual QGesture object that were not accepted - will be propagated up the parent widget chain until a widget accepts them - individually, by calling QGestureEvent::accept() for each of them, or an event - filter consumes the event. + QEvent::accept() function, all individual QGesture object that were not + accepted and in the Qt::GestureStarted state will be propagated up the + parent widget chain until a widget accepts them individually, by calling + QGestureEvent::accept() for each of them, or an event filter consumes the + event. \sa QGesture, QGestureRecognizer, QWidget::grabGesture(), QGraphicsObject::grabGesture() @@ -4240,7 +4241,7 @@ QGestureEvent::~QGestureEvent() /*! Returns all gestures that are delivered in the event. */ -QList QGestureEvent::allGestures() const +QList QGestureEvent::gestures() const { return d_func()->gestures; } @@ -4417,11 +4418,16 @@ QWidget *QGestureEvent::widget() const } /*! - Returns the scene-local coordinates if the \a gesturePoint is inside a graphics view. + Returns the scene-local coordinates if the \a gesturePoint is inside a + graphics view. + + This functional might be useful when the gesture event is delivered to a + QGraphicsObject to translate a point in screen coordinates to scene-local + coordinates. \sa QPointF::isNull(). */ -QPointF QGestureEvent::mapToScene(const QPointF &gesturePoint) const +QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const { QWidget *w = widget(); if (w) // we get the viewport as widget, not the graphics view diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index fb245c0b57..dfd0f3383c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -827,7 +827,7 @@ public: QGestureEvent(const QList &gestures); ~QGestureEvent(); - QList allGestures() const; + QList gestures() const; QGesture *gesture(Qt::GestureType type) const; QList activeGestures() const; @@ -859,7 +859,7 @@ public: void setWidget(QWidget *widget); QWidget *widget() const; - QPointF mapToScene(const QPointF &gesturePoint) const; + QPointF mapToGraphicsScene(const QPointF &gesturePoint) const; private: QGestureEventPrivate *d_func(); diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp index df9974601a..e322af25f3 100644 --- a/src/gui/kernel/qgesture.cpp +++ b/src/gui/kernel/qgesture.cpp @@ -54,7 +54,7 @@ QT_BEGIN_NAMESPACE Gesture objects are not constructed directly by developers. They are created by the QGestureRecognizer object that is registered with the application; see - QApplication::registerGestureRecognizer(). + QGestureRecognizer::registerRecognizer(). \section1 Gesture Properties @@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE destroy particular instances of them and create new ones to replace them. The registered gesture recognizer monitors the input events for the target - object via its \l{QGestureRecognizer::}{filterEvent()} function, updating the + object via its \l{QGestureRecognizer::}{recognize()} function, updating the properties of the gesture object as required. The gesture object may be delivered to the target object in a QGestureEvent if @@ -90,7 +90,7 @@ QT_BEGIN_NAMESPACE Constructs a new gesture object with the given \a parent. QGesture objects are created by gesture recognizers in the - QGestureRecognizer::createGesture() function. + QGestureRecognizer::create() function. */ QGesture::QGesture(QObject *parent) : QObject(*new QGesturePrivate, parent) @@ -129,7 +129,7 @@ QGesture::~QGesture() \brief The point that is used to find the receiver for the gesture event. The hot-spot is a point in the global coordinate system, use - QWidget::mapFromGlobal() or QGestureEvent::mapToScene() to get a + QWidget::mapFromGlobal() or QGestureEvent::mapToGraphicsScene() to get a local hot-spot. The hot-spot should be set by the gesture recognizer to allow gesture event @@ -180,8 +180,10 @@ void QGesture::unsetHotSpot() automatically. \value CancelNone On accepting this gesture no other gestures will be affected. - \value CancelAllInContext On accepting this gesture all gestures that are active - in the context (Qt::GestureContext) will be cancelled. + + \value CancelAllInContext On accepting this gesture all gestures that are + active in the context (respecting the Qt::GestureFlag that were specified + when subscribed to the gesture) will be cancelled. */ void QGesture::setGestureCancelPolicy(GestureCancelPolicy policy) @@ -207,15 +209,6 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const \sa {Gestures Programming}, QPinchGesture, QSwipeGesture */ -/*! - \property QPanGesture::totalOffset - \brief the total offset from the first input position to the current input - position - - The total offset measures the total change in position of the user's input - covered by the gesture on the input device. -*/ - /*! \property QGesture::gestureCancelPolicy \brief the policy for deciding what happens on accepting a gesture @@ -241,11 +234,19 @@ QGesture::GestureCancelPolicy QGesture::gestureCancelPolicy() const /*! \property QPanGesture::offset - \brief the offset from the previous input position to the current input + \brief the total offset from the first input position to the current input position - The offset measures the change in position of the user's input on the - input device. + The offset measures the total change in position of the user's input + covered by the gesture on the input device. +*/ + +/*! + \property QPanGesture::delta + \brief the offset from the previous input position to the current input + + This is essentially the same as the difference between offset() and + lastOffset(). */ /*! @@ -261,10 +262,6 @@ QPanGesture::QPanGesture(QObject *parent) d_func()->gestureType = Qt::PanGesture; } -QPointF QPanGesture::totalOffset() const -{ - return d_func()->totalOffset; -} QPointF QPanGesture::lastOffset() const { @@ -276,15 +273,15 @@ QPointF QPanGesture::offset() const return d_func()->offset; } -qreal QPanGesture::acceleration() const +QPointF QPanGesture::delta() const { - return d_func()->acceleration; + Q_D(const QPanGesture); + return d->offset - d->lastOffset; } - -void QPanGesture::setTotalOffset(const QPointF &value) +qreal QPanGesture::acceleration() const { - d_func()->totalOffset = value; + return d_func()->acceleration; } void QPanGesture::setLastOffset(const QPointF &value) @@ -326,7 +323,7 @@ void QPanGesture::setAcceleration(qreal value) */ /*! - \enum QPinchGesture::WhatChange + \enum QPinchGesture::ChangeFlag This enum describes the changes that can occur to the properties of the gesture object. @@ -335,19 +332,30 @@ void QPanGesture::setAcceleration(qreal value) \value RotationAngleChanged The rotation angle held by rotationAngle changed. \value CenterPointChanged The center point held by centerPoint changed. - \sa whatChanged + \sa changeFlags, totalChangeFlags +*/ + +/*! + \property QPinchGesture::totalChangeFlags + \brief the property of the gesture that has change + + This property indicates which of the other properties has changed since the + gesture has started. You can use this information to determine which aspect + of your user interface needs to be updated. + + \sa changeFlags, scaleFactor, rotationAngle, centerPoint */ /*! - \property QPinchGesture::whatChanged - \brief the property of the gesture that has changed + \property QPinchGesture::changeFlags + \brief the property of the gesture that has changed in the current step This property indicates which of the other properties has changed since the previous gesture event included information about this gesture. You can use this information to determine which aspect of your user interface needs to be updated. - \sa scaleFactor, rotationAngle, centerPoint + \sa totalChangeFlags, scaleFactor, rotationAngle, centerPoint */ /*! @@ -441,16 +449,25 @@ QPinchGesture::QPinchGesture(QObject *parent) d_func()->gestureType = Qt::PinchGesture; } -QPinchGesture::WhatChanged QPinchGesture::whatChanged() const +QPinchGesture::ChangeFlags QPinchGesture::totalChangeFlags() const +{ + return d_func()->totalChangeFlags; +} + +void QPinchGesture::setTotalChangeFlags(QPinchGesture::ChangeFlags value) { - return d_func()->whatChanged; + d_func()->totalChangeFlags = value; } -void QPinchGesture::setWhatChanged(QPinchGesture::WhatChanged value) +QPinchGesture::ChangeFlags QPinchGesture::changeFlags() const { - d_func()->whatChanged = value; + return d_func()->changeFlags; } +void QPinchGesture::setChangeFlags(QPinchGesture::ChangeFlags value) +{ + d_func()->changeFlags = value; +} QPointF QPinchGesture::startCenterPoint() const { diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h index 8614ecbfca..dd322adac9 100644 --- a/src/gui/kernel/qgesture.h +++ b/src/gui/kernel/qgesture.h @@ -106,20 +106,19 @@ class Q_GUI_EXPORT QPanGesture : public QGesture Q_OBJECT Q_DECLARE_PRIVATE(QPanGesture) - Q_PROPERTY(QPointF totalOffset READ totalOffset WRITE setTotalOffset) Q_PROPERTY(QPointF lastOffset READ lastOffset WRITE setLastOffset) Q_PROPERTY(QPointF offset READ offset WRITE setOffset) + Q_PROPERTY(QPointF delta READ delta STORED false) Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration) public: QPanGesture(QObject *parent = 0); - QPointF totalOffset() const; QPointF lastOffset() const; QPointF offset() const; + QPointF delta() const; qreal acceleration() const; - void setTotalOffset(const QPointF &value); void setLastOffset(const QPointF &value); void setOffset(const QPointF &value); void setAcceleration(qreal value); @@ -135,14 +134,15 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture Q_DECLARE_PRIVATE(QPinchGesture) public: - enum WhatChange { + enum ChangeFlag { ScaleFactorChanged = 0x1, RotationAngleChanged = 0x2, CenterPointChanged = 0x4 }; - Q_DECLARE_FLAGS(WhatChanged, WhatChange) + Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) - Q_PROPERTY(WhatChanged whatChanged READ whatChanged WRITE setWhatChanged) + Q_PROPERTY(ChangeFlags totalChangeFlags READ totalChangeFlags WRITE setTotalChangeFlags) + Q_PROPERTY(ChangeFlags changeFlags READ changeFlags WRITE setChangeFlags) Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor WRITE setTotalScaleFactor) Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor WRITE setLastScaleFactor) @@ -159,8 +159,11 @@ public: public: QPinchGesture(QObject *parent = 0); - WhatChanged whatChanged() const; - void setWhatChanged(WhatChanged value); + ChangeFlags totalChangeFlags() const; + void setTotalChangeFlags(ChangeFlags value); + + ChangeFlags changeFlags() const; + void setChangeFlags(ChangeFlags value); QPointF startCenterPoint() const; QPointF lastCenterPoint() const; @@ -188,7 +191,7 @@ public: QT_END_NAMESPACE -Q_DECLARE_METATYPE(QPinchGesture::WhatChanged) +Q_DECLARE_METATYPE(QPinchGesture::ChangeFlags) QT_BEGIN_NAMESPACE diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 73a6bcf0f4..96fd64d185 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -90,7 +90,6 @@ public: { } - QPointF totalOffset; QPointF lastOffset; QPointF offset; QPoint lastPosition; @@ -103,12 +102,15 @@ class QPinchGesturePrivate : public QGesturePrivate public: QPinchGesturePrivate() - : whatChanged(0), totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0), - totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0) + : totalChangeFlags(0), changeFlags(0), + totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0), + totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0), + isNewSequence(true) { } - QPinchGesture::WhatChanged whatChanged; + QPinchGesture::ChangeFlags totalChangeFlags; + QPinchGesture::ChangeFlags changeFlags; QPointF startCenterPoint; QPointF lastCenterPoint; diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index e4a1eb4630..d2939f0363 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -67,6 +67,15 @@ QT_BEGIN_NAMESPACE +QGestureManager *qt_gestureManager = 0; + +QGestureManager* QGestureManager::instance() +{ + if (!qt_gestureManager) + qt_gestureManager = new QGestureManager(qApp); + return qt_gestureManager; +} + QGestureManager::QGestureManager(QObject *parent) : QObject(parent), state(NotGesture), m_lastCustomGestureId(0) { @@ -99,7 +108,7 @@ QGestureManager::~QGestureManager() Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) { - QGesture *dummy = recognizer->createGesture(0); + QGesture *dummy = recognizer->create(0); if (!dummy) { qWarning("QGestureManager::registerGestureRecognizer: " "the recognizer fails to create a gesture object, skipping registration."); @@ -179,7 +188,7 @@ QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recogni } Q_ASSERT(recognizer); - QGesture *state = recognizer->createGesture(object); + QGesture *state = recognizer->create(object); if (!state) return 0; state->setParent(this); @@ -226,18 +235,19 @@ bool QGestureManager::filterEventThroughContexts(const QMultiHashfilterEvent(state, target, event); + QGestureRecognizer::Result result = recognizer->recognize(state, target, event); QGestureRecognizer::Result type = result & QGestureRecognizer::ResultState_Mask; - if (type == QGestureRecognizer::GestureTriggered) { + result &= QGestureRecognizer::ResultHint_Mask; + if (type == QGestureRecognizer::TriggerGesture) { DEBUG() << "QGestureManager:Recognizer: gesture triggered: " << state; triggeredGestures << state; - } else if (type == QGestureRecognizer::GestureFinished) { + } else if (type == QGestureRecognizer::FinishGesture) { DEBUG() << "QGestureManager:Recognizer: gesture finished: " << state; finishedGestures << state; - } else if (type == QGestureRecognizer::MaybeGesture) { + } else if (type == QGestureRecognizer::MayBeGesture) { DEBUG() << "QGestureManager:Recognizer: maybe gesture: " << state; newMaybeGestures << state; - } else if (type == QGestureRecognizer::NotGesture) { + } else if (type == QGestureRecognizer::CancelGesture) { DEBUG() << "QGestureManager:Recognizer: not gesture: " << state; notGestures << state; } else if (type == QGestureRecognizer::Ignore) { @@ -434,7 +444,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) QSet types; QMultiHash contexts; QWidget *w = receiver; - typedef QMap::const_iterator ContextIterator; + typedef QMap::const_iterator ContextIterator; if (!w->d_func()->gestureContext.isEmpty()) { for(ContextIterator it = w->d_func()->gestureContext.begin(), e = w->d_func()->gestureContext.end(); it != e; ++it) { @@ -448,7 +458,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) { for (ContextIterator it = w->d_func()->gestureContext.begin(), e = w->d_func()->gestureContext.end(); it != e; ++it) { - if ((it.value() & Qt::GestureContext_Mask) == Qt::WidgetWithChildrenGesture) { + if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(w, it.key()); @@ -468,7 +478,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) QMultiHash contexts; QGraphicsObject *item = receiver; if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) { - typedef QMap::const_iterator ContextIterator; + typedef QMap::const_iterator ContextIterator; for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { types.insert(it.key()); @@ -479,10 +489,10 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) item = item->parentObject(); while (item) { - typedef QMap::const_iterator ContextIterator; + typedef QMap::const_iterator ContextIterator; for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.begin(), e = item->QGraphicsItem::d_func()->gestureContext.end(); it != e; ++it) { - if ((it.value() & Qt::GestureContext_Mask) == Qt::ItemWithChildrenGesture) { + if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { types.insert(it.key()); contexts.insertMulti(item, it.key()); @@ -521,12 +531,12 @@ void QGestureManager::getGestureTargets(const QSet &gestures, foreach (QWidget *widget, gestures.keys()) { QWidget *w = widget->parentWidget(); while (w) { - QMap::const_iterator it + QMap::const_iterator it = w->d_func()->gestureContext.find(type); if (it != w->d_func()->gestureContext.end()) { // i.e. 'w' listens to gesture 'type' - Qt::GestureContext context = it.value() & Qt::GestureContext_Mask; - if (context == Qt::WidgetWithChildrenGesture && w != widget) { + Qt::GestureFlags flags = it.value(); + if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) { // conflicting gesture! (*conflicts)[widget].append(gestures[widget]); break; @@ -620,7 +630,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, QApplication::sendEvent(receiver, &event); bool eventAccepted = event.isAccepted(); - foreach(QGesture *gesture, event.allGestures()) { + foreach(QGesture *gesture, event.gestures()) { if (eventAccepted || event.isAccepted(gesture)) { QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); @@ -646,7 +656,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, QGestureEvent event(it.value()); QApplication::sendEvent(it.key(), &event); bool eventAccepted = event.isAccepted(); - foreach (QGesture *gesture, event.allGestures()) { + foreach (QGesture *gesture, event.gestures()) { if (gesture->state() == Qt::GestureStarted && (eventAccepted || event.isAccepted(gesture))) { QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index d60aedc7e0..27cc8fc7e6 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -76,7 +76,6 @@ public: bool filterEvent(QGesture *receiver, QEvent *event); bool filterEvent(QGraphicsObject *receiver, QEvent *event); - // declared in qapplication.cpp static QGestureManager* instance(); void cleanupCachedGestures(QObject *target, Qt::GestureType type); @@ -141,6 +140,8 @@ private: void cancelGesturesForChildren(QGesture *originatingGesture); }; +extern QGestureManager *qt_gestureManager; + QT_END_NAMESPACE #endif // QGESTUREMANAGER_P_H diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp index 2673be35cb..ed0bdcca9f 100644 --- a/src/gui/kernel/qgesturerecognizer.cpp +++ b/src/gui/kernel/qgesturerecognizer.cpp @@ -42,6 +42,7 @@ #include "qgesturerecognizer.h" #include "private/qgesture_p.h" +#include "private/qgesturemanager_p.h" QT_BEGIN_NAMESPACE @@ -65,12 +66,12 @@ QT_BEGIN_NAMESPACE objects, and modifying the associated QGesture objects to include relevant information about the user's input. - Gestures are created when the framework calls createGesture() to handle user input + Gestures are created when the framework calls create() to handle user input for a particular instance of a QWidget or QGraphicsObject subclass. A QGesture object is created for each widget or item that is configured to use gestures. Once a QGesture has been created for a target object, the gesture recognizer will - receive events for it in its filterEvent() handler function. + receive events for it in its recognize() handler function. When a gesture is canceled, the reset() function is called, giving the recognizer the chance to update the appropriate properties in the corresponding QGesture object. @@ -79,20 +80,22 @@ QT_BEGIN_NAMESPACE To add support for new gestures, you need to derive from QGestureRecognizer to create a custom recognizer class, construct an instance of this class, and register it with - the application by calling QApplication::registerGestureRecognizer(). You can also + the application by calling QGestureRecognizer::registerRecognizer(). You can also subclass QGesture to create a custom gesture class, or rely on dynamic properties to express specific details of the gesture you want to handle. - Your custom QGestureRecognizer subclass needs to reimplement the filterEvent() function - to handle and filter the incoming input events for QWidget and QGraphicsObject subclasses. - Although the logic for gesture recognition is implemented in this function, you can - store persistent information about the state of the recognition process in the QGesture - object supplied. The filterEvent() function must return a value of Qt::GestureState that - indicates the state of recognition for a given gesture and target object. This determines - whether or not a gesture event will be delivered to a target object. + Your custom QGestureRecognizer subclass needs to reimplement the recognize() + function to handle and filter the incoming input events for QWidget and + QGraphicsObject subclasses. Although the logic for gesture recognition is + implemented in this function, you can store persistent information about the + state of the recognition process in the QGesture object supplied. The + recognize() function must return a value of QGestureRecognizer::Result that + indicates the state of recognition for a given gesture and target object. + This determines whether or not a gesture event will be delivered to a target + object. If you choose to represent a gesture by a custom QGesture subclass, you will need to - reimplement the createGesture() function to construct instances of your gesture class. + reimplement the create() function to construct instances of your gesture class. Similarly, you may need to reimplement the reset() function if your custom gesture objects need to be specially handled when a gesture is canceled. @@ -105,37 +108,37 @@ QT_BEGIN_NAMESPACE This enum describes the result of the current event filtering step in a gesture recognizer state machine. - The result consists of a state value (one of Ignore, NotGesture, - MaybeGesture, GestureTriggered, GestureFinished) and an optional hint + The result consists of a state value (one of Ignore, MayBeGesture, + TriggerGesture, FinishGesture, CancelGesture) and an optional hint (ConsumeEventHint). \value Ignore The event does not change the state of the recognizer. - \value NotGesture The event made it clear that it is not a gesture. If the - gesture recognizer was in GestureTriggered state before, then the gesture - is canceled and the appropriate QGesture object will be delivered to the - target as a part of a QGestureEvent. - - \value MaybeGesture The event changed the internal state of the recognizer, + \value MayBeGesture The event changed the internal state of the recognizer, but it isn't clear yet if it is a gesture or not. The recognizer needs to - filter more events to decide. Gesture recognizers in the MaybeGesture state + filter more events to decide. Gesture recognizers in the MayBeGesture state may be reset automatically if they take too long to recognize gestures. - \value GestureTriggered The gesture has been triggered and the appropriate + \value TriggerGesture The gesture has been triggered and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent. - \value GestureFinished The gesture has been finished successfully and the + \value FinishGesture The gesture has been finished successfully and the appropriate QGesture object will be delivered to the target as a part of a QGestureEvent. - \value ConsumeEventHint This hint specifies that the gesture framework should - consume the filtered event and not deliver it to the receiver. + \value CancelGesture The event made it clear that it is not a gesture. If + the gesture recognizer was in GestureTriggered state before, then the + gesture is canceled and the appropriate QGesture object will be delivered + to the target as a part of a QGestureEvent. + + \value ConsumeEventHint This hint specifies that the gesture framework + should consume the filtered event and not deliver it to the receiver. \omitvalue ResultState_Mask \omitvalue ResultHint_Mask - \sa QGestureRecognizer::filterEvent() + \sa QGestureRecognizer::recognize() */ /*! @@ -159,7 +162,7 @@ QGestureRecognizer::~QGestureRecognizer() Reimplement this function to create a custom QGesture-derived gesture object if necessary. */ -QGesture *QGestureRecognizer::createGesture(QObject *target) +QGesture *QGestureRecognizer::create(QObject *target) { Q_UNUSED(target); return new QGesture; @@ -183,7 +186,7 @@ void QGestureRecognizer::reset(QGesture *gesture) } /*! - \fn QGestureRecognizer::filterEvent(QGesture *gesture, QObject *watched, QEvent *event) + \fn QGestureRecognizer::recognize(QGesture *gesture, QObject *watched, QEvent *event) Handles the given \a event for the \a watched object, updating the state of the \a gesture object as required, and returns a suitable result for the current recognition step. @@ -194,7 +197,34 @@ void QGestureRecognizer::reset(QGesture *gesture) The result reflects how much of the gesture has been recognized. The state of the \a gesture object is set depending on the result. - \sa Qt::GestureState + \sa QGestureRecognizer::Result +*/ + +/*! + Registers the given \a recognizer in the gesture framework and returns a gesture ID + for it. + + The application takes ownership of the \a recognizer and returns the gesture type + ID associated with it. For gesture recognizers which handle custom QGesture + objects (i.e., those which return Qt::CustomGesture in a QGesture::gestureType() + function) the return value is a generated gesture ID with the Qt::CustomGesture + flag set. + + \sa unregisterRecognizer(), QGestureRecognizer::create(), QGesture */ +Qt::GestureType QGestureRecognizer::registerRecognizer(QGestureRecognizer *recognizer) +{ + return QGestureManager::instance()->registerGestureRecognizer(recognizer); +} + +/*! + Unregisters all gesture recognizers of the specified \a type. + + \sa registerRecognizer() +*/ +void QGestureRecognizer::unregisterRecognizer(Qt::GestureType type) +{ + QGestureManager::instance()->unregisterGestureRecognizer(type); +} QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesturerecognizer.h b/src/gui/kernel/qgesturerecognizer.h index a3c990db8b..4eebf7cf3f 100644 --- a/src/gui/kernel/qgesturerecognizer.h +++ b/src/gui/kernel/qgesturerecognizer.h @@ -43,6 +43,7 @@ #define QGESTURERECOGNIZER_H #include +#include QT_BEGIN_HEADER @@ -58,30 +59,34 @@ class Q_GUI_EXPORT QGestureRecognizer public: enum ResultFlag { - Ignore = 0x0001, - NotGesture = 0x0002, - MaybeGesture = 0x0004, - GestureTriggered = 0x0008, // Gesture started or updated - GestureFinished = 0x0010, + Ignore = 0x0001, - ResultState_Mask = 0x00ff, + MayBeGesture = 0x0002, + TriggerGesture = 0x0004, + FinishGesture = 0x0008, + CancelGesture = 0x0010, + + ResultState_Mask = 0x00ff, ConsumeEventHint = 0x0100, // StoreEventHint = 0x0200, // ReplayStoredEventsHint = 0x0400, // DiscardStoredEventsHint = 0x0800, - ResultHint_Mask = 0xff00 + ResultHint_Mask = 0xff00 }; Q_DECLARE_FLAGS(Result, ResultFlag) QGestureRecognizer(); virtual ~QGestureRecognizer(); - virtual QGesture *createGesture(QObject *target); - virtual QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event) = 0; - + virtual QGesture *create(QObject *target); + virtual Result recognize(QGesture *state, QObject *watched, + QEvent *event) = 0; virtual void reset(QGesture *state); + + static Qt::GestureType registerRecognizer(QGestureRecognizer *recognizer); + static void unregisterRecognizer(Qt::GestureType type); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QGestureRecognizer::Result) diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 57cf12d966..ba00a9068a 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -52,7 +52,7 @@ QPanGestureRecognizer::QPanGestureRecognizer() { } -QGesture *QPanGestureRecognizer::createGesture(QObject *target) +QGesture *QPanGestureRecognizer::create(QObject *target) { if (target && target->isWidgetType()) { #if defined(Q_OS_WIN) @@ -66,21 +66,21 @@ QGesture *QPanGestureRecognizer::createGesture(QObject *target) return new QPanGesture; } -QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { - QPanGesture *q = static_cast(state); + QPanGesture *q = static_cast(state); QPanGesturePrivate *d = q->d_func(); - const QTouchEvent *ev = static_cast(event); + const QTouchEvent *ev = static_cast(event); QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; QTouchEvent::TouchPoint p = ev->touchPoints().at(0); d->lastPosition = p.pos().toPoint(); - d->lastOffset = d->totalOffset = d->offset = QPointF(); + d->lastOffset = d->offset = QPointF(); break; } case QEvent::TouchEnd: { @@ -90,13 +90,12 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); d->lastOffset = d->offset; d->offset = - QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), - p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; - d->totalOffset += d->offset; + QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), + p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; } - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; } else { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } break; } @@ -106,14 +105,13 @@ QGestureRecognizer::Result QPanGestureRecognizer::filterEvent(QGesture *state, Q QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); d->lastOffset = d->offset; d->offset = - QPointF(p1.pos().x() - p1.lastPos().x() + p2.pos().x() - p2.lastPos().x(), - p1.pos().y() - p1.lastPos().y() + p2.pos().y() - p2.lastPos().y()) / 2; - d->totalOffset += d->offset; - if (d->totalOffset.x() > 10 || d->totalOffset.y() > 10 || - d->totalOffset.x() < -10 || d->totalOffset.y() < -10) { - result = QGestureRecognizer::GestureTriggered; + QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), + p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; + if (d->offset.x() > 10 || d->offset.y() > 10 || + d->offset.x() < -10 || d->offset.y() < -10) { + result = QGestureRecognizer::TriggerGesture; } else { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; } } break; @@ -135,7 +133,7 @@ void QPanGestureRecognizer::reset(QGesture *state) QPanGesture *pan = static_cast(state); QPanGesturePrivate *d = pan->d_func(); - d->totalOffset = d->lastOffset = d->offset = QPointF(); + d->lastOffset = d->offset = QPointF(); d->lastPosition = QPoint(); d->acceleration = 0; @@ -151,7 +149,7 @@ QPinchGestureRecognizer::QPinchGestureRecognizer() { } -QGesture *QPinchGestureRecognizer::createGesture(QObject *target) +QGesture *QPinchGestureRecognizer::create(QObject *target) { if (target && target->isWidgetType()) { static_cast(target)->setAttribute(Qt::WA_AcceptTouchEvents); @@ -159,7 +157,7 @@ QGesture *QPinchGestureRecognizer::createGesture(QObject *target) return new QPinchGesture; } -QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QPinchGesture *q = static_cast(state); QPinchGesturePrivate *d = q->d_func(); @@ -170,19 +168,19 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, switch (event->type()) { case QEvent::TouchBegin: { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; break; } case QEvent::TouchEnd: { if (q->state() != Qt::NoGesture) { - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; } else { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } break; } case QEvent::TouchUpdate: { - d->whatChanged = 0; + d->changeFlags = 0; if (ev->touchPoints().size() == 2) { QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); @@ -201,7 +199,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, d->lastCenterPoint = d->centerPoint; d->centerPoint = centerPoint; - d->whatChanged |= QPinchGesture::CenterPointChanged; + d->changeFlags |= QPinchGesture::CenterPointChanged; const qreal scaleFactor = QLineF(p1.pos(), p2.pos()).length() / QLineF(d->startPosition[0], d->startPosition[1]).length(); @@ -212,7 +210,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, } d->scaleFactor = scaleFactor; d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor; - d->whatChanged |= QPinchGesture::ScaleFactorChanged; + d->changeFlags |= QPinchGesture::ScaleFactorChanged; const qreal rotationAngle = -line.angle(); if (d->isNewSequence) @@ -221,13 +219,14 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, d->lastRotationAngle = d->rotationAngle; d->rotationAngle = rotationAngle; d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle; - d->whatChanged |= QPinchGesture::RotationAngleChanged; + d->changeFlags |= QPinchGesture::RotationAngleChanged; + d->totalChangeFlags |= d->changeFlags; d->isNewSequence = false; - result = QGestureRecognizer::GestureTriggered; + result = QGestureRecognizer::TriggerGesture; } else { d->isNewSequence = true; - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; } break; } @@ -245,10 +244,10 @@ QGestureRecognizer::Result QPinchGestureRecognizer::filterEvent(QGesture *state, void QPinchGestureRecognizer::reset(QGesture *state) { - QPinchGesture *pinch = static_cast(state); + QPinchGesture *pinch = static_cast(state); QPinchGesturePrivate *d = pinch->d_func(); - d->whatChanged = 0; + d->totalChangeFlags = d->changeFlags = 0; d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF(); d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0; diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index 827b2a2615..e6f346c830 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -63,9 +63,8 @@ class QPanGestureRecognizer : public QGestureRecognizer public: QPanGestureRecognizer(); - QGesture *createGesture(QObject *target); - - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; @@ -74,9 +73,9 @@ class QPinchGestureRecognizer : public QGestureRecognizer public: QPinchGestureRecognizer(); - QGesture *createGesture(QObject *target); + QGesture *create(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 00d9a990a2..25284e4bd5 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -11711,20 +11711,20 @@ QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const */ /*! - Subscribes the widget to a given \a gesture with a \a context. + Subscribes the widget to a given \a gesture with specific \a flags. \sa ungrabGesture(), QGestureEvent \since 4.6 */ -void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) +void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) { Q_D(QWidget); - d->gestureContext.insert(gesture, context); + d->gestureContext.insert(gesture, flags); (void)QGestureManager::instance(); // create a gesture manager } /*! - Unsubscribes the widget to a given \a gesture type + Unsubscribes the widget from a given \a gesture type \sa grabGesture(), QGestureEvent \since 4.6 diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index fce3f09753..05f0069e07 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -354,7 +354,7 @@ public: QGraphicsEffect *graphicsEffect() const; void setGraphicsEffect(QGraphicsEffect *effect); - void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::WidgetWithChildrenGesture); + void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags()); void ungrabGesture(Qt::GestureType type); public Q_SLOTS: diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 616a972a6e..dd859a752c 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -631,7 +631,7 @@ public: #ifndef QT_NO_ACTION QList actions; #endif - QMap gestureContext; + QMap gestureContext; // Bit fields. uint high_attributes[3]; // the low ones are in QWidget::widget_attributes diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp index 0e5ee46132..44feaaf12d 100644 --- a/src/gui/widgets/qplaintextedit.cpp +++ b/src/gui/widgets/qplaintextedit.cpp @@ -1458,15 +1458,15 @@ bool QPlainTextEdit::event(QEvent *e) QScrollBar *vBar = verticalScrollBar(); if (g->state() == Qt::GestureStarted) d->originalOffsetY = vBar->value(); - QPointF totalOffset = g->totalOffset(); - if (!totalOffset.isNull()) { + QPointF offset = g->offset(); + if (!offset.isNull()) { if (QApplication::isRightToLeft()) - totalOffset.rx() *= -1; + offset.rx() *= -1; // QPlainTextEdit scrolls by lines only in vertical direction QFontMetrics fm(document()->defaultFont()); int lineHeight = fm.height(); int newX = hBar->value() - g->lastOffset().x(); - int newY = d->originalOffsetY - totalOffset.y()/lineHeight; + int newY = d->originalOffsetY - offset.y()/lineHeight; hBar->setValue(newX); vBar->setValue(newY); } diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 9b2bc577fe..20b53f2d34 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -111,12 +111,12 @@ public: CustomEvent::EventType = QEvent::registerEventType(); } - QGesture* createGesture(QObject *) + QGesture* create(QObject *) { return new CustomGesture; } - QGestureRecognizer::Result filterEvent(QGesture *state, QObject*o , QEvent *event) + QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) { if (event->type() == CustomEvent::EventType) { QGestureRecognizer::Result result = 0; @@ -128,13 +128,13 @@ public: if (e->hasHotSpot) g->setHotSpot(e->hotSpot); if (g->serial >= CustomGesture::SerialFinishedThreshold) - result |= QGestureRecognizer::GestureFinished; + result |= QGestureRecognizer::FinishGesture; else if (g->serial >= CustomGesture::SerialStartedThreshold) - result |= QGestureRecognizer::GestureTriggered; + result |= QGestureRecognizer::TriggerGesture; else if (g->serial >= CustomGesture::SerialMaybeThreshold) - result |= QGestureRecognizer::MaybeGesture; + result |= QGestureRecognizer::MayBeGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; return result; } return QGestureRecognizer::Ignore; @@ -142,7 +142,7 @@ public: void reset(QGesture *state) { - CustomGesture *g = static_cast(state); + CustomGesture *g = static_cast(state); g->serial = 0; QGestureRecognizer::reset(state); } @@ -159,26 +159,26 @@ public: CustomEvent::EventType = QEvent::registerEventType(); } - QGesture* createGesture(QObject *) + QGesture* create(QObject *) { return new CustomGesture; } - QGestureRecognizer::Result filterEvent(QGesture *state, QObject*, QEvent *event) + QGestureRecognizer::Result recognize(QGesture *state, QObject*, QEvent *event) { if (event->type() == CustomEvent::EventType) { QGestureRecognizer::Result result = QGestureRecognizer::ConsumeEventHint; - CustomGesture *g = static_cast(state); - CustomEvent *e = static_cast(event); + CustomGesture *g = static_cast(state); + CustomEvent *e = static_cast(event); g->serial = e->serial; if (e->hasHotSpot) g->setHotSpot(e->hotSpot); if (g->serial >= CustomGesture::SerialFinishedThreshold) - result |= QGestureRecognizer::GestureFinished; + result |= QGestureRecognizer::FinishGesture; else if (g->serial >= CustomGesture::SerialMaybeThreshold) - result |= QGestureRecognizer::GestureTriggered; + result |= QGestureRecognizer::TriggerGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; return result; } return QGestureRecognizer::Ignore; @@ -186,7 +186,7 @@ public: void reset(QGesture *state) { - CustomGesture *g = static_cast(state); + CustomGesture *g = static_cast(state); g->serial = 0; QGestureRecognizer::reset(state); } @@ -256,7 +256,7 @@ protected: } if (eventsPtr) { QGestureEvent *e = static_cast(event); - QList gestures = e->allGestures(); + QList gestures = e->gestures(); foreach(QGesture *g, gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { @@ -345,14 +345,14 @@ tst_Gestures::~tst_Gestures() void tst_Gestures::initTestCase() { - CustomGesture::GestureType = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + CustomGesture::GestureType = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); QVERIFY(CustomGesture::GestureType != Qt::GestureType(0)); QVERIFY(CustomGesture::GestureType != Qt::CustomGesture); } void tst_Gestures::cleanupTestCase() { - QApplication::unregisterGestureRecognizer(CustomGesture::GestureType); + QGestureRecognizer::unregisterRecognizer(CustomGesture::GestureType); } void tst_Gestures::init() @@ -366,7 +366,7 @@ void tst_Gestures::cleanup() void tst_Gestures::customGesture() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, &widget); @@ -387,7 +387,7 @@ void tst_Gestures::customGesture() void tst_Gestures::consumeEventHint() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomGestureRecognizer::ConsumeEvents = true; CustomEvent event; @@ -400,7 +400,7 @@ void tst_Gestures::consumeEventHint() void tst_Gestures::autoCancelingGestures() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); // send partial gesture. The gesture will be in the "maybe" state, but will // never get enough events to fire, so Qt will have to kill it. CustomEvent ev; @@ -424,7 +424,7 @@ void tst_Gestures::gestureOverChild() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, child); @@ -440,7 +440,7 @@ void tst_Gestures::gestureOverChild() QCOMPARE(widget.gestureOverrideEventsReceived, 0); // enable gestures over the children - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + widget.grabGesture(CustomGesture::GestureType); widget.reset(); child->reset(); @@ -469,8 +469,8 @@ void tst_Gestures::multipleWidgetOnlyGestureInTree() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - child->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + parent.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + child->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; @@ -507,8 +507,8 @@ void tst_Gestures::conflictingGestures() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -579,7 +579,7 @@ void tst_Gestures::conflictingGestures() child->reset(); // we set an attribute to make sure all gesture events are propagated - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + parent.grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); parent.acceptGestureOverride = false; child->acceptGestureOverride = false; parent.ignoredGestures << CustomGesture::GestureType; @@ -596,7 +596,7 @@ void tst_Gestures::conflictingGestures() parent.reset(); child->reset(); - Qt::GestureType ContinuousGesture = QApplication::registerGestureRecognizer(new CustomContinuousGestureRecognizer); + Qt::GestureType ContinuousGesture = QGestureRecognizer::registerRecognizer(new CustomContinuousGestureRecognizer); static const int ContinuousGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1; child->grabGesture(ContinuousGesture); // child accepts override. And it also receives another custom gesture. @@ -610,13 +610,13 @@ void tst_Gestures::conflictingGestures() QCOMPARE(parent.gestureOverrideEventsReceived, 0); QCOMPARE(parent.gestureEventsReceived, 0); - QApplication::unregisterGestureRecognizer(ContinuousGesture); + QGestureRecognizer::unregisterRecognizer(ContinuousGesture); } void tst_Gestures::finishedWithoutStarted() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); // the gesture will claim it finished, but it was never started. CustomEvent ev; @@ -636,9 +636,9 @@ void tst_Gestures::finishedWithoutStarted() void tst_Gestures::unknownGesture() { GestureWidget widget; - widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - widget.grabGesture(Qt::CustomGesture, Qt::WidgetGesture); - widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::WidgetGesture); + widget.grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + widget.grabGesture(Qt::CustomGesture, Qt::DontStartGestureOnChildren); + widget.grabGesture(Qt::GestureType(Qt::PanGesture+512), Qt::DontStartGestureOnChildren); CustomEvent event; sendCustomGesture(&event, &widget); @@ -740,7 +740,7 @@ protected: } if (eventsPtr) { QGestureEvent *e = static_cast(event); - QList gestures = e->allGestures(); + QList gestures = e->gestures(); foreach(QGesture *g, gestures) { eventsPtr->all << g->gestureType(); switch(g->state()) { @@ -784,7 +784,7 @@ void tst_Gestures::graphicsItemGesture() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -858,7 +858,7 @@ void tst_Gestures::graphicsItemTreeGesture() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item1->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -916,10 +916,10 @@ void tst_Gestures::explicitGraphicsObjectTarget() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - item1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); - item2->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); - item2_child1->grabGesture(CustomGesture::GestureType, Qt::ItemGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item2->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + item2_child1->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -976,7 +976,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() QTest::qWaitForWindowShown(&view); view.ensureVisible(scene.sceneRect()); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); item1->grabGesture(CustomGesture::GestureType); static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1; @@ -1030,7 +1030,7 @@ void tst_Gestures::gestureOverChildGraphicsItem() item2->grabGesture(CustomGesture::GestureType); item2->ignoredGestures << CustomGesture::GestureType; item1->ignoredGestures << CustomGesture::GestureType; - item1->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint); + item1->grabGesture(CustomGesture::GestureType, Qt::ReceivePartialGestures); event.hotSpot = mapToGlobal(QPointF(10, 10), item2_child1, &view); event.hasHotSpot = true; @@ -1051,10 +1051,10 @@ void tst_Gestures::twoGesturesOnDifferentLevel() GestureWidget *child = new GestureWidget("child"); l->addWidget(child); - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(SecondGesture, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(SecondGesture); CustomEvent event; // sending events that form a gesture to one widget, but they will be @@ -1079,7 +1079,7 @@ void tst_Gestures::twoGesturesOnDifferentLevel() for(int i = 0; i < child->events.all.size(); ++i) QCOMPARE(parent.events.all.at(i), CustomGesture::GestureType); - QApplication::unregisterGestureRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); } void tst_Gestures::multipleGesturesInTree() @@ -1091,19 +1091,19 @@ void tst_Gestures::multipleGesturesInTree() GestureWidget *D = new GestureWidget("D", C); Qt::GestureType FirstGesture = CustomGesture::GestureType; - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - - Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; - A->grabGesture(FirstGesture, context); // A [1 3] - A->grabGesture(ThirdGesture, context); // | - B->grabGesture(SecondGesture, context); // B [ 2 3] - B->grabGesture(ThirdGesture, context); // | - C->grabGesture(FirstGesture, context); // C [1 2 3] - C->grabGesture(SecondGesture, context); // | - C->grabGesture(ThirdGesture, context); // D [1 3] - D->grabGesture(FirstGesture, context); - D->grabGesture(ThirdGesture, context); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + + Qt::GestureFlags flags = Qt::ReceivePartialGestures; + A->grabGesture(FirstGesture, flags); // A [1 3] + A->grabGesture(ThirdGesture, flags); // | + B->grabGesture(SecondGesture, flags); // B [ 2 3] + B->grabGesture(ThirdGesture, flags); // | + C->grabGesture(FirstGesture, flags); // C [1 2 3] + C->grabGesture(SecondGesture, flags); // | + C->grabGesture(ThirdGesture, flags); // D [1 3] + D->grabGesture(FirstGesture, flags); + D->grabGesture(ThirdGesture, flags); // make sure all widgets ignore events, so they get propagated. A->ignoredGestures << FirstGesture << ThirdGesture; @@ -1150,8 +1150,8 @@ void tst_Gestures::multipleGesturesInTree() QCOMPARE(A->events.all.count(SecondGesture), 0); QCOMPARE(A->events.all.count(ThirdGesture), TotalGestureEventsCount); - QApplication::unregisterGestureRecognizer(SecondGesture); - QApplication::unregisterGestureRecognizer(ThirdGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); } void tst_Gestures::multipleGesturesInComplexTree() @@ -1163,27 +1163,27 @@ void tst_Gestures::multipleGesturesInComplexTree() GestureWidget *D = new GestureWidget("D", C); Qt::GestureType FirstGesture = CustomGesture::GestureType; - Qt::GestureType SecondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType ThirdGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType FourthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType FifthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType SixthGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - Qt::GestureType SeventhGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); - - Qt::GestureContext context = Qt::WidgetWithChildrenGesture | Qt::AcceptPartialGesturesHint; - A->grabGesture(FirstGesture, context); // A [1,3,4] - A->grabGesture(ThirdGesture, context); // | - A->grabGesture(FourthGesture, context); // B [2,3,5] - B->grabGesture(SecondGesture, context); // | - B->grabGesture(ThirdGesture, context); // C [1,2,3,6] - B->grabGesture(FifthGesture, context); // | - C->grabGesture(FirstGesture, context); // D [1,3,7] - C->grabGesture(SecondGesture, context); - C->grabGesture(ThirdGesture, context); - C->grabGesture(SixthGesture, context); - D->grabGesture(FirstGesture, context); - D->grabGesture(ThirdGesture, context); - D->grabGesture(SeventhGesture, context); + Qt::GestureType SecondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType ThirdGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType FourthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType FifthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType SixthGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + Qt::GestureType SeventhGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); + + Qt::GestureFlags flags = Qt::ReceivePartialGestures; + A->grabGesture(FirstGesture, flags); // A [1,3,4] + A->grabGesture(ThirdGesture, flags); // | + A->grabGesture(FourthGesture, flags); // B [2,3,5] + B->grabGesture(SecondGesture, flags); // | + B->grabGesture(ThirdGesture, flags); // C [1,2,3,6] + B->grabGesture(FifthGesture, flags); // | + C->grabGesture(FirstGesture, flags); // D [1,3,7] + C->grabGesture(SecondGesture, flags); + C->grabGesture(ThirdGesture, flags); + C->grabGesture(SixthGesture, flags); + D->grabGesture(FirstGesture, flags); + D->grabGesture(ThirdGesture, flags); + D->grabGesture(SeventhGesture, flags); // make sure all widgets ignore events, so they get propagated. QSet allGestureTypes; @@ -1247,12 +1247,12 @@ void tst_Gestures::multipleGesturesInComplexTree() QCOMPARE(A->events.all.count(SixthGesture), 0); QCOMPARE(A->events.all.count(SeventhGesture), 0); - QApplication::unregisterGestureRecognizer(SecondGesture); - QApplication::unregisterGestureRecognizer(ThirdGesture); - QApplication::unregisterGestureRecognizer(FourthGesture); - QApplication::unregisterGestureRecognizer(FifthGesture); - QApplication::unregisterGestureRecognizer(SixthGesture); - QApplication::unregisterGestureRecognizer(SeventhGesture); + QGestureRecognizer::unregisterRecognizer(SecondGesture); + QGestureRecognizer::unregisterRecognizer(ThirdGesture); + QGestureRecognizer::unregisterRecognizer(FourthGesture); + QGestureRecognizer::unregisterRecognizer(FifthGesture); + QGestureRecognizer::unregisterRecognizer(SixthGesture); + QGestureRecognizer::unregisterRecognizer(SeventhGesture); } void tst_Gestures::testMapToScene() @@ -1261,7 +1261,7 @@ void tst_Gestures::testMapToScene() QList list; list << &gesture; QGestureEvent event(list); - QCOMPARE(event.mapToScene(gesture.hotSpot()), QPointF()); // not set, can't do much + QCOMPARE(event.mapToGraphicsScene(gesture.hotSpot()), QPointF()); // not set, can't do much QGraphicsScene scene; QGraphicsView view(&scene); @@ -1278,7 +1278,7 @@ void tst_Gestures::testMapToScene() QPoint origin = view.mapToGlobal(QPoint()); event.setWidget(view.viewport()); - QCOMPARE(event.mapToScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200))); + QCOMPARE(event.mapToGraphicsScene(origin + QPoint(100, 200)), view.mapToScene(QPoint(100, 200))); } void tst_Gestures::ungrabGesture() // a method on QWidget @@ -1296,7 +1296,7 @@ void tst_Gestures::ungrabGesture() // a method on QWidget if (event->type() == QEvent::Gesture) { QGestureEvent *gestureEvent = static_cast(event); if (gestureEvent) - foreach (QGesture *g, gestureEvent->allGestures()) + foreach (QGesture *g, gestureEvent->gestures()) gestures.insert(g); } return GestureWidget::event(event); @@ -1307,8 +1307,8 @@ void tst_Gestures::ungrabGesture() // a method on QWidget MockGestureWidget *a = &parent; MockGestureWidget *b = new MockGestureWidget("B", a); - a->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - b->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); + a->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + b->grabGesture(CustomGesture::GestureType); b->ignoredGestures << CustomGesture::GestureType; CustomEvent event; @@ -1375,14 +1375,14 @@ void tst_Gestures::autoCancelGestures() { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast(event); - Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here... - ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); + Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... + ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } return GestureWidget::event(event); } }; - const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); MockWidget parent("parent"); // this one sets the cancel policy to CancelAllInContext parent.resize(300, 100); @@ -1390,8 +1390,8 @@ void tst_Gestures::autoCancelGestures() GestureWidget *child = new GestureWidget("child", &parent); child->setGeometry(10, 10, 100, 80); - parent.grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + parent.grabGesture(CustomGesture::GestureType); + child->grabGesture(secondGesture); parent.show(); QTest::qWaitForWindowShown(&parent); @@ -1425,14 +1425,14 @@ void tst_Gestures::autoCancelGestures2() bool event(QEvent *event) { if (event->type() == QEvent::Gesture) { QGestureEvent *ge = static_cast(event); - Q_ASSERT(ge->allGestures().count() == 1); // can't use QCOMPARE here... - ge->allGestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); + Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... + ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); } return GestureItem::event(event); } }; - const Qt::GestureType secondGesture = QApplication::registerGestureRecognizer(new CustomGestureRecognizer); + const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); QGraphicsScene scene; QGraphicsView view(&scene); @@ -1444,10 +1444,10 @@ void tst_Gestures::autoCancelGestures2() parent->setPos(0, 0); child->setPos(10, 10); scene.addItem(parent); - view.viewport()->grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); - view.viewport()->grabGesture(secondGesture, Qt::WidgetGesture); - parent->grabGesture(CustomGesture::GestureType, Qt::WidgetWithChildrenGesture); - child->grabGesture(secondGesture, Qt::WidgetWithChildrenGesture); + view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren); + view.viewport()->grabGesture(secondGesture, Qt::DontStartGestureOnChildren); + parent->grabGesture(CustomGesture::GestureType); + child->grabGesture(secondGesture); view.show(); QTest::qWaitForWindowShown(&view); diff --git a/tests/manual/gestures/graphicsview/gestures.cpp b/tests/manual/gestures/graphicsview/gestures.cpp index 5416457d19..4c21712a28 100644 --- a/tests/manual/gestures/graphicsview/gestures.cpp +++ b/tests/manual/gestures/graphicsview/gestures.cpp @@ -45,41 +45,41 @@ Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture; -QGesture *ThreeFingerSlideGestureRecognizer::createGesture(QObject *) +QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *) { return new ThreeFingerSlideGesture; } -QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { ThreeFingerSlideGesture *d = static_cast(state); QGestureRecognizer::Result result; switch (event->type()) { case QEvent::TouchBegin: - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; case QEvent::TouchEnd: if (d->gestureFired) - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; case QEvent::TouchUpdate: if (d->state() != Qt::NoGesture) { QTouchEvent *ev = static_cast(event); if (ev->touchPoints().size() == 3) { d->gestureFired = true; - result = QGestureRecognizer::GestureTriggered; + result = QGestureRecognizer::TriggerGesture; } else { - result = QGestureRecognizer::MaybeGesture; + result = QGestureRecognizer::MayBeGesture; for (int i = 0; i < ev->touchPoints().size(); ++i) { const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i); const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength(); if (distance > 20) { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } } } } else { - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; } break; @@ -89,7 +89,7 @@ QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGestu if (d->state() != Qt::NoGesture) result = QGestureRecognizer::Ignore; else - result = QGestureRecognizer::NotGesture; + result = QGestureRecognizer::CancelGesture; break; default: result = QGestureRecognizer::Ignore; @@ -105,12 +105,12 @@ void ThreeFingerSlideGestureRecognizer::reset(QGesture *state) } -QGesture *RotateGestureRecognizer::createGesture(QObject *) +QGesture *RotateGestureRecognizer::create(QObject *) { return new QGesture; } -QGestureRecognizer::Result RotateGestureRecognizer::filterEvent(QGesture *, QObject *, QEvent *event) +QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event) { switch (event->type()) { case QEvent::TouchBegin: diff --git a/tests/manual/gestures/graphicsview/gestures.h b/tests/manual/gestures/graphicsview/gestures.h index 6140b12d62..8a31b7117b 100644 --- a/tests/manual/gestures/graphicsview/gestures.h +++ b/tests/manual/gestures/graphicsview/gestures.h @@ -59,8 +59,8 @@ public: class ThreeFingerSlideGestureRecognizer : public QGestureRecognizer { private: - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; @@ -70,8 +70,8 @@ public: RotateGestureRecognizer(); private: - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp index de92afe44e..f8433b59f3 100644 --- a/tests/manual/gestures/graphicsview/main.cpp +++ b/tests/manual/gestures/graphicsview/main.cpp @@ -66,11 +66,11 @@ protected: default: qDebug("view: Pan: "); break; } - const QPointF offset = pan->offset(); + const QPointF delta = pan->delta(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); - vbar->setValue(vbar->value() - offset.y()); - hbar->setValue(hbar->value() - offset.x()); + vbar->setValue(vbar->value() - delta.y()); + hbar->setValue(hbar->value() - delta.x()); ge->accept(pan); return true; } @@ -152,8 +152,8 @@ private: MainWindow::MainWindow() { - (void)QApplication::registerGestureRecognizer(new MousePanGestureRecognizer); - ThreeFingerSlideGesture::Type = QApplication::registerGestureRecognizer(new ThreeFingerSlideGestureRecognizer); + (void)QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer); + ThreeFingerSlideGesture::Type = QGestureRecognizer::registerRecognizer(new ThreeFingerSlideGestureRecognizer); tabWidget = new QTabWidget; diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp index 6cdbe12847..82adfbd97f 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp @@ -51,12 +51,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer() { } -QGesture* MousePanGestureRecognizer::createGesture(QObject *) +QGesture* MousePanGestureRecognizer::create(QObject *) { return new QPanGesture; } -QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast(state); QPoint globalPos; @@ -78,23 +78,19 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) { g->setHotSpot(globalPos); - g->setProperty("lastPos", globalPos); + g->setProperty("startPos", globalPos); g->setProperty("pressed", QVariant::fromValue(true)); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) { if (g->property("pressed").toBool()) { - QPoint pos = globalPos; - QPoint lastPos = g->property("lastPos").toPoint(); + QPoint offset = globalPos - g->property("startPos").toPoint(); g->setLastOffset(g->offset()); - lastPos = pos - lastPos; - g->setOffset(QPointF(lastPos.x(), lastPos.y())); - g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y())); - g->setProperty("lastPos", pos); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + g->setOffset(QPointF(offset.x(), offset.y())); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) { - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } return QGestureRecognizer::Ignore; } @@ -102,11 +98,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat void MousePanGestureRecognizer::reset(QGesture *state) { QPanGesture *g = static_cast(state); - g->setTotalOffset(QPointF()); g->setLastOffset(QPointF()); g->setOffset(QPointF()); g->setAcceleration(0); - g->setProperty("lastPos", QVariant()); + g->setProperty("startPos", QVariant()); g->setProperty("pressed", QVariant::fromValue(false)); QGestureRecognizer::reset(state); } diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h index b062fd0620..6e04621f29 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h @@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer public: MousePanGestureRecognizer(); - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture* create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp index 9a5eb02913..4f33b289e2 100644 --- a/tests/manual/gestures/scrollarea/main.cpp +++ b/tests/manual/gestures/scrollarea/main.cpp @@ -50,7 +50,7 @@ public: ScrollArea(QWidget *parent = 0) : QScrollArea(parent), outside(false) { - viewport()->grabGesture(Qt::PanGesture); + viewport()->grabGesture(Qt::PanGesture, Qt::ReceivePartialGestures); } protected: @@ -87,8 +87,8 @@ protected: if (outside) return; - const QPointF offset = pan->offset(); - const QPointF totalOffset = pan->totalOffset(); + const QPointF delta = pan->delta(); + const QPointF totalOffset = pan->offset(); QScrollBar *vbar = verticalScrollBar(); QScrollBar *hbar = horizontalScrollBar(); @@ -102,8 +102,8 @@ protected: outside = true; return; } - vbar->setValue(vbar->value() - offset.y()); - hbar->setValue(hbar->value() - offset.x()); + vbar->setValue(vbar->value() - delta.y()); + hbar->setValue(hbar->value() - delta.x()); event->accept(pan); } } @@ -147,8 +147,8 @@ protected: event->ignore(pan); if (outside) return; - const QPointF offset = pan->offset(); - const QPointF totalOffset = pan->totalOffset(); + const QPointF delta = pan->delta(); + const QPointF totalOffset = pan->offset(); if (orientation() == Qt::Horizontal) { if ((value() == minimum() && totalOffset.x() < -10) || (value() == maximum() && totalOffset.x() > 10)) { @@ -156,7 +156,7 @@ protected: return; } if (totalOffset.y() < 40 && totalOffset.y() > -40) { - setValue(value() + offset.x()); + setValue(value() + delta.x()); event->accept(pan); } else { outside = true; @@ -168,7 +168,7 @@ protected: return; } if (totalOffset.x() < 40 && totalOffset.x() > -40) { - setValue(value() - offset.y()); + setValue(value() - delta.y()); event->accept(pan); } else { outside = true; @@ -232,7 +232,7 @@ private: int main(int argc, char **argv) { QApplication app(argc, argv); - app.registerGestureRecognizer(new MousePanGestureRecognizer); + QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer); MainWindow w; w.show(); return app.exec(); diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp index ce5ef570c2..66fcf18023 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp @@ -49,12 +49,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer() { } -QGesture* MousePanGestureRecognizer::createGesture(QObject *) +QGesture *MousePanGestureRecognizer::create(QObject *) { return new QPanGesture; } -QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast(state); if (event->type() == QEvent::TouchBegin) { @@ -68,24 +68,20 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat if (g->property("ignoreMousePress").toBool()) return QGestureRecognizer::Ignore; g->setHotSpot(me->globalPos()); - g->setProperty("lastPos", me->globalPos()); + g->setProperty("startPos", me->globalPos()); g->setProperty("pressed", QVariant::fromValue(true)); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } else if (event->type() == QEvent::MouseMove) { if (g->property("pressed").toBool()) { - QPoint pos = me->globalPos(); - QPoint lastPos = g->property("lastPos").toPoint(); + QPoint offset = me->globalPos() - g->property("startPos").toPoint(); g->setLastOffset(g->offset()); - lastPos = pos - lastPos; - g->setOffset(QPointF(lastPos.x(), lastPos.y())); - g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y())); - g->setProperty("lastPos", pos); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + g->setOffset(QPointF(offset.x(), offset.y())); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } else if (event->type() == QEvent::MouseButtonRelease) { if (g->property("pressed").toBool()) - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; } return QGestureRecognizer::Ignore; } @@ -93,11 +89,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat void MousePanGestureRecognizer::reset(QGesture *state) { QPanGesture *g = static_cast(state); - g->setTotalOffset(QPointF()); g->setLastOffset(QPointF()); g->setOffset(QPointF()); g->setAcceleration(0); - g->setProperty("lastPos", QVariant()); + g->setProperty("startPos", QVariant()); g->setProperty("pressed", QVariant::fromValue(false)); g->setProperty("ignoreMousePress", QVariant::fromValue(false)); QGestureRecognizer::reset(state); diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h index b062fd0620..6e04621f29 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h @@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer public: MousePanGestureRecognizer(); - QGesture* createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture* create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; -- cgit v1.2.3 From c8a7b0430120b391e356a821390aaaebacbbb006 Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Tue, 3 Nov 2009 11:15:38 +0100 Subject: Toolbar Icons are clipped on Leopard in Cocoa port. Scale the pixmap to correct size (16,16) before setting as the image for the Document Icon button. Reviewed-by: Denis --- src/gui/kernel/qwidget_mac.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 79f55a101d..9270220d31 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -3026,7 +3026,8 @@ void QWidgetPrivate::setWindowIcon_sys(bool forceReset) if (icon.isNull()) { [iconButton setImage:nil]; } else { - NSImage *image = static_cast(qt_mac_create_nsimage(*pm)); + QPixmap scaled = pm->scaled(QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation); + NSImage *image = static_cast(qt_mac_create_nsimage(scaled)); [iconButton setImage:image]; [image release]; } -- cgit v1.2.3 From 14a1a9af8ae1b3d2379e6f8c24536afb20b39509 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 3 Nov 2009 11:16:39 +0100 Subject: Cocoa: fix q3filedialog autotest Q3FileDialog does not exist in the cocoa port. Do ifdef this test out on cocoa Rev-by: prasanth --- tests/auto/q3filedialog/tst_q3filedialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/auto/q3filedialog/tst_q3filedialog.cpp b/tests/auto/q3filedialog/tst_q3filedialog.cpp index 2585f60b71..e2686eb97d 100644 --- a/tests/auto/q3filedialog/tst_q3filedialog.cpp +++ b/tests/auto/q3filedialog/tst_q3filedialog.cpp @@ -59,7 +59,9 @@ public: virtual ~tst_Q3FileDialog(); private slots: +#ifndef QT_MAC_USE_COCOA void getSetCheck(); +#endif }; tst_Q3FileDialog::tst_Q3FileDialog() @@ -70,6 +72,7 @@ tst_Q3FileDialog::~tst_Q3FileDialog() { } +#ifndef QT_MAC_USE_COCOA class Preview : public QLabel, public Q3FilePreview { public: @@ -125,6 +128,7 @@ void tst_Q3FileDialog::getSetCheck() obj1.setPreviewMode(Q3FileDialog::PreviewMode(Q3FileDialog::Info)); QCOMPARE(obj1.previewMode(), Q3FileDialog::PreviewMode(Q3FileDialog::Info)); } +#endif QTEST_MAIN(tst_Q3FileDialog) #include "tst_q3filedialog.moc" -- cgit v1.2.3 From 51c9b68425c1d3fe64a08e6ef0357fbd6bdd8f8a Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Tue, 3 Nov 2009 12:55:19 +0100 Subject: Compile fix after the last gesture api change Reviewed-by: trustme --- examples/gestures/imagegestures/imagewidget.cpp | 6 +-- src/gui/kernel/qgesture_p.h | 2 +- src/gui/kernel/qmacgesturerecognizer_mac.mm | 57 ++++++++++------------ src/gui/kernel/qmacgesturerecognizer_mac_p.h | 13 +++-- src/gui/kernel/qstandardgestures.cpp | 2 - .../kernel/qwinnativepangesturerecognizer_win.cpp | 23 ++++----- .../kernel/qwinnativepangesturerecognizer_win_p.h | 5 +- 7 files changed, 50 insertions(+), 58 deletions(-) diff --git a/examples/gestures/imagegestures/imagewidget.cpp b/examples/gestures/imagegestures/imagewidget.cpp index da9daaeb15..f615129103 100644 --- a/examples/gestures/imagegestures/imagewidget.cpp +++ b/examples/gestures/imagegestures/imagewidget.cpp @@ -124,9 +124,9 @@ void ImageWidget::panTriggered(QPanGesture *gesture) setCursor(Qt::ArrowCursor); } #endif - QPointF lastOffset = gesture->offset(); - horizontalOffset += lastOffset.x(); - verticalOffset += lastOffset.y(); + QPointF delta = gesture->delta(); + horizontalOffset += delta.x(); + verticalOffset += delta.y(); update(); } diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index 96fd64d185..ae2e28715f 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -92,7 +92,7 @@ public: QPointF lastOffset; QPointF offset; - QPoint lastPosition; + QPoint startPosition; qreal acceleration; }; diff --git a/src/gui/kernel/qmacgesturerecognizer_mac.mm b/src/gui/kernel/qmacgesturerecognizer_mac.mm index 70195809a6..d842322a24 100644 --- a/src/gui/kernel/qmacgesturerecognizer_mac.mm +++ b/src/gui/kernel/qmacgesturerecognizer_mac.mm @@ -53,13 +53,13 @@ QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer() { } -QGesture *QMacSwipeGestureRecognizer::createGesture(QObject * /*target*/) +QGesture *QMacSwipeGestureRecognizer::create(QObject * /*target*/) { return new QSwipeGesture; } QGestureRecognizer::Result -QMacSwipeGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) +QMacSwipeGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) { if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { QNativeGestureEvent *ev = static_cast(event); @@ -67,7 +67,7 @@ QMacSwipeGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent case QNativeGestureEvent::Swipe: { QSwipeGesture *g = static_cast(gesture); g->setSwipeAngle(ev->angle); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; break; } default: break; @@ -90,13 +90,13 @@ QMacPinchGestureRecognizer::QMacPinchGestureRecognizer() { } -QGesture *QMacPinchGestureRecognizer::createGesture(QObject * /*target*/) +QGesture *QMacPinchGestureRecognizer::create(QObject * /*target*/) { return new QPinchGesture; } QGestureRecognizer::Result -QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent *event) +QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event) { if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) { QPinchGesture *g = static_cast(gesture); @@ -106,26 +106,26 @@ QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent reset(gesture); g->setStartCenterPoint(static_cast(obj)->mapFromGlobal(ev->position)); g->setCenterPoint(g->startCenterPoint()); - g->setWhatChanged(QPinchGesture::CenterPointChanged); - return QGestureRecognizer::MaybeGesture | QGestureRecognizer::ConsumeEventHint; + g->setChangeFlags(QPinchGesture::CenterPointChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint; case QNativeGestureEvent::Rotate: { g->setLastScaleFactor(g->scaleFactor()); g->setLastRotationAngle(g->rotationAngle()); g->setRotationAngle(g->rotationAngle() + ev->percentage); - g->setWhatChanged(QPinchGesture::RotationAngleChanged); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; - break; + g->setChangeFlags(QPinchGesture::RotationAngleChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } case QNativeGestureEvent::Zoom: g->setLastScaleFactor(g->scaleFactor()); g->setLastRotationAngle(g->rotationAngle()); g->setScaleFactor(g->scaleFactor() + ev->percentage); - g->setWhatChanged(QPinchGesture::ScaleFactorChanged); - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; - break; + g->setChangeFlags(QPinchGesture::ScaleFactorChanged); + g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags()); + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; case QNativeGestureEvent::GestureEnd: - return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint; - break; + return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; default: break; } @@ -137,7 +137,8 @@ QMacPinchGestureRecognizer::filterEvent(QGesture *gesture, QObject *obj, QEvent void QMacPinchGestureRecognizer::reset(QGesture *gesture) { QPinchGesture *g = static_cast(gesture); - g->setWhatChanged(0); + g->setChangeFlags(0); + g->setTotalChangeFlags(0); g->setScaleFactor(1.0f); g->setTotalScaleFactor(1.0f); g->setLastScaleFactor(1.0f); @@ -158,7 +159,7 @@ QMacPanGestureRecognizer::QMacPanGestureRecognizer() : _panCanceled(true) { } -QGesture *QMacPanGestureRecognizer::createGesture(QObject *target) +QGesture *QMacPanGestureRecognizer::create(QObject *target) { if (!target) return new QPanGesture; @@ -172,7 +173,7 @@ QGesture *QMacPanGestureRecognizer::createGesture(QObject *target) } QGestureRecognizer::Result -QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent *event) +QMacPanGestureRecognizer::recognize(QGesture *gesture, QObject *target, QEvent *event) { const int panBeginDelay = 300; const int panBeginRadius = 3; @@ -185,10 +186,9 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent if (ev->touchPoints().size() == 1) { reset(gesture); _startPos = QCursor::pos(); - _lastPos = _startPos; _panTimer.start(panBeginDelay, target); _panCanceled = false; - return QGestureRecognizer::MaybeGesture; + return QGestureRecognizer::MayBeGesture; } break;} case QEvent::TouchEnd: { @@ -197,7 +197,7 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent const QTouchEvent *ev = static_cast(event); if (ev->touchPoints().size() == 1) - return QGestureRecognizer::GestureFinished; + return QGestureRecognizer::FinishGesture; break;} case QEvent::TouchUpdate: { if (_panCanceled) @@ -212,23 +212,21 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent if ((p - _startPos).manhattanLength() > panBeginRadius) { _panCanceled = true; _panTimer.stop(); - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } } else { const QPointF p = QCursor::pos(); - const QPointF posOffset = p - _lastPos; + const QPointF posOffset = p - _startPos; g->setLastOffset(g->offset()); g->setOffset(QPointF(posOffset.x(), posOffset.y())); - g->setTotalOffset(g->lastOffset() + g->offset()); - _lastPos = p; - return QGestureRecognizer::GestureTriggered; + return QGestureRecognizer::TriggerGesture; } } else if (_panTimer.isActive()) { // I only want to cancel the pan if the user is pressing // more than one finger, and the pan hasn't started yet: _panCanceled = true; _panTimer.stop(); - return QGestureRecognizer::NotGesture; + return QGestureRecognizer::CancelGesture; } break;} case QEvent::Timer: { @@ -239,8 +237,7 @@ QMacPanGestureRecognizer::filterEvent(QGesture *gesture, QObject *target, QEvent break; // Begin new pan session! _startPos = QCursor::pos(); - _lastPos = _startPos; - return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } break; } default: @@ -254,11 +251,9 @@ void QMacPanGestureRecognizer::reset(QGesture *gesture) { QPanGesture *g = static_cast(gesture); _startPos = QPointF(); - _lastPos = QPointF(); _panCanceled = true; g->setOffset(QPointF(0, 0)); g->setLastOffset(QPointF(0, 0)); - g->setTotalOffset(QPointF(0, 0)); g->setAcceleration(qreal(1)); QGestureRecognizer::reset(gesture); } diff --git a/src/gui/kernel/qmacgesturerecognizer_mac_p.h b/src/gui/kernel/qmacgesturerecognizer_mac_p.h index bdc2e081a9..2dac56a833 100644 --- a/src/gui/kernel/qmacgesturerecognizer_mac_p.h +++ b/src/gui/kernel/qmacgesturerecognizer_mac_p.h @@ -64,8 +64,8 @@ class QMacSwipeGestureRecognizer : public QGestureRecognizer public: QMacSwipeGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); }; @@ -74,8 +74,8 @@ class QMacPinchGestureRecognizer : public QGestureRecognizer public: QMacPinchGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); }; @@ -86,12 +86,11 @@ class QMacPanGestureRecognizer : public QObject, public QGestureRecognizer public: QMacPanGestureRecognizer(); - QGesture *createGesture(QObject *target); - QGestureRecognizer::Result filterEvent(QGesture *gesture, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event); void reset(QGesture *gesture); private: QPointF _startPos; - QPointF _lastPos; QBasicTimer _panTimer; bool _panCanceled; }; diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index ba00a9068a..dfd49eb752 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -79,7 +79,6 @@ QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, QOb case QEvent::TouchBegin: { result = QGestureRecognizer::MayBeGesture; QTouchEvent::TouchPoint p = ev->touchPoints().at(0); - d->lastPosition = p.pos().toPoint(); d->lastOffset = d->offset = QPointF(); break; } @@ -134,7 +133,6 @@ void QPanGestureRecognizer::reset(QGesture *state) QPanGesturePrivate *d = pan->d_func(); d->lastOffset = d->offset = QPointF(); - d->lastPosition = QPoint(); d->acceleration = 0; QGestureRecognizer::reset(state); diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp index c3c8a28cf6..5fceb13161 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp @@ -56,7 +56,7 @@ QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer() { } -QGesture *QWinNativePanGestureRecognizer::createGesture(QObject *target) +QGesture *QWinNativePanGestureRecognizer::create(QObject *target) { if (!target) return new QPanGesture; // a special case @@ -73,7 +73,9 @@ QGesture *QWinNativePanGestureRecognizer::createGesture(QObject *target) return new QPanGesture; } -QGestureRecognizer::Result QWinNativePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) +QGestureRecognizer::Result QWinNativePanGestureRecognizer::recognize(QGesture *state, + QObject *, + QEvent *event) { QPanGesture *q = static_cast(state); QPanGesturePrivate *d = q->d_func(); @@ -85,26 +87,25 @@ QGestureRecognizer::Result QWinNativePanGestureRecognizer::filterEvent(QGesture case QNativeGestureEvent::GestureBegin: break; case QNativeGestureEvent::Pan: - result = QGestureRecognizer::GestureTriggered; + result = QGestureRecognizer::TriggerGesture; event->accept(); break; case QNativeGestureEvent::GestureEnd: if (q->state() == Qt::NoGesture) return QGestureRecognizer::Ignore; // some other gesture has ended - result = QGestureRecognizer::GestureFinished; + result = QGestureRecognizer::FinishGesture; break; default: return QGestureRecognizer::Ignore; } if (q->state() == Qt::NoGesture) { - d->lastOffset = d->totalOffset = d->offset = QPointF(); + d->lastOffset = d->offset = QPointF(); + d->startPosition = ev->position; } else { d->lastOffset = d->offset; - d->offset = QPointF(ev->position.x() - d->lastPosition.x(), - ev->position.y() - d->lastPosition.y()); - d->totalOffset += d->offset; + d->offset = QPointF(ev->position.x() - d->startPosition.x(), + ev->position.y() - d->startPosition.y()); } - d->lastPosition = ev->position; } return result; } @@ -114,8 +115,8 @@ void QWinNativePanGestureRecognizer::reset(QGesture *state) QPanGesture *pan = static_cast(state); QPanGesturePrivate *d = pan->d_func(); - d->totalOffset = d->lastOffset = d->offset = QPointF(); - d->lastPosition = QPoint(); + d->lastOffset = d->offset = QPointF(); + d->startPosition = QPoint(); d->acceleration = 0; QGestureRecognizer::reset(state); diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h index 1d723daa3e..8fb0d50b17 100644 --- a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h +++ b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h @@ -62,9 +62,8 @@ class QWinNativePanGestureRecognizer : public QGestureRecognizer public: QWinNativePanGestureRecognizer(); - QGesture *createGesture(QObject *target); - - QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event); + QGesture *create(QObject *target); + QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event); void reset(QGesture *state); }; -- cgit v1.2.3