[QGIS Commit] r9297 - in trunk/qgis/src: core/composer gui
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Sep 11 05:01:06 EDT 2008
Author: mhugent
Date: 2008-09-11 05:01:06 -0400 (Thu, 11 Sep 2008)
New Revision: 9297
Modified:
trunk/qgis/src/core/composer/qgscomposeritem.h
trunk/qgis/src/core/composer/qgscomposermap.cpp
trunk/qgis/src/core/composer/qgscomposermap.h
trunk/qgis/src/gui/qgscomposerview.cpp
trunk/qgis/src/gui/qgscomposerview.h
Log:
Consider mouse wheel in composer map (ticket #1289)
Modified: trunk/qgis/src/core/composer/qgscomposeritem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.h 2008-09-11 06:14:55 UTC (rev 9296)
+++ trunk/qgis/src/core/composer/qgscomposeritem.h 2008-09-11 09:01:06 UTC (rev 9297)
@@ -70,9 +70,17 @@
/**Moves item in canvas coordinates*/
void move( double dx, double dy );
- /**Move Content of item. Does nothing per default (but implemented in composer map)*/
+ /**Move Content of item. Does nothing per default (but implemented in composer map)
+ @param dx move in x-direction (canvas coordinates)
+ @param dy move in y-direction(canvas coordinates)*/
virtual void moveContent( double dx, double dy ) {}
+ /**Zoom content of item. Does nothing per default (but implemented in composer map)
+ @param delta value from wheel event that describes magnitude and direction (positive /negative number)
+ @param x x-position of mouse cursor (in item coordinates)
+ @param y y-position of mouse cursor (in item coordinates)*/
+ virtual void zoomContent( int delta, double x, double y) {}
+
/**Sets this items bound in scene coordinates such that 1 item size units
corresponds to 1 scene size unit*/
virtual void setSceneRect( const QRectF& rectangle );
Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp 2008-09-11 06:14:55 UTC (rev 9296)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp 2008-09-11 09:01:06 UTC (rev 9297)
@@ -35,6 +35,7 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPainter>
+#include <QSettings>
#include <iostream>
#include <cmath>
@@ -278,6 +279,68 @@
}
}
+void QgsComposerMap::zoomContent( int delta, double x, double y)
+{
+ QSettings settings;
+
+ //read zoom mode
+ //0: zoom, 1: zoom and recenter, 2: zoom to cursor, 3: nothing
+ int zoomMode = settings.value("/qgis/wheel_action", 0 ).toInt();
+ if(zoomMode == 3) //do nothing
+ {
+ return;
+ }
+
+ double zoomFactor = settings.value("/qgis/zoom_factor", 2.0).toDouble();
+
+ //find out new center point
+ double centerX = (mExtent.xMax() + mExtent.xMin()) / 2;
+ double centerY = (mExtent.yMax() + mExtent.yMin()) / 2;
+
+ if(zoomMode != 0)
+ {
+ //find out map coordinates of mouse position
+ double mapMouseX = mExtent.xMin() + (x / rect().width()) * (mExtent.xMax() - mExtent.xMin());
+ double mapMouseY = mExtent.yMin() + (1 - (y / rect().height())) * (mExtent.yMax() - mExtent.yMin());
+ if(zoomMode == 1) //zoom and recenter
+ {
+ centerX = mapMouseX;
+ centerY = mapMouseY;
+ }
+ else if(zoomMode == 2) //zoom to cursor
+ {
+ centerX = mapMouseX + (centerX - mapMouseX) * (1.0 / zoomFactor);
+ centerY = mapMouseY + (centerY - mapMouseY) * (1.0 / zoomFactor);
+ }
+ }
+
+ double newIntervalX, newIntervalY;
+
+ if(delta > 0)
+ {
+ newIntervalX = (mExtent.xMax() - mExtent.xMin()) / zoomFactor;
+ newIntervalY = (mExtent.yMax() - mExtent.yMin()) / zoomFactor;
+ }
+ else if(delta < 0)
+ {
+ newIntervalX = (mExtent.xMax() - mExtent.xMin()) * zoomFactor;
+ newIntervalY = (mExtent.yMax() - mExtent.yMin()) * zoomFactor;
+ }
+ else //no need to zoom
+ {
+ return;
+ }
+
+ mExtent.setXMaximum(centerX + newIntervalX / 2);
+ mExtent.setXMinimum(centerX - newIntervalX / 2);
+ mExtent.setYMaximum(centerY + newIntervalY / 2);
+ mExtent.setYMinimum(centerY - newIntervalY / 2);
+
+ emit extentChanged();
+ cache();
+ update();
+}
+
void QgsComposerMap::setSceneRect( const QRectF& rectangle )
{
double w = rectangle.width();
Modified: trunk/qgis/src/core/composer/qgscomposermap.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.h 2008-09-11 06:14:55 UTC (rev 9296)
+++ trunk/qgis/src/core/composer/qgscomposermap.h 2008-09-11 09:01:06 UTC (rev 9297)
@@ -87,6 +87,12 @@
@param dy move in y-direction (item and canvas coordinates)*/
void moveContent( double dx, double dy );
+ /**Zoom content of map
+ @param delta value from wheel event that describes magnitude and direction (positive /negative number)
+ @param x x-coordinate of mouse position in item coordinates
+ @param y y-coordinate of mouse position in item coordinates*/
+ void zoomContent( int delta, double x, double y);
+
/**Sets new scene rectangle bounds and recalculates hight and extent*/
void setSceneRect( const QRectF& rectangle );
Modified: trunk/qgis/src/gui/qgscomposerview.cpp
===================================================================
--- trunk/qgis/src/gui/qgscomposerview.cpp 2008-09-11 06:14:55 UTC (rev 9296)
+++ trunk/qgis/src/gui/qgscomposerview.cpp 2008-09-11 09:01:06 UTC (rev 9297)
@@ -336,6 +336,22 @@
}
}
+void QgsComposerView::wheelEvent( QWheelEvent* event)
+{
+ QPointF scenePoint = mapToScene( event->pos() );
+
+ //select topmost item at position of event
+ QgsComposerItem* theItem = composition()->composerItemAt( scenePoint );
+ if (theItem)
+ {
+ if(theItem->isSelected())
+ {
+ QPointF itemPoint = theItem->mapFromScene(scenePoint);
+ theItem->zoomContent(event->delta(), itemPoint.x(), itemPoint.y());
+ }
+ }
+}
+
void QgsComposerView::setComposition( QgsComposition* c )
{
setScene( c );
Modified: trunk/qgis/src/gui/qgscomposerview.h
===================================================================
--- trunk/qgis/src/gui/qgscomposerview.h 2008-09-11 06:14:55 UTC (rev 9296)
+++ trunk/qgis/src/gui/qgscomposerview.h 2008-09-11 09:01:06 UTC (rev 9297)
@@ -79,6 +79,8 @@
void keyPressEvent( QKeyEvent * e );
void keyReleaseEvent( QKeyEvent * e );
+ void wheelEvent( QWheelEvent* event);
+
private:
/**Status of shift key (used for multiple selection)*/
bool mShiftKeyPressed;
More information about the QGIS-commit
mailing list