@@ -605,55 +605,63 @@ void QgsComposerMap::moveContent( double dx, double dy )
605605
606606void QgsComposerMap::zoomContent ( int delta, double x, double y )
607607{
608- if ( mDrawing )
608+ QSettings settings;
609+
610+ // read zoom mode
611+ QgsComposerItem::ZoomMode zoomMode = ( QgsComposerItem::ZoomMode )settings.value ( " /qgis/wheel_action" , 2 ).toInt ();
612+ if ( zoomMode == QgsComposerItem::NoZoom )
609613 {
614+ // do nothing
610615 return ;
611616 }
612617
613- QSettings settings;
618+ double zoomFactor = settings.value ( " /qgis/zoom_factor" , 2.0 ).toDouble ();
619+ zoomFactor = delta > 0 ? zoomFactor : 1 / zoomFactor;
614620
615- // read zoom mode
616- // 0: zoom, 1: zoom and recenter, 2: zoom to cursor, 3: nothing
617- int zoomMode = settings.value ( " /qgis/wheel_action" , 2 ).toInt ();
618- if ( zoomMode == 3 ) // do nothing
621+ zoomContent ( zoomFactor, QPointF ( x, y ), zoomMode );
622+ }
623+
624+ void QgsComposerMap::zoomContent ( const double factor, const QPointF point, const ZoomMode mode )
625+ {
626+ if ( mDrawing )
619627 {
620628 return ;
621629 }
622630
623- double zoomFactor = settings.value ( " /qgis/zoom_factor" , 2.0 ).toDouble ();
631+ if ( mode == QgsComposerItem::NoZoom )
632+ {
633+ // do nothing
634+ return ;
635+ }
636+
637+ // find out map coordinates of position
638+ double mapX = currentMapExtent ()->xMinimum () + ( point.x () / rect ().width () ) * ( currentMapExtent ()->xMaximum () - currentMapExtent ()->xMinimum () );
639+ double mapY = currentMapExtent ()->yMinimum () + ( 1 - ( point.y () / rect ().height () ) ) * ( currentMapExtent ()->yMaximum () - currentMapExtent ()->yMinimum () );
624640
625641 // find out new center point
626642 double centerX = ( currentMapExtent ()->xMaximum () + currentMapExtent ()->xMinimum () ) / 2 ;
627643 double centerY = ( currentMapExtent ()->yMaximum () + currentMapExtent ()->yMinimum () ) / 2 ;
628644
629- if ( zoomMode != 0 )
645+ if ( mode != QgsComposerItem::Zoom )
630646 {
631- // find out map coordinates of mouse position
632- double mapMouseX = currentMapExtent ()->xMinimum () + ( x / rect ().width () ) * ( currentMapExtent ()->xMaximum () - currentMapExtent ()->xMinimum () );
633- double mapMouseY = currentMapExtent ()->yMinimum () + ( 1 - ( y / rect ().height () ) ) * ( currentMapExtent ()->yMaximum () - currentMapExtent ()->yMinimum () );
634- if ( zoomMode == 1 ) // zoom and recenter
647+ if ( mode == QgsComposerItem::ZoomRecenter )
635648 {
636- centerX = mapMouseX ;
637- centerY = mapMouseY ;
649+ centerX = mapX ;
650+ centerY = mapY ;
638651 }
639- else if ( zoomMode == 2 ) // zoom to cursor
652+ else if ( mode == QgsComposerItem::ZoomToPoint )
640653 {
641- centerX = mapMouseX + ( centerX - mapMouseX ) * ( 1.0 / zoomFactor );
642- centerY = mapMouseY + ( centerY - mapMouseY ) * ( 1.0 / zoomFactor );
654+ centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
655+ centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
643656 }
644657 }
645658
646659 double newIntervalX, newIntervalY;
647660
648- if ( delta > 0 )
649- {
650- newIntervalX = ( currentMapExtent ()->xMaximum () - currentMapExtent ()->xMinimum () ) / zoomFactor;
651- newIntervalY = ( currentMapExtent ()->yMaximum () - currentMapExtent ()->yMinimum () ) / zoomFactor;
652- }
653- else if ( delta < 0 )
661+ if ( factor > 0 )
654662 {
655- newIntervalX = ( currentMapExtent ()->xMaximum () - currentMapExtent ()->xMinimum () ) * zoomFactor ;
656- newIntervalY = ( currentMapExtent ()->yMaximum () - currentMapExtent ()->yMinimum () ) * zoomFactor ;
663+ newIntervalX = ( currentMapExtent ()->xMaximum () - currentMapExtent ()->xMinimum () ) / factor ;
664+ newIntervalY = ( currentMapExtent ()->yMaximum () - currentMapExtent ()->yMinimum () ) / factor ;
657665 }
658666 else // no need to zoom
659667 {
0 commit comments