Skip to content
Permalink
Browse files

Fix for #340.

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@6197 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 7, 2006
1 parent 622d34a commit e29bbebaeb94e8dae4778e991e23d821b1048f6c
Showing with 29 additions and 4 deletions.
  1. +20 −4 src/composer/qgscomposer.cpp
  2. +3 −0 src/composer/qgscomposer.h
  3. +5 −0 src/composer/qgscomposerview.cpp
  4. +1 −0 src/composer/qgscomposerview.h
@@ -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();
}
@@ -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;

@@ -60,3 +60,8 @@ void QgsComposerView::keyPressEvent ( QKeyEvent * e )
{
mComposer->composition()->keyPressEvent ( e );
}

void QgsComposerView::resizeEvent ( QResizeEvent * )
{
mComposer->zoomFull();
}
@@ -38,6 +38,7 @@ class QgsComposerView: public Q3CanvasView
void contentsMouseMoveEvent(QMouseEvent*);

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

private:
QgsComposer *mComposer;

0 comments on commit e29bbeb

Please sign in to comment.
You can’t perform that action at this time.