Skip to content

Commit

Permalink
Fix for multiline labels in composer (ticket #181)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9202 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 28, 2008
1 parent 2d4de7b commit b7902ca
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/core/composer/qgscomposerlabel.cpp
Original file line number Diff line number Diff line change
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 b7902ca

Please sign in to comment.