Skip to content

Commit ecf2600

Browse files
committedMay 15, 2014
[composer] Allow for finer control over text rendered with QgsComposerItem::drawText, fixes clipped text when using italic fonts in legend titles
1 parent 25d991c commit ecf2600

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed
 

‎python/core/composer/qgscomposeritem.sip

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,10 @@ class QgsComposerItem : QObject, QGraphicsRectItem
353353
to work around the Qt font bug)*/
354354
void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
355355

356-
/**Like the above, but with a rectangle for multiline text*/
357-
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop ) const;
356+
/**Like the above, but with a rectangle for multiline text
357+
* @param flags allows for passing Qt::TextFlags to control appearance of rendered text
358+
*/
359+
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
358360

359361
/**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
360362
double textWidthMillimeters( const QFont& font, const QString& text ) const;

‎src/core/composer/qgscomposeritem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString&
619619
p->restore();
620620
}
621621

622-
void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment, Qt::AlignmentFlag valignment ) const
622+
void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment, Qt::AlignmentFlag valignment, int flags ) const
623623
{
624624
QFont textFont = scaledFontPixelSize( font );
625625

@@ -630,7 +630,7 @@ void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString&
630630
p->setFont( textFont );
631631
double scaleFactor = 1.0 / FONT_WORKAROUND_SCALE;
632632
p->scale( scaleFactor, scaleFactor );
633-
p->drawText( scaledRect, halignment | valignment | Qt::TextWordWrap, text );
633+
p->drawText( scaledRect, halignment | valignment | flags, text );
634634
p->restore();
635635
}
636636
void QgsComposerItem::drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const

‎src/core/composer/qgscomposeritem.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
313313
to work around the Qt font bug)*/
314314
void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
315315

316-
/**Like the above, but with a rectangle for multiline text*/
317-
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop ) const;
316+
/**Like the above, but with a rectangle for multiline text
317+
* @param flags allows for passing Qt::TextFlags to control appearance of rendered text
318+
*/
319+
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
318320

319321
/**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
320322
double textWidthMillimeters( const QFont& font, const QString& text ) const;

‎src/core/composer/qgscomposerlabel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
152152
//debug
153153
//painter->setPen( QColor( Qt::red ) );
154154
//painter->drawRect( painterRect );
155-
drawText( painter, painterRect, textToDraw, mFont, mHAlignment, mVAlignment );
155+
drawText( painter, painterRect, textToDraw, mFont, mHAlignment, mVAlignment, Qt::TextWordWrap );
156156
}
157157

158158
painter->restore();

‎src/core/composer/qgscomposerlegend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ QSizeF QgsComposerLegend::drawTitle( QPainter* painter, QPointF point, Qt::Align
249249

250250
if ( painter )
251251
{
252-
drawText( painter, r, *titlePart, styleFont( QgsComposerLegendStyle::Title ), halignment, Qt::AlignVCenter );
252+
drawText( painter, r, *titlePart, styleFont( QgsComposerLegendStyle::Title ), halignment, Qt::AlignVCenter, Qt::TextDontClip );
253253
}
254254

255255
//update max width of title

0 commit comments

Comments
 (0)
Please sign in to comment.