Skip to content

Commit

Permalink
Fix for #340.
Browse files Browse the repository at this point in the history
Do correct translation in world matrix after every zoom in composer.
Also does full zoom when composer window gets resized.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6197 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 7, 2006
1 parent eaea678 commit 8a0dd8f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/composer/qgscomposer.cpp
Expand Up @@ -231,18 +231,34 @@ void QgsComposer::on_mActionZoomAll_activated(void)
zoomFull();
}

QMatrix QgsComposer::updateMatrix(double scaleChange)
{
double scale = mView->worldMatrix().m11() * scaleChange; // get new scale

double dx = ( mView->width() - scale * mComposition->canvas()->width() ) / 2;
double dy = ( mView->height() - scale * mComposition->canvas()->height() ) / 2;

// don't translate if composition is bigger than view
if (dx < 0) dx = 0;
if (dy < 0) dy = 0;

// create new world matrix:
QMatrix m;
m.translate ( dx, dy );
m.scale ( scale, scale );
return m;
}

void QgsComposer::on_mActionZoomIn_activated(void)
{
QMatrix m = mView->worldMatrix();
m.scale( 2.0, 2.0 );
QMatrix m = updateMatrix(2);
mView->setWorldMatrix( m );
mView->repaintContents();
}

void QgsComposer::on_mActionZoomOut_activated(void)
{
QMatrix m = mView->worldMatrix();
m.scale( 0.5, 0.5 );
QMatrix m = updateMatrix(0.5);
mView->setWorldMatrix( m );
mView->repaintContents();
}
Expand Down
3 changes: 3 additions & 0 deletions src/composer/qgscomposer.h
Expand Up @@ -169,6 +169,9 @@ public slots:
//! Set buttons up
void setToolActionsOff (void);

//! returns new world matrix for canvas view after zoom with factor scaleChange
QMatrix updateMatrix(double scaleChange);

//! Pointer to composer view
QgsComposerView *mView;

Expand Down
5 changes: 5 additions & 0 deletions src/composer/qgscomposerview.cpp
Expand Up @@ -60,3 +60,8 @@ void QgsComposerView::keyPressEvent ( QKeyEvent * e )
{
mComposer->composition()->keyPressEvent ( e );
}

void QgsComposerView::resizeEvent ( QResizeEvent * )
{
mComposer->zoomFull();
}
1 change: 1 addition & 0 deletions src/composer/qgscomposerview.h
Expand Up @@ -38,6 +38,7 @@ class QgsComposerView: public Q3CanvasView
void contentsMouseMoveEvent(QMouseEvent*);

void keyPressEvent ( QKeyEvent * e );
void resizeEvent ( QResizeEvent * );

private:
QgsComposer *mComposer;
Expand Down

0 comments on commit 8a0dd8f

Please sign in to comment.