Handle change in product or orientation in View.

This commit is contained in:
Jim Evins
2016-04-15 23:40:40 -04:00
parent 783ede0a03
commit 0023106801
2 changed files with 33 additions and 10 deletions
+33 -9
View File
@@ -137,7 +137,7 @@ View::setModel( LabelModel* model )
connect( model, SIGNAL(changed()), this, SLOT(update()) );
connect( model, SIGNAL(selectionChanged()), this, SLOT(update()) );
connect( model, SIGNAL(sizeChanged()), this, SLOT(update()) );
connect( model, SIGNAL(sizeChanged()), this, SLOT(onModelSizeChanged()) );
update();
}
@@ -1152,17 +1152,41 @@ void View::onSettingsChanged()
}
///
/// Model changed handler
///
void View::onModelChanged()
{
}
///
/// Model size changed handler
///
void View::onModelSizeChanged()
{
using std::min;
using std::max;
if (mZoomToFitFlag)
{
double wPixels = mScrollArea->maximumViewportSize().width();
double hPixels = mScrollArea->maximumViewportSize().height();
double x_scale = ( wPixels - ZOOM_TO_FIT_PAD ) / mModel->w().pt();
double y_scale = ( hPixels - ZOOM_TO_FIT_PAD ) / mModel->h().pt();
double newZoom = min( x_scale, y_scale ) * PTS_PER_INCH / physicalDpiX();
// Limits
newZoom = min( newZoom, zoomLevels[0] );
newZoom = max( newZoom, zoomLevels[nZoomLevels-1] );
mZoom = newZoom;
}
/* Actual scale depends on DPI of display (assume DpiX == DpiY). */
mScale = mZoom * physicalDpiX() / PTS_PER_INCH;
setMinimumSize( mScale*mModel->w().pt() + ZOOM_TO_FIT_PAD,
mScale*mModel->h().pt() + ZOOM_TO_FIT_PAD );
/* Adjust origin to center label in widget. */
mX0 = (width()/mScale - mModel->w()) / 2;
mY0 = (height()/mScale - mModel->h()) / 2;
update();
emit zoomChanged();
}