Skip to content
Permalink
Browse files
[composer] Allow for finer control over text rendered with QgsCompose…
…rItem::drawText, fixes clipped text when using italic fonts in legend titles
  • Loading branch information
nyalldawson committed May 15, 2014
1 parent 25d991c commit ecf2600a4e52ef36e2c9309e13cbbee10bf06c33
@@ -353,8 +353,10 @@ class QgsComposerItem : QObject, QGraphicsRectItem
to work around the Qt font bug)*/
void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;

/**Like the above, but with a rectangle for multiline text*/
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop ) const;
/**Like the above, but with a rectangle for multiline text
* @param flags allows for passing Qt::TextFlags to control appearance of rendered text
*/
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;

/**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double textWidthMillimeters( const QFont& font, const QString& text ) const;
@@ -619,7 +619,7 @@ void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString&
p->restore();
}

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

@@ -630,7 +630,7 @@ void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString&
p->setFont( textFont );
double scaleFactor = 1.0 / FONT_WORKAROUND_SCALE;
p->scale( scaleFactor, scaleFactor );
p->drawText( scaledRect, halignment | valignment | Qt::TextWordWrap, text );
p->drawText( scaledRect, halignment | valignment | flags, text );
p->restore();
}
void QgsComposerItem::drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const
@@ -313,8 +313,10 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
to work around the Qt font bug)*/
void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;

/**Like the above, but with a rectangle for multiline text*/
void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop ) const;
/**Like the above, but with a rectangle for multiline text
* @param flags allows for passing Qt::TextFlags to control appearance of rendered text
*/
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;

/**Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE*/
double textWidthMillimeters( const QFont& font, const QString& text ) const;
@@ -152,7 +152,7 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
//debug
//painter->setPen( QColor( Qt::red ) );
//painter->drawRect( painterRect );
drawText( painter, painterRect, textToDraw, mFont, mHAlignment, mVAlignment );
drawText( painter, painterRect, textToDraw, mFont, mHAlignment, mVAlignment, Qt::TextWordWrap );
}

painter->restore();
@@ -249,7 +249,7 @@ QSizeF QgsComposerLegend::drawTitle( QPainter* painter, QPointF point, Qt::Align

if ( painter )
{
drawText( painter, r, *titlePart, styleFont( QgsComposerLegendStyle::Title ), halignment, Qt::AlignVCenter );
drawText( painter, r, *titlePart, styleFont( QgsComposerLegendStyle::Title ), halignment, Qt::AlignVCenter, Qt::TextDontClip );
}

//update max width of title

0 comments on commit ecf2600

Please sign in to comment.