Skip to content
Permalink
Browse files

[composer] Follow up da5766c, fix picture rotation calculation

Previous commit failed to address the issue for non-squareish
images.
  • Loading branch information
nyalldawson committed Oct 20, 2014
1 parent c496fc7 commit 09691baf7e3ea2d1ebeedf3d9f6b275c8d246546
Showing with 20 additions and 5 deletions.
  1. +20 −5 src/core/composer/qgscomposerpicture.cpp
@@ -519,16 +519,30 @@ void QgsComposerPicture::setSceneRect( const QRectF& rectangle )

if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
{
//if width has changed more than height, then fix width and set height correspondingly
QSizeF targetImageSize;
if ( mPictureRotation == 0 )
{
targetImageSize = currentPictureSize;
}
else
{
//calculate aspect ratio of bounds of rotated image
QTransform tr;
tr.rotate( mPictureRotation );
QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) );
targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() );
}

//if height has changed more than width, then fix width and set height correspondingly
//else, do the opposite
if ( qAbs( rect().width() - rectangle.width() ) >
if ( qAbs( rect().width() - rectangle.width() ) <
qAbs( rect().height() - rectangle.height() ) )
{
newRect.setHeight( currentPictureSize.height() * newRect.width() / currentPictureSize.width() );
newRect.setHeight( targetImageSize.height() * newRect.width() / targetImageSize.width() );
}
else
{
newRect.setWidth( currentPictureSize.width() * newRect.height() / currentPictureSize.height() );
newRect.setWidth( targetImageSize.width() * newRect.height() / targetImageSize.height() );
}
}
else if ( mResizeMode == FrameToImageSize )
@@ -592,7 +606,8 @@ void QgsComposerPicture::setPictureRotation( double r )

//keep the center in the same location
newRect.moveCenter( oldRect.center() );
setSceneRect( newRect );
QgsComposerItem::setSceneRect( newRect );
emit itemChanged();
}

emit pictureRotationChanged( mPictureRotation );

0 comments on commit 09691ba

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