Skip to content

Commit 09691ba

Browse files
committedOct 20, 2014
[composer] Follow up da5766c, fix picture rotation calculation
Previous commit failed to address the issue for non-squareish images.
1 parent c496fc7 commit 09691ba

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed
 

‎src/core/composer/qgscomposerpicture.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,30 @@ void QgsComposerPicture::setSceneRect( const QRectF& rectangle )
519519

520520
if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
521521
{
522-
//if width has changed more than height, then fix width and set height correspondingly
522+
QSizeF targetImageSize;
523+
if ( mPictureRotation == 0 )
524+
{
525+
targetImageSize = currentPictureSize;
526+
}
527+
else
528+
{
529+
//calculate aspect ratio of bounds of rotated image
530+
QTransform tr;
531+
tr.rotate( mPictureRotation );
532+
QRectF rotatedBounds = tr.mapRect( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ) );
533+
targetImageSize = QSizeF( rotatedBounds.width(), rotatedBounds.height() );
534+
}
535+
536+
//if height has changed more than width, then fix width and set height correspondingly
523537
//else, do the opposite
524-
if ( qAbs( rect().width() - rectangle.width() ) >
538+
if ( qAbs( rect().width() - rectangle.width() ) <
525539
qAbs( rect().height() - rectangle.height() ) )
526540
{
527-
newRect.setHeight( currentPictureSize.height() * newRect.width() / currentPictureSize.width() );
541+
newRect.setHeight( targetImageSize.height() * newRect.width() / targetImageSize.width() );
528542
}
529543
else
530544
{
531-
newRect.setWidth( currentPictureSize.width() * newRect.height() / currentPictureSize.height() );
545+
newRect.setWidth( targetImageSize.width() * newRect.height() / targetImageSize.height() );
532546
}
533547
}
534548
else if ( mResizeMode == FrameToImageSize )
@@ -592,7 +606,8 @@ void QgsComposerPicture::setPictureRotation( double r )
592606

593607
//keep the center in the same location
594608
newRect.moveCenter( oldRect.center() );
595-
setSceneRect( newRect );
609+
QgsComposerItem::setSceneRect( newRect );
610+
emit itemChanged();
596611
}
597612

598613
emit pictureRotationChanged( mPictureRotation );

0 commit comments

Comments
 (0)
Please sign in to comment.