Skip to content
Permalink
Browse files

Improved label rotation

  • Loading branch information
mhugent committed Jun 29, 2012
1 parent 0cd7ceb commit 0a9204c40dd8ea2ddf8da414c7112b5ee7093f3a
@@ -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 ) ) );
}
}

@@ -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 );
@@ -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 );
}

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

mRotationSpinBox->blockSignals( block );
}
@@ -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();
@@ -72,6 +72,7 @@ class CORE_EXPORT QgsComposerMergeCommand: public QgsComposerItemCommand
//composer label
ComposerLabelSetText,
ComposerLabelSetId,
ComposerLabelRotation,
//composer map
ComposerMapRotation,
ComposerMapAnnotationDistance,
@@ -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 );
@@ -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
@@ -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
@@ -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

0 comments on commit 0a9204c

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