19 #include <qapplication.h> 20 #include <qdesktopwidget.h> 57 #ifndef QT_NO_RICHTEXT 64 for ( EngineMap::const_iterator it =
d_map.constBegin();
65 it !=
d_map.constEnd(); ++it )
77 for ( EngineMap::const_iterator it =
d_map.begin();
78 it !=
d_map.end(); ++it )
89 EngineMap::const_iterator it =
d_map.find( format );
90 if ( it !=
d_map.end() )
110 EngineMap::const_iterator it =
d_map.constFind( format );
111 if ( it !=
d_map.constEnd() )
117 d_map.remove( format );
120 if ( engine != NULL )
121 d_map.insert( format, engine );
129 EngineMap::const_iterator it =
d_map.find( format );
130 if ( it !=
d_map.end() )
140 renderFlags(
Qt::AlignCenter ),
142 borderPen(
Qt::NoPen ),
143 backgroundBrush(
Qt::NoBrush ),
144 paintAttributes( 0 ),
145 layoutAttributes( 0 ),
186 d_data->textEngine =
textEngine( text, textFormat );
205 delete d_layoutCache;
233 return !( other == *this );
248 d_data->textEngine =
textEngine( text, textFormat );
249 d_layoutCache->invalidate();
273 if ( renderFlags != d_data->renderFlags )
275 d_data->renderFlags = renderFlags;
276 d_layoutCache->invalidate();
286 return d_data->renderFlags;
299 setPaintAttribute( PaintUsingTextFont );
319 if ( d_data->paintAttributes & PaintUsingTextFont )
334 d_data->color = color;
335 setPaintAttribute( PaintUsingTextColor );
341 return d_data->color;
355 if ( d_data->paintAttributes & PaintUsingTextColor )
356 return d_data->color;
369 d_data->borderRadius = qMax( 0.0, radius );
378 return d_data->borderRadius;
389 d_data->borderPen = pen;
390 setPaintAttribute( PaintBackground );
399 return d_data->borderPen;
410 d_data->backgroundBrush = brush;
411 setPaintAttribute( PaintBackground );
420 return d_data->backgroundBrush;
436 d_data->paintAttributes |= attribute;
438 d_data->paintAttributes &= ~attribute;
451 return d_data->paintAttributes & attribute;
464 d_data->layoutAttributes |= attribute;
466 d_data->layoutAttributes &= ~attribute;
479 return d_data->layoutAttributes | attribute;
495 const QFont font( usedFont( defaultFont ), QApplication::desktop() );
499 if ( d_data->layoutAttributes & MinimumLayout )
501 double left, right, top, bottom;
502 d_data->textEngine->textMargins( font, d_data->text,
503 left, right, top, bottom );
505 h = d_data->textEngine->heightForWidth(
506 font, d_data->renderFlags, d_data->text,
507 width + left + right );
513 h = d_data->textEngine->heightForWidth(
514 font, d_data->renderFlags, d_data->text, width );
531 const QFont font( usedFont( defaultFont ), QApplication::desktop() );
533 if ( !d_layoutCache->textSize.isValid()
534 || d_layoutCache->font != font )
536 d_layoutCache->textSize = d_data->textEngine->textSize(
537 font, d_data->renderFlags, d_data->text );
538 d_layoutCache->font = font;
541 QSizeF sz = d_layoutCache->textSize;
543 if ( d_data->layoutAttributes & MinimumLayout )
545 double left, right, top, bottom;
546 d_data->textEngine->textMargins( font, d_data->text,
547 left, right, top, bottom );
548 sz -= QSizeF( left + right, top + bottom );
562 if ( d_data->paintAttributes & PaintBackground )
564 if ( d_data->borderPen != Qt::NoPen ||
565 d_data->backgroundBrush != Qt::NoBrush )
569 painter->setPen( d_data->borderPen );
570 painter->setBrush( d_data->backgroundBrush );
572 if ( d_data->borderRadius == 0 )
578 painter->setRenderHint( QPainter::Antialiasing,
true );
579 painter->drawRoundedRect( rect,
580 d_data->borderRadius, d_data->borderRadius );
589 if ( d_data->paintAttributes & PaintUsingTextFont )
591 painter->setFont( d_data->font );
594 if ( d_data->paintAttributes & PaintUsingTextColor )
596 if ( d_data->color.isValid() )
597 painter->setPen( d_data->color );
600 QRectF expandedRect = rect;
601 if ( d_data->layoutAttributes & MinimumLayout )
606 const QFont font( painter->font(), QApplication::desktop() );
608 double left, right, top, bottom;
609 d_data->textEngine->textMargins(
610 font, d_data->text, left, right, top, bottom );
612 expandedRect.setTop( rect.top() - top );
613 expandedRect.setBottom( rect.bottom() + bottom );
614 expandedRect.setLeft( rect.left() - left );
615 expandedRect.setRight( rect.right() + right );
618 d_data->textEngine->draw( painter, expandedRect,
619 d_data->renderFlags, d_data->text );
QFlags< LayoutAttribute > LayoutAttributes
Layout attributes.
virtual bool mightRender(const QString &text) const =0
QwtText::PaintAttributes paintAttributes
void setFont(const QFont &)
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
void setBorderPen(const QPen &)
static const QwtTextEngine * textEngine(const QString &text, QwtText::TextFormat=AutoText)
void setTextEngine(QwtText::TextFormat, QwtTextEngine *)
Use the Scribe framework (Qt Rich Text) to render the text.
bool operator!=(const QwtText &) const
Relational operator.
QwtText(const QString &=QString(), TextFormat textFormat=AutoText)
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
void draw(QPainter *painter, const QRectF &rect) const
const QwtTextEngine * textEngine(QwtText::TextFormat) const
void setColor(const QColor &)
bool testLayoutAttribute(LayoutAttribute) const
static void setTextEngine(QwtText::TextFormat, QwtTextEngine *)
LayoutCache * d_layoutCache
const QwtTextEngine * textEngine
bool testPaintAttribute(PaintAttribute) const
QwtText::LayoutAttributes layoutAttributes
QSizeF textSize(const QFont &=QFont()) const
PaintAttribute
Paint Attributes.
void setRenderFlags(int flags)
Change the render flags.
double borderRadius() const
static void drawRect(QPainter *, double x, double y, double w, double h)
Wrapper for QPainter::drawRect()
QFont usedFont(const QFont &) const
QMap< int, QwtTextEngine * > EngineMap
void setLayoutAttribute(LayoutAttribute, bool on=true)
QColor color() const
Return the pen color, used for painting the text.
A class representing a text.
A text engine for Qt rich texts.
Abstract base class for rendering text strings.
bool operator==(const QwtText &) const
Relational operator.
void setBackgroundBrush(const QBrush &)
void setPaintAttribute(PaintAttribute, bool on=true)
LayoutAttribute
Layout Attributes The layout attributes affects some aspects of the layout of the text...
static QwtTextEngineDict & dict()
void setBorderRadius(double)
QBrush backgroundBrush() const
QFont font() const
Return the font.
const QwtTextEngine * engine(EngineMap::const_iterator &it) const
double heightForWidth(double width, const QFont &=QFont()) const
QColor usedColor(const QColor &) const
Draw the text as it is, using a QwtPlainTextEngine.
A text engine for plain texts.
QwtText & operator=(const QwtText &)
Assignment operator.