Skip to content
Permalink
Browse files
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 96f236989916de881e67b89d9c95dbc23cda4484
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/core/composer/qgscomposerlabel.cpp
@@ -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() )
@@ -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 )
@@ -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

0 comments on commit 96f2369

Please sign in to comment.