From 99b890b25a832cd6a3f86a0a6826a39516504a53 Mon Sep 17 00:00:00 2001 From: Marco Bernasocchi Date: Thu, 9 Feb 2012 15:05:47 +0100 Subject: [PATCH 1/2] initial right click support --- src/app/qgisapp.cpp | 35 +++++++++++++++++++++++++++++++++++ src/app/qgisapp.h | 10 ++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 688801c5b110..51e9c2f01ce1 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -625,6 +625,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent, // request notification of FileOpen events (double clicking a file icon in Mac OS X Finder) QgsApplication::setFileOpenEventReceiver( this ); +#ifndef ANDROID2 + //add reacting to long click in android + grabGesture(Qt::TapAndHoldGesture); +#endif + // update windows qApp->processEvents(); @@ -734,6 +739,12 @@ bool QgisApp::event( QEvent * event ) openFile( foe->file() ); done = true; } +#ifndef ANDROID2 + else if (event->type() == QEvent::Gesture ) + { + done = gestureEvent(static_cast(event)); + } +#endif else { // pass other events to base class @@ -7265,3 +7276,27 @@ QMenu* QgisApp::createPopupMenu() return menu; } + +#ifndef ANDROID2 +bool QgisApp::gestureEvent(QGestureEvent *event) +{ + if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) + { + tapAndHoldTriggered(static_cast(tapAndHold)); + } + return true; +} + +void QgisApp::tapAndHoldTriggered(QTapAndHoldGesture *gesture) +{ + if (gesture->state() == Qt::GestureFinished) { + QPoint pos = gesture->position().toPoint(); + qDebug() << "tapAndHoldTriggered: LONG CLICK gesture happened at " << pos; + QWidget * receiver = QApplication::widgetAt( this->mapToGlobal(pos) ); + qDebug() << "widget under point of click: " << receiver; + + QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonPress, pos, Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); + QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonRelease, pos, Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); + } +} +#endif diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index f0b43e9100c8..408126846eeb 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -83,6 +83,11 @@ class QgsScaleComboBox; #include #include +#ifndef ANDROID2 +#include +#include +#endif + #include "qgsconfig.h" #include "qgsfeature.h" #include "qgspoint.h" @@ -1154,6 +1159,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow bool cmpByText( QAction* a, QAction* b ); QString mOldScale; + +#ifndef ANDROID2 + bool gestureEvent(QGestureEvent *event); + void tapAndHoldTriggered(QTapAndHoldGesture *gesture); +#endif }; #ifdef ANDROID From a90e3e9262ed1a581ca426236620c281f8646bef Mon Sep 17 00:00:00 2001 From: Marco Bernasocchi Date: Thu, 16 Feb 2012 22:07:13 +0100 Subject: [PATCH 2/2] Fixed Right click support using TapAndHold gesture --- src/app/qgisapp.cpp | 12 ++++++------ src/app/qgisapp.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 51e9c2f01ce1..4a334132732c 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -625,7 +625,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent, // request notification of FileOpen events (double clicking a file icon in Mac OS X Finder) QgsApplication::setFileOpenEventReceiver( this ); -#ifndef ANDROID2 +#ifdef ANDROID //add reacting to long click in android grabGesture(Qt::TapAndHoldGesture); #endif @@ -739,7 +739,7 @@ bool QgisApp::event( QEvent * event ) openFile( foe->file() ); done = true; } -#ifndef ANDROID2 +#ifdef ANDROID else if (event->type() == QEvent::Gesture ) { done = gestureEvent(static_cast(event)); @@ -7277,7 +7277,7 @@ QMenu* QgisApp::createPopupMenu() return menu; } -#ifndef ANDROID2 +#ifdef ANDROID bool QgisApp::gestureEvent(QGestureEvent *event) { if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) @@ -7291,12 +7291,12 @@ void QgisApp::tapAndHoldTriggered(QTapAndHoldGesture *gesture) { if (gesture->state() == Qt::GestureFinished) { QPoint pos = gesture->position().toPoint(); + QWidget * receiver = QApplication::widgetAt( pos ); qDebug() << "tapAndHoldTriggered: LONG CLICK gesture happened at " << pos; - QWidget * receiver = QApplication::widgetAt( this->mapToGlobal(pos) ); qDebug() << "widget under point of click: " << receiver; - QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonPress, pos, Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); - QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonRelease, pos, Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); + QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonPress, receiver->mapFromGlobal( pos ), Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); + QApplication::postEvent( receiver, new QMouseEvent( QEvent::MouseButtonRelease, receiver->mapFromGlobal( pos ), Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ); } } #endif diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 408126846eeb..2c8aade8571c 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -83,7 +83,7 @@ class QgsScaleComboBox; #include #include -#ifndef ANDROID2 +#ifdef ANDROID #include #include #endif @@ -1160,7 +1160,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow QString mOldScale; -#ifndef ANDROID2 +#ifdef ANDROID bool gestureEvent(QGestureEvent *event); void tapAndHoldTriggered(QTapAndHoldGesture *gesture); #endif