[QGIS Commit] r9202 - trunk/qgis/src/core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Aug 28 11:25:02 EDT 2008


Author: mhugent
Date: 2008-08-28 11:25:01 -0400 (Thu, 28 Aug 2008)
New Revision: 9202

Modified:
   trunk/qgis/src/core/composer/qgscomposerlabel.cpp
Log:
Fix for multiline labels in composer (ticket #181)

Modified: trunk/qgis/src/core/composer/qgscomposerlabel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2008-08-28 14:43:41 UTC (rev 9201)
+++ trunk/qgis/src/core/composer/qgscomposerlabel.cpp	2008-08-28 15:25:01 UTC (rev 9202)
@@ -48,8 +48,14 @@
   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::setText( const QString& text )
 {
   mText = text;
-  adjustSizeToText();
 }
 
 void QgsComposerLabel::setFont( const QFont& f )
@@ -76,13 +81,12 @@
   {
     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



More information about the QGIS-commit mailing list