Skip to content

Commit

Permalink
Improved label rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 29, 2012
1 parent 0cd7ceb commit 0a9204c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/app/composer/qgscomposerlabelwidget.cpp
Expand Up @@ -34,7 +34,6 @@ QgsComposerLabelWidget::QgsComposerLabelWidget( QgsComposerLabel* label ): QWidg
{
setGuiElementValues();
connect( mComposerLabel, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
connect( mRotationSpinBox, SIGNAL( valueChanged( double ) ), mComposerLabel, SLOT( setRotation( double ) ) );
}
}

Expand Down Expand Up @@ -173,6 +172,17 @@ void QgsComposerLabelWidget::on_mLabelIdLineEdit_textChanged( const QString& tex
}
}

void QgsComposerLabelWidget::on_mRotationSpinBox_valueChanged( double v )
{
if ( mComposerLabel )
{
mComposerLabel->beginCommand( tr( "Label rotation changed" ), QgsComposerMergeCommand::ComposerLabelRotation );
mComposerLabel->setRotation( v );
mComposerLabel->update();
mComposerLabel->endCommand();
}
}

void QgsComposerLabelWidget::setGuiElementValues()
{
blockAllSignals( true );
Expand All @@ -185,6 +195,7 @@ void QgsComposerLabelWidget::setGuiElementValues()
mLeftRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignLeft );
mCenterRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignHCenter );
mRightRadioButton->setChecked( mComposerLabel->hAlign() == Qt::AlignRight );
mRotationSpinBox->setValue( mComposerLabel->rotation() );
blockAllSignals( false );
}

Expand All @@ -198,5 +209,5 @@ void QgsComposerLabelWidget::blockAllSignals( bool block )
mLeftRadioButton->blockSignals( block );
mCenterRadioButton->blockSignals( block );
mRightRadioButton->blockSignals( block );

mRotationSpinBox->blockSignals( block );
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposerlabelwidget.h
Expand Up @@ -43,6 +43,7 @@ class QgsComposerLabelWidget: public QWidget, private Ui::QgsComposerLabelWidget
void on_mBottomRadioButton_clicked();
void on_mMiddleRadioButton_clicked();
void on_mLabelIdLineEdit_textChanged( const QString& text );
void on_mRotationSpinBox_valueChanged( double v );

private slots:
void setGuiElementValues();
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposeritemcommand.h
Expand Up @@ -72,6 +72,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
ComposerLabelRotation,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
Expand Down
25 changes: 20 additions & 5 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -49,15 +49,17 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*

//support multiline labels
double penWidth = pen().widthF();
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin,
rect().height() - 2 * penWidth - 2 * mMargin );

QRectF painterRect( penWidth + mMargin, penWidth + mMargin, mTextBoxWidth - 2 * penWidth - 2 * mMargin, mTextBoxHeight - 2 * penWidth - 2 * mMargin );
painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
painter->rotate( mRotation );
painter->translate( -mTextBoxWidth / 2.0, -mTextBoxHeight / 2.0 );

//debug
painter->setPen( QColor( Qt::red ) );
painter->drawRect( painterRect );
drawText( painter, painterRect, displayText(), mFont, mHAlignment, mVAlignment );


painter->restore();

drawFrame( painter );
Expand Down Expand Up @@ -119,7 +121,7 @@ void QgsComposerLabel::adjustSizeToText()

sizeChangedByRotation( width, height );

setSceneRect( QRectF( transform().dx(), transform().dy(), width, height ) );
QgsComposerItem::setSceneRect( QRectF( transform().dx(), transform().dy(), width, height ) );
}

QFont QgsComposerLabel::font() const
Expand All @@ -131,12 +133,25 @@ void QgsComposerLabel::setRotation( double r )
{
double width = mTextBoxWidth;
double height = mTextBoxHeight;
QgsComposerItem::setRotation( r );
sizeChangedByRotation( width, height );

double x = transform().dx() + rect().width() / 2.0 - width / 2.0;
double y = transform().dy() + rect().height() / 2.0 - height / 2.0;
QgsComposerItem::setSceneRect( QRectF( x, y, width, height ) );
QgsComposerItem::setRotation( r );
}

void QgsComposerLabel::setSceneRect( const QRectF& rectangle )
{
if ( rectangle.width() != rect().width() || rectangle.height() != rect().height() )
{
double textBoxWidth = rectangle.width();
double textBoxHeight = rectangle.height();
imageSizeConsideringRotation( textBoxWidth, textBoxHeight );
mTextBoxWidth = textBoxWidth;
mTextBoxHeight = textBoxHeight;
}
QgsComposerItem::setSceneRect( rectangle );
}

bool QgsComposerLabel::writeXML( QDomElement& elem, QDomDocument & doc ) const
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposerlabel.h
Expand Up @@ -77,6 +77,8 @@ class CORE_EXPORT QgsComposerLabel: public QgsComposerItem
@note: this function was added in version 1.4*/
QColor fontColor() const {return mFontColor;}

void setSceneRect( const QRectF& rectangle );

/** stores state in Dom element
* @param elem is Dom element corresponding to 'Composer' tag
* @param doc document
Expand Down

0 comments on commit 0a9204c

Please sign in to comment.