Skip to content

Commit

Permalink
[composer] Follow up da5766c, fix picture rotation calculation
Browse files Browse the repository at this point in the history
Previous commit failed to address the issue for non-squareish
images.
  • Loading branch information
nyalldawson committed Oct 20, 2014
1 parent c496fc7 commit 09691ba
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/core/composer/qgscomposerpicture.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 09691ba

Please sign in to comment.