@@ -519,16 +519,30 @@ void QgsComposerPicture::setSceneRect( const QRectF& rectangle )
519
519
520
520
if ( mResizeMode == ZoomResizeFrame && !rect ().isEmpty () && !( currentPictureSize.isEmpty () ) )
521
521
{
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
523
537
// else, do the opposite
524
- if ( qAbs ( rect ().width () - rectangle.width () ) >
538
+ if ( qAbs ( rect ().width () - rectangle.width () ) <
525
539
qAbs ( rect ().height () - rectangle.height () ) )
526
540
{
527
- newRect.setHeight ( currentPictureSize .height () * newRect.width () / currentPictureSize .width () );
541
+ newRect.setHeight ( targetImageSize .height () * newRect.width () / targetImageSize .width () );
528
542
}
529
543
else
530
544
{
531
- newRect.setWidth ( currentPictureSize .width () * newRect.height () / currentPictureSize .height () );
545
+ newRect.setWidth ( targetImageSize .width () * newRect.height () / targetImageSize .height () );
532
546
}
533
547
}
534
548
else if ( mResizeMode == FrameToImageSize )
@@ -592,7 +606,8 @@ void QgsComposerPicture::setPictureRotation( double r )
592
606
593
607
// keep the center in the same location
594
608
newRect.moveCenter ( oldRect.center () );
595
- setSceneRect ( newRect );
609
+ QgsComposerItem::setSceneRect ( newRect );
610
+ emit itemChanged ();
596
611
}
597
612
598
613
emit pictureRotationChanged ( mPictureRotation );
0 commit comments