Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding touch maptool that allows panning, pinch zooming, double tap z…
…oomWithCenter, twofinger tap zoomOut

fixed toolbar button functionality
  • Loading branch information
mbernasocchi committed Mar 28, 2012
1 parent 3d53e29 commit 48a0612
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 26 deletions.
5 changes: 4 additions & 1 deletion images/images.qrc
Expand Up @@ -108,7 +108,7 @@
<file>themes/default/mActionNewFolder.png</file>
<file>themes/default/mActionNewVectorLayer.png</file>
<file>themes/default/mActionNodeTool.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOffsetCurve.png</file>
<file>themes/default/mActionOpenTable.png</file>
<file>themes/default/mActionOptions.png</file>
<file>themes/default/mActionPan.png</file>
Expand Down Expand Up @@ -366,7 +366,10 @@
<file>themes/gis/mIconMssql.png</file>
<file>themes/gis/mIconConnect.png</file>
<file>themes/gis/mIconDbSchema.png</file>
<file>themes/gis/mActionTouch.png</file>
<file>themes/default/mActionAddMssqlLayer.png</file>
<file>themes/default/mActionTouch.png</file>
<file>themes/classic/mActionTouch.png</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
Binary file added images/themes/classic/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/gis/mActionTouch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 65 additions & 20 deletions src/app/qgisapp.cpp
Expand Up @@ -258,6 +258,10 @@ extern "C"
#include <windows.h>
#endif

#ifdef HAVE_TOUCH
#include "qgsmaptooltouch.h"
#endif

class QTreeWidgetItem;


Expand Down Expand Up @@ -626,7 +630,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 );

#ifdef ANDROID
#ifdef HAVE_TOUCH
//add reacting to long click in android
grabGesture( Qt::TapAndHoldGesture );
#endif
Expand All @@ -646,6 +650,9 @@ QgisApp::~QgisApp()
delete mMapTools.mZoomIn;
delete mMapTools.mZoomOut;
delete mMapTools.mPan;
#ifdef HAVE_TOUCH
delete mMapTools.mTouch;
#endif
delete mMapTools.mIdentify;
delete mMapTools.mFeatureAction;
delete mMapTools.mMeasureDist;
Expand Down Expand Up @@ -741,8 +748,8 @@ bool QgisApp::event( QEvent * event )
openFile( foe->file() );
done = true;
}
#ifdef ANDROID
else if ( event->type() == QEvent::Gesture )
#ifdef HAVE_TOUCH
else if (event->type() == QEvent::Gesture )
{
done = gestureEvent( static_cast<QGestureEvent*>( event ) );
}
Expand Down Expand Up @@ -820,6 +827,9 @@ void QgisApp::createActions()

// View Menu Items

#ifdef HAVE_TOUCH
connect( mActionTouch, SIGNAL( triggered() ), this, SLOT( touch() ) );
#endif
connect( mActionPan, SIGNAL( triggered() ), this, SLOT( pan() ) );
connect( mActionPanToSelected, SIGNAL( triggered() ), this, SLOT( panToSelected() ) );
connect( mActionZoomIn, SIGNAL( triggered() ), this, SLOT( zoomIn() ) );
Expand Down Expand Up @@ -1009,6 +1019,9 @@ void QgisApp::createActionGroups()
//
// Map Tool Group
mMapToolGroup = new QActionGroup( this );
#ifdef HAVE_TOUCH
mMapToolGroup->addAction( mActionTouch );
#endif
mMapToolGroup->addAction( mActionPan );
mMapToolGroup->addAction( mActionZoomIn );
mMapToolGroup->addAction( mActionZoomOut );
Expand Down Expand Up @@ -1529,6 +1542,9 @@ void QgisApp::setTheme( QString theThemeName )
mActionZoomOut->setIcon( getThemeIcon( "/mActionZoomOut.png" ) );
mActionZoomFullExtent->setIcon( getThemeIcon( "/mActionZoomFullExtent.png" ) );
mActionZoomToSelected->setIcon( getThemeIcon( "/mActionZoomToSelected.png" ) );
#ifdef HAVE_TOUCH
mActionTouch->setIcon( getThemeIcon( "/mActionTouch.png" ) );
#endif
mActionPan->setIcon( getThemeIcon( "/mActionPan.png" ) );
mActionZoomLast->setIcon( getThemeIcon( "/mActionZoomLast.png" ) );
mActionZoomNext->setIcon( getThemeIcon( "/mActionZoomNext.png" ) );
Expand Down Expand Up @@ -1660,6 +1676,10 @@ void QgisApp::createCanvasTools()
mMapTools.mZoomOut->setAction( mActionZoomOut );
mMapTools.mPan = new QgsMapToolPan( mMapCanvas );
mMapTools.mPan->setAction( mActionPan );
#ifdef HAVE_TOUCH
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
mMapTools.mTouch->setAction( mActionTouch );
#endif
mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas );
mMapTools.mIdentify->setAction( mActionIdentify );
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
Expand Down Expand Up @@ -1725,6 +1745,9 @@ void QgisApp::createCanvasTools()
mMapTools.mChangeLabelProperties->setAction( mActionChangeLabelProperties );
//ensure that non edit tool is initialised or we will get crashes in some situations
mNonEditMapTool = mMapTools.mPan;
//#ifdef HAVE_TOUCH
// mNonEditMapTool = mMapTools.mTouch;
//#endif
}

void QgisApp::createOverview()
Expand Down Expand Up @@ -2275,10 +2298,11 @@ bool QgisApp::addVectorLayers( QStringList const & theLayerQStringList, const QS
// present a dialog to choose GDAL raster sublayers
void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
{
if ( !layer || layer->subLayers().size() < 1 )
if ( !layer )
return;

QStringList sublayers = layer->subLayers();

QgsDebugMsg( "sublayers:\n " + sublayers.join( " \n" ) + "\n" );

// if promptLayers=Load all, load all sublayers without prompting
Expand All @@ -2303,7 +2327,16 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )

if ( chooseSublayersDialog.exec() )
{
loadGDALSublayers( layer->source(), chooseSublayersDialog.getSelection() );
foreach( QString path, chooseSublayersDialog.getSelection() )
{
QString name = path;
name.replace( layer->source(), QFileInfo( layer->source() ).completeBaseName() );
QgsRasterLayer *rlayer = new QgsRasterLayer( path, name );
if ( rlayer && rlayer->isValid() )
{
addRasterLayer( rlayer );
}
}
}
}

Expand All @@ -2316,9 +2349,11 @@ bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )

QSettings settings;
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", 1 ).toInt();
// 0 = always -> always ask (if there are existing sublayers)
// 1 = if needed -> ask if layer has no bands, but has sublayers
// 2 = never

// return true if promptLayers=Always or if promptLayers!=Never and there are no bands
return promptLayers == 0 || ( promptLayers != 2 && layer->bandCount() == 0 );
return promptLayers == 0 || ( promptLayers == 1 && layer->bandCount() == 0 );
}

// This method will load with GDAL the layers in parameter.
Expand Down Expand Up @@ -2732,6 +2767,10 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )
// set the initial map tool
mMapCanvas->setMapTool( mMapTools.mPan );
mNonEditMapTool = mMapTools.mPan; // signals are not yet setup to catch this
#ifdef HAVE_TOUCH
mMapCanvas->setMapTool( mMapTools.mTouch );
mNonEditMapTool = mMapTools.mTouch; // signals are not yet setup to catch this
#endif
} // QgisApp::fileNew(bool thePromptToSaveFlag)


Expand Down Expand Up @@ -2821,11 +2860,7 @@ void QgisApp::fileOpen()
deletePrintComposers();
removeAnnotationItems();
// clear out any stuff from previous project

//avoid multiple canvas redraws during loading of project files
bool bkRenderFlag = mMapCanvas->renderFlag();
mMapCanvas->setRenderFlag( false );

mMapCanvas->freeze( true );
removeAllLayers();

QgsProject::instance()->setFileName( fullPath );
Expand All @@ -2835,7 +2870,8 @@ void QgisApp::fileOpen()
QMessageBox::critical( this,
tr( "QGIS Project Read Error" ),
QgsProject::instance()->error() );
mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return;
}

Expand All @@ -2847,7 +2883,8 @@ void QgisApp::fileOpen()
// add this to the list of recently used project files
saveRecentProjectPath( fullPath, settings );

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}

} // QgisApp::fileOpen
Expand All @@ -2859,8 +2896,7 @@ void QgisApp::fileOpen()
*/
bool QgisApp::addProject( QString projectFile )
{
bool bkRenderFlag = mMapCanvas->renderFlag();
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze( true );

QApplication::setOverrideCursor( Qt::WaitCursor );

Expand All @@ -2878,7 +2914,8 @@ bool QgisApp::addProject( QString projectFile )

QApplication::restoreOverrideCursor();

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return false;
}

Expand Down Expand Up @@ -2914,7 +2951,8 @@ bool QgisApp::addProject( QString projectFile )

QApplication::restoreOverrideCursor();

mMapCanvas->setRenderFlag( bkRenderFlag );
mMapCanvas->freeze( false );
mMapCanvas->refresh();
return true;
} // QgisApp::addProject(QString projectFile)

Expand Down Expand Up @@ -3362,6 +3400,13 @@ void QgisApp::pan()
mMapCanvas->setMapTool( mMapTools.mPan );
}

#ifdef HAVE_TOUCH
void QgisApp::touch()
{
mMapCanvas->setMapTool( mMapTools.mTouch );
}
#endif

void QgisApp::zoomFull()
{
mMapCanvas->zoomToFullExtent();
Expand Down Expand Up @@ -7361,8 +7406,8 @@ QMenu* QgisApp::createPopupMenu()
return menu;
}

#ifdef ANDROID
bool QgisApp::gestureEvent( QGestureEvent *event )
#ifdef HAVE_TOUCH
bool QgisApp::gestureEvent(QGestureEvent *event)
{
if ( QGesture *tapAndHold = event->gesture( Qt::TapAndHoldGesture ) )
{
Expand Down
19 changes: 15 additions & 4 deletions src/app/qgisapp.h
Expand Up @@ -83,7 +83,7 @@ class QgsScaleComboBox;
#include <QPointer>
#include <QSslError>

#ifdef ANDROID
#ifdef HAVE_TOUCH
#include <QGestureEvent>
#include <QTapAndHoldGesture>
#endif
Expand Down Expand Up @@ -244,6 +244,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionSnappingOptions() { return mActionSnappingOptions; }
QAction *actionOffsetCurve() { return mActionOffsetCurve; }

#ifdef HAVE_TOUCH
QAction *actionTouch() { return mActionTouch; }
#endif

QAction *actionPan() { return mActionPan; }
QAction *actionPanToSelected() { return mActionPanToSelected; }
QAction *actionZoomIn() { return mActionZoomIn; }
Expand Down Expand Up @@ -767,6 +771,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void zoomIn();
//! Set map tool to pan
void pan();
#ifdef HAVE_TOUCH
//! Set map tool to touch
void touch();
#endif
//! Identify feature(s) on the currently selected layer
void identify();
//! Measure distance
Expand Down Expand Up @@ -992,6 +1000,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QgsMapTool* mZoomIn;
QgsMapTool* mZoomOut;
QgsMapTool* mPan;
#ifdef HAVE_TOUCH
QgsMapTool* mTouch;
#endif
QgsMapTool* mIdentify;
QgsMapTool* mFeatureAction;
QgsMapTool* mMeasureDist;
Expand Down Expand Up @@ -1169,9 +1180,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

QString mOldScale;

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

Expand Down
14 changes: 14 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -80,6 +80,13 @@ qgsexpressionhighlighter.cpp
qgsquerybuilder.cpp
)

IF (WITH_TOUCH)
SET(QGIS_GUI_SRCS
${QGIS_GUI_SRCS}
qgsmaptooltouch.cpp
)
ENDIF (WITH_TOUCH)

SET(QGIS_GUI_MOC_HDRS

symbology-ng/qgsdashspacedialog.h
Expand Down Expand Up @@ -185,6 +192,13 @@ attributetable/qgsattributetableidcolumnpair.h
attributetable/qgsattributetabledelegate.h
)

IF (WITH_TOUCH)
SET(QGIS_GUI_HDRS
${QGIS_GUI_HDRS}
qgsmaptooltouch.h
)
ENDIF (WITH_TOUCH)

SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsgenericprojectionselectorbase.h
Expand Down
27 changes: 26 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -1559,4 +1559,29 @@ void QgsMapCanvas::mapToolDestroyed()
{
QgsDebugMsg( "maptool destroyed" );
mMapTool = 0;
}
}

#ifdef HAVE_TOUCH
bool QgsMapCanvas::event( QEvent * e )
{
bool done = false;
if ( mDrawing )
{
return done;
}
if (e->type() == QEvent::Gesture )
{
// call handler of current map tool
if ( mMapTool )
{
done = mMapTool->gestureEvent( static_cast<QGestureEvent*>(e) );
}
}
else
{
// pass other events to base class
done = QGraphicsView::event( e );
}
return done;
}
#endif
9 changes: 9 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -30,6 +30,10 @@
#include <QGraphicsView>
#include <QtCore>

#ifdef HAVE_TOUCH
#include <QGestureEvent>
#endif

class QWheelEvent;
class QPixmap;
class QPaintEvent;
Expand Down Expand Up @@ -357,6 +361,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void zoomNextStatusChanged( bool );

protected:
#ifdef HAVE_TOUCH
//! Overridden standard event to be gestures aware
bool event( QEvent * e );
#endif

//! Overridden key press event
void keyPressEvent( QKeyEvent * e );

Expand Down

0 comments on commit 48a0612

Please sign in to comment.