Skip to content
Permalink
Browse files

[composer] Fix item rotation so that rotation occurs around item center

  • Loading branch information
nyalldawson committed Dec 30, 2013
1 parent cea569d commit 41365d8501629c95ac13e49b1b7b0dbfca4fe40f
@@ -504,7 +504,7 @@ void QgsComposerItemWidget::on_mItemRotationSpinBox_valueChanged( double val )
if ( mItem )
{
mItem->beginCommand( tr( "Item rotation changed" ), QgsComposerMergeCommand::ItemRotation );
mItem->setItemRotation( val );
mItem->setItemRotation( val, true );
mItem->update();
mItem->endCommand();
}
@@ -486,8 +486,6 @@ void QgsComposerItem::setSceneRect( const QRectF& rectangle )

QRectF newRect( 0, 0, newWidth, newHeight );
QGraphicsRectItem::setRect( newRect );
//rotate item around its centre point
setTransformOriginPoint( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) );
setPos( xTranslation, yTranslation );

emit sizeChanged();
@@ -712,8 +710,21 @@ void QgsComposerItem::setRotation( double r )
setItemRotation( r );
}

void QgsComposerItem::setItemRotation( double r )
void QgsComposerItem::setItemRotation( double r, bool adjustPosition )
{
if ( adjustPosition )
{
//adjustPosition set, so shift the position of the item so that rotation occurs around item center
//create a line from the centrepoint of the rect() to its origin, in scene coordinates
QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
//rotate this line by the current rotation angle
refLine.setAngle( refLine.angle() - r + mItemRotation );
//get new end point of line - this is the new item position
QPointF rotatedReferencePoint = refLine.p2();
setPos( rotatedReferencePoint );
emit sizeChanged();
}

if ( r > 360 )
{
mItemRotation = (( int )r ) % 360;
@@ -723,8 +734,7 @@ void QgsComposerItem::setItemRotation( double r )
mItemRotation = r;
}

//rotate item around its centre point
setTransformOriginPoint( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) );
setTransformOriginPoint( 0, 0 );
QGraphicsItem::setRotation( mItemRotation );

emit itemRotationChanged( r );
@@ -320,9 +320,12 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
virtual void setRotation( double r );

/**Sets the item rotation
@param r item rotation in degrees
@param adjustPosition set to true if item should be shifted so that rotation occurs
around item center. If false, rotation occurs around item origin
@note this method was added in version 2.1
*/
virtual void setItemRotation( double r );
virtual void setItemRotation( double r, bool adjustPosition = false );

void repaint();

0 comments on commit 41365d8

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