Skip to content

Commit

Permalink
Merge pull request #96 from mbernasocchi/android
Browse files Browse the repository at this point in the history
Android right click using TapAndHoldGesture
  • Loading branch information
timlinux committed Feb 25, 2012
2 parents c42f094 + a90e3e9 commit 4e7603f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

#ifdef ANDROID
//add reacting to long click in android
grabGesture(Qt::TapAndHoldGesture);
#endif

// update windows
qApp->processEvents();

Expand Down Expand Up @@ -734,6 +739,12 @@ bool QgisApp::event( QEvent * event )
openFile( foe->file() );
done = true;
}
#ifdef ANDROID
else if (event->type() == QEvent::Gesture )
{
done = gestureEvent(static_cast<QGestureEvent*>(event));
}
#endif
else
{
// pass other events to base class
Expand Down Expand Up @@ -7265,3 +7276,27 @@ QMenu* QgisApp::createPopupMenu()

return menu;
}

#ifdef ANDROID
bool QgisApp::gestureEvent(QGestureEvent *event)
{
if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture))
{
tapAndHoldTriggered(static_cast<QTapAndHoldGesture *>(tapAndHold));
}
return true;
}

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;
qDebug() << "widget under point of click: " << receiver;

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
10 changes: 10 additions & 0 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class QgsScaleComboBox;
#include <QPointer>
#include <QSslError>

#ifdef ANDROID
#include <QGestureEvent>
#include <QTapAndHoldGesture>
#endif

#include "qgsconfig.h"
#include "qgsfeature.h"
#include "qgspoint.h"
Expand Down Expand Up @@ -1154,6 +1159,11 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
bool cmpByText( QAction* a, QAction* b );

QString mOldScale;

#ifdef ANDROID
bool gestureEvent(QGestureEvent *event);
void tapAndHoldTriggered(QTapAndHoldGesture *gesture);
#endif
};

#ifdef ANDROID
Expand Down

0 comments on commit 4e7603f

Please sign in to comment.