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)
231
231
zoomFull ();
232
232
}
233
233
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
+
234
252
void QgsComposer::on_mActionZoomIn_activated (void )
235
253
{
236
- QMatrix m = mView ->worldMatrix ();
237
- m.scale ( 2.0 , 2.0 );
254
+ QMatrix m = updateMatrix (2 );
238
255
mView ->setWorldMatrix ( m );
239
256
mView ->repaintContents ();
240
257
}
241
258
242
259
void QgsComposer::on_mActionZoomOut_activated (void )
243
260
{
244
- QMatrix m = mView ->worldMatrix ();
245
- m.scale ( 0.5 , 0.5 );
261
+ QMatrix m = updateMatrix (0.5 );
246
262
mView ->setWorldMatrix ( m );
247
263
mView ->repaintContents ();
248
264
}
Original file line number Diff line number Diff line change @@ -169,6 +169,9 @@ public slots:
169
169
// ! Set buttons up
170
170
void setToolActionsOff (void );
171
171
172
+ // ! returns new world matrix for canvas view after zoom with factor scaleChange
173
+ QMatrix updateMatrix (double scaleChange);
174
+
172
175
// ! Pointer to composer view
173
176
QgsComposerView *mView ;
174
177
Original file line number Diff line number Diff line change @@ -60,3 +60,8 @@ void QgsComposerView::keyPressEvent ( QKeyEvent * e )
60
60
{
61
61
mComposer ->composition ()->keyPressEvent ( e );
62
62
}
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
38
38
void contentsMouseMoveEvent (QMouseEvent*);
39
39
40
40
void keyPressEvent ( QKeyEvent * e );
41
+ void resizeEvent ( QResizeEvent * );
41
42
42
43
private:
43
44
QgsComposer *mComposer ;
You can’t perform that action at this time.
0 commit comments