Skip to content
Permalink
Browse files
Replaced zoomFull() code with a single QGraphicsView function.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8441 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
StevenB authored and StevenB committed May 15, 2008
1 parent 47f79b5 commit 6401a8e9695bb8d858f7bb8ae248bee419353cfd
Showing with 5 additions and 42 deletions.
  1. +1 −39 src/app/composer/qgscomposer.cpp
  2. +4 −3 src/app/composer/qgscomposerview.cpp
@@ -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);
@@ -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

0 comments on commit 6401a8e

Please sign in to comment.