Skip to content

Commit

Permalink
Replaced zoomFull() code with a single QGraphicsView function.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@8441 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
StevenB authored and StevenB committed May 15, 2008
1 parent 68cdb3a commit b2cff74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 42 deletions.
40 changes: 1 addition & 39 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -225,52 +225,14 @@ QgsComposition *QgsComposer::composition(void)

void QgsComposer::zoomFull(void)
{
//can we just use QGraphicsView::fitInView with the "paper" rect?

QMatrix m;

// scale
double xscale = 1.0 * (mView->width()-10) / mComposition->canvas()->width();
double yscale = 1.0 * (mView->height()-10) / mComposition->canvas()->height();
double scale = ( xscale < yscale ? xscale : yscale );

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

m.translate ( dx, dy );
m.scale( scale, scale );

mView->setMatrix( m );
// mView->repaintContents(); //needed?

mView->fitInView(0, 0, mComposition->paperWidth(), mComposition->paperHeight(), Qt::KeepAspectRatio);
}

void QgsComposer::on_mActionZoomAll_activated(void)
{
zoomFull();
}
/*
QMatrix QgsComposer::updateMatrix(double scaleChange)
{
double scale = mView->matrix().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)
{
mView->scale(2, 2);
Expand Down
7 changes: 4 additions & 3 deletions src/app/composer/qgscomposerview.cpp
Expand Up @@ -67,14 +67,15 @@ void QgsComposerView::keyPressEvent ( QKeyEvent * e )

void QgsComposerView::resizeEvent ( QResizeEvent * )
{
#ifdef QGISDEBUG
std::cout << "QgsComposerView::resizeEvent()" << std::endl;
#endif

/* BUG: When QT adds scrollbars because we're zooming in, it causes a resizeEvent.
* If we call zoomFull(), we reset the view size, which keeps us from zooming in.
* Really, we should do something like re-center the window.
*/
//mComposer->zoomFull();
#ifdef QGISDEBUG
std::cout << "resize anchor: " << resizeAnchor() << std::endl;
#endif
}

//TODO: add mouse wheel event forwarding
Expand Down

0 comments on commit b2cff74

Please sign in to comment.