File tree Expand file tree Collapse file tree 4 files changed +29
-4
lines changed Expand file tree Collapse file tree 4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -231,18 +231,34 @@ void QgsComposer::on_mActionZoomAll_activated(void)
231231 zoomFull ();
232232}
233233
234+ QMatrix QgsComposer::updateMatrix (double scaleChange)
235+ {
236+ double scale = mView ->worldMatrix ().m11 () * scaleChange; // get new scale
237+
238+ double dx = ( mView ->width () - scale * mComposition ->canvas ()->width () ) / 2 ;
239+ double dy = ( mView ->height () - scale * mComposition ->canvas ()->height () ) / 2 ;
240+
241+ // don't translate if composition is bigger than view
242+ if (dx < 0 ) dx = 0 ;
243+ if (dy < 0 ) dy = 0 ;
244+
245+ // create new world matrix:
246+ QMatrix m;
247+ m.translate ( dx, dy );
248+ m.scale ( scale, scale );
249+ return m;
250+ }
251+
234252void QgsComposer::on_mActionZoomIn_activated (void )
235253{
236- QMatrix m = mView ->worldMatrix ();
237- m.scale ( 2.0 , 2.0 );
254+ QMatrix m = updateMatrix (2 );
238255 mView ->setWorldMatrix ( m );
239256 mView ->repaintContents ();
240257}
241258
242259void QgsComposer::on_mActionZoomOut_activated (void )
243260{
244- QMatrix m = mView ->worldMatrix ();
245- m.scale ( 0.5 , 0.5 );
261+ QMatrix m = updateMatrix (0.5 );
246262 mView ->setWorldMatrix ( m );
247263 mView ->repaintContents ();
248264}
Original file line number Diff line number Diff line change @@ -169,6 +169,9 @@ public slots:
169169 // ! Set buttons up
170170 void setToolActionsOff (void );
171171
172+ // ! returns new world matrix for canvas view after zoom with factor scaleChange
173+ QMatrix updateMatrix (double scaleChange);
174+
172175 // ! Pointer to composer view
173176 QgsComposerView *mView ;
174177
Original file line number Diff line number Diff line change @@ -60,3 +60,8 @@ void QgsComposerView::keyPressEvent ( QKeyEvent * e )
6060{
6161 mComposer ->composition ()->keyPressEvent ( e );
6262}
63+
64+ void QgsComposerView::resizeEvent ( QResizeEvent * )
65+ {
66+ mComposer ->zoomFull ();
67+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class QgsComposerView: public Q3CanvasView
3838 void contentsMouseMoveEvent (QMouseEvent*);
3939
4040 void keyPressEvent ( QKeyEvent * e );
41+ void resizeEvent ( QResizeEvent * );
4142
4243private:
4344 QgsComposer *mComposer ;
You can’t perform that action at this time.
0 commit comments