Skip to content
Permalink
Browse files

[composer] Allow rotation for pictures set to "zoom & resize" mode

Previously rotation was only allowed for pictures set to "Zoom" mode,
which causes pictures to change size when the rotation changes (frame
size is constant). This change allows pictures set to "Zoom and resize"
mode to have rotation set. Altering the rotation when in this mode
keeps the picture size constant and changes the frame size to suit.

(fix #10640)
  • Loading branch information
nyalldawson committed Oct 19, 2014
1 parent a7d708f commit da5766c19d030fbf03e3863a5b7a3a8db46581a4
Showing with 34 additions and 5 deletions.
  1. +4 −2 src/app/composer/qgscomposerpicturewidget.cpp
  2. +30 −3 src/core/composer/qgscomposerpicture.cpp
@@ -225,7 +225,8 @@ void QgsComposerPictureWidget::on_mResizeModeComboBox_currentIndexChanged( int i
mPicture->endCommand();

//disable picture rotation for non-zoom modes
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom );
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom ||
mPicture->resizeMode() == QgsComposerPicture::ZoomResizeFrame );

//disable anchor point control for certain zoom modes
if ( mPicture->resizeMode() == QgsComposerPicture::Zoom ||
@@ -408,7 +409,8 @@ void QgsComposerPictureWidget::setGuiElementValues()

mResizeModeComboBox->setCurrentIndex(( int )mPicture->resizeMode() );
//disable picture rotation for non-zoom modes
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom );
mRotationGroupBox->setEnabled( mPicture->resizeMode() == QgsComposerPicture::Zoom ||
mPicture->resizeMode() == QgsComposerPicture::ZoomResizeFrame );

mAnchorPointComboBox->setCurrentIndex(( int )mPicture->pictureAnchor() );
//disable anchor point control for certain zoom modes
@@ -202,6 +202,15 @@ void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsIte
painter->translate( dX, dY );
}
}
else if ( mResizeMode == ZoomResizeFrame )
{
if ( mPictureRotation != 0 )
{
painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
painter->rotate( mPictureRotation );
painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
}
}

if ( mMode == SVG )
{
@@ -510,9 +519,9 @@ void QgsComposerPicture::setSceneRect( const QRectF& rectangle )

if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
{
//if width has changed less than height, then fix width and set height correspondingly
//if width has changed more than height, 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() );
@@ -532,7 +541,7 @@ void QgsComposerPicture::setSceneRect( const QRectF& rectangle )
}

//find largest scaling of picture with this rotation which fits in item
if ( mResizeMode == Zoom )
if ( mResizeMode == Zoom || mResizeMode == ZoomResizeFrame )
{
QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), newRect, mPictureRotation );
mPictureWidth = rotatedImageRect.width();
@@ -556,6 +565,7 @@ void QgsComposerPicture::setRotation( double r )

void QgsComposerPicture::setPictureRotation( double r )
{
double oldRotation = mPictureRotation;
mPictureRotation = r;

if ( mResizeMode == Zoom )
@@ -567,6 +577,23 @@ void QgsComposerPicture::setPictureRotation( double r )
mPictureHeight = rotatedImageRect.height();
update();
}
else if ( mResizeMode == ZoomResizeFrame )
{
QSizeF currentPictureSize = pictureSize();
QRectF oldRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );

//calculate actual size of image inside frame
QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), oldRotation );

//rotate image rect by new rotation and get bounding box
QTransform tr;
tr.rotate( mPictureRotation );
QRectF newRect = tr.mapRect( QRectF( 0, 0, rotatedImageRect.width(), rotatedImageRect.height() ) );

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

emit pictureRotationChanged( mPictureRotation );
}

0 comments on commit da5766c

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