Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for multiline labels in composer (ticket #181)
git-svn-id: http://svn.osgeo.org/qgis/trunk@9202 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 28, 2008
1 parent 9cd3ca9 commit 96f2369
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/composer/qgscomposerlabel.cpp
Expand Up @@ -48,7 +48,13 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
painter->setFont( mFont );

QFontMetricsF fontSize( mFont );
painter->drawText( QPointF( mMargin, mMargin + fontSize.ascent() ), mText );

//support multiline labels
double penWidth = pen().widthF();
QRectF painterRect(penWidth, penWidth, rect().width() - 2 * penWidth, \
rect().height() - 2 * penWidth);
painter->drawText(painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText);


drawFrame( painter );
if ( isSelected() )
Expand All @@ -60,7 +66,6 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
void QgsComposerLabel::setText( const QString& text )
{
mText = text;
adjustSizeToText();
}

void QgsComposerLabel::setFont( const QFont& f )
Expand All @@ -76,13 +81,12 @@ void QgsComposerLabel::setFont( const QFont& f )
{
mFont = f;
}
adjustSizeToText();
}

void QgsComposerLabel::adjustSizeToText()
{
QFontMetricsF fontInfo( mFont );
setSceneRect( QRectF( transform().dx(), transform().dy(), fontInfo.width( mText ) + 2 * mMargin, fontInfo.ascent() + 2 * mMargin ) );
setSceneRect( QRectF( transform().dx(), transform().dy(), fontInfo.width( mText ) + 2 * mMargin + 2 * pen().widthF(), fontInfo.ascent() + 2 * mMargin + 2 * pen().widthF()) );
}

QFont QgsComposerLabel::font() const
Expand Down

0 comments on commit 96f2369

Please sign in to comment.