mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Fix for multiline labels in composer (ticket #181)
git-svn-id: http://svn.osgeo.org/qgis/trunk@9202 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
9cd3ca94aa
commit
96f2369899
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user