From 20570bfa3e8b5206cc116499dc5bdd09155c8693 Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Thu, 19 Jun 2014 15:48:19 +0700 Subject: [PATCH] Feeling dizzy? It will not get any better if you type "dizzy" into coordinates box in the status bar! --- src/app/qgisapp.cpp | 30 ++++++++++++++++++++++++++++++ src/app/qgisapp.h | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index ca319e500fe..54a12df9970 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1724,6 +1724,8 @@ void QgisApp::createStatusBar() mCoordsEdit->setToolTip( tr( "Current map coordinate (lat,lon or east,north)" ) ); statusBar()->addPermanentWidget( mCoordsEdit, 0 ); connect( mCoordsEdit, SIGNAL( returnPressed() ), this, SLOT( userCenter() ) ); + mDizzyTimer = new QTimer( this ); + connect( mDizzyTimer, SIGNAL( timeout() ), this, SLOT( dizzy() ) ); // add a label to show current scale mScaleLabel = new QLabel( QString(), statusBar() ); @@ -6605,8 +6607,36 @@ void QgisApp::userScale() mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() ); } +void QgisApp::dizzy() +{ + // constants should go to options so that people can customize them to their taste + int d = 10; // max. translational dizziness offset + int r = 4; // max. rotational dizzines angle + QRectF rect = mMapCanvas->sceneRect(); + if ( rect.x() < -d || rect.x() > d || rect.y() < -d || rect.y() > d ) + return; // do not affect panning + rect.moveTo(( rand() % ( 2 * d ) ) - d, ( rand() % ( 2 * d ) ) - d ); + mMapCanvas->setSceneRect( rect ); + QTransform matrix; + matrix.rotate(( rand() % ( 2 * r ) ) - r ); + mMapCanvas->setTransform( matrix ); +} + void QgisApp::userCenter() { + if ( mCoordsEdit->text() == "dizzy" ) + { + // sometimes you may feel a bit dizzy... + if ( mDizzyTimer->isActive() ) + { + mDizzyTimer->stop(); + mMapCanvas->setSceneRect( mMapCanvas->viewport()->rect() ); + mMapCanvas->setTransform( QTransform() ); + } + else + mDizzyTimer->start( 100 ); + } + QStringList parts = mCoordsEdit->text().split( ',' ); if ( parts.size() != 2 ) return; diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index e9039877055..f01e6b6d4c5 100755 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -1230,6 +1230,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow * @note added in 2.3 */ void activateDeuteranopePreview(); + /** Make the user feel dizzy */ + void dizzy(); + signals: /** emitted when a key is pressed and we want non widget sublasses to be able to pick up on this (e.g. maplayer) */ @@ -1542,6 +1545,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow */ QTimer *mpMapTipsTimer; + //! Helps to make people dizzy + QTimer* mDizzyTimer; + /** Point of last mouse position in map coordinates (used with MapTips) */ QgsPoint mLastMapPosition;