21 #include <qapplication.h> 22 #include <qdesktopwidget.h> 26 class QwtTextEngineDict
29 static QwtTextEngineDict &dict();
43 inline const QwtTextEngine *engine( EngineMap::const_iterator &it )
const 52 QwtTextEngineDict &QwtTextEngineDict::dict()
54 static QwtTextEngineDict engineDict;
58 QwtTextEngineDict::QwtTextEngineDict()
61 #ifndef QT_NO_RICHTEXT 66 QwtTextEngineDict::~QwtTextEngineDict()
68 for ( EngineMap::const_iterator it = d_map.constBegin();
69 it != d_map.constEnd(); ++it )
76 const QwtTextEngine *QwtTextEngineDict::textEngine(
const QString& text,
81 for ( EngineMap::const_iterator it = d_map.begin();
82 it != d_map.end(); ++it )
93 EngineMap::const_iterator it = d_map.find( format );
94 if ( it != d_map.end() )
114 EngineMap::const_iterator it = d_map.constFind( format );
115 if ( it != d_map.constEnd() )
117 delete this->engine( it );
118 d_map.remove( format );
121 if ( engine != NULL )
122 d_map.insert( format, engine );
130 EngineMap::const_iterator it = d_map.find( format );
131 if ( it != d_map.end() )
141 renderFlags( Qt::AlignCenter ),
143 borderPen( Qt::NoPen ),
144 backgroundBrush( Qt::NoBrush ),
181 d_data->
textEngine = textEngine( d_data->text, PlainText );
196 d_data->textEngine = textEngine( text, textFormat );
215 delete d_layoutCache;
243 return !( other == *this );
258 d_data->textEngine = textEngine( text, textFormat );
259 d_layoutCache->invalidate();
283 if ( renderFlags != d_data->renderFlags )
285 d_data->renderFlags = renderFlags;
286 d_layoutCache->invalidate();
296 return d_data->renderFlags;
309 setPaintAttribute( PaintUsingTextFont );
329 if ( d_data->paintAttributes & PaintUsingTextFont )
344 d_data->color = color;
345 setPaintAttribute( PaintUsingTextColor );
351 return d_data->color;
365 if ( d_data->paintAttributes & PaintUsingTextColor )
366 return d_data->color;
379 d_data->borderRadius =
qwtMaxF( 0.0, radius );
388 return d_data->borderRadius;
399 d_data->borderPen = pen;
400 setPaintAttribute( PaintBackground );
409 return d_data->borderPen;
420 d_data->backgroundBrush = brush;
421 setPaintAttribute( PaintBackground );
430 return d_data->backgroundBrush;
446 d_data->paintAttributes |= attribute;
448 d_data->paintAttributes &= ~attribute;
461 return d_data->paintAttributes & attribute;
474 d_data->layoutAttributes |= attribute;
476 d_data->layoutAttributes &= ~attribute;
489 return d_data->layoutAttributes | attribute;
501 return heightForWidth( width, QFont() );
517 const QFont font( usedFont( defaultFont ), QApplication::desktop() );
521 if ( d_data->layoutAttributes & MinimumLayout )
524 d_data->textEngine->textMargins( font, d_data->text,
525 left, right, top, bottom );
527 h = d_data->textEngine->heightForWidth(
528 font, d_data->renderFlags, d_data->text,
529 width + left + right );
535 h = d_data->textEngine->heightForWidth(
536 font, d_data->renderFlags, d_data->text, width );
549 return textSize( QFont() );
563 const QFont font( usedFont( defaultFont ), QApplication::desktop() );
565 if ( !d_layoutCache->textSize.isValid()
566 || d_layoutCache->font != font )
568 d_layoutCache->textSize = d_data->textEngine->textSize(
569 font, d_data->renderFlags, d_data->text );
570 d_layoutCache->font = font;
573 QSizeF sz = d_layoutCache->textSize;
575 if ( d_data->layoutAttributes & MinimumLayout )
578 d_data->textEngine->textMargins( font, d_data->text,
579 left, right, top, bottom );
580 sz -= QSizeF( left + right, top + bottom );
594 if ( d_data->paintAttributes & PaintBackground )
596 if ( d_data->borderPen != Qt::NoPen ||
597 d_data->backgroundBrush != Qt::NoBrush )
601 painter->setPen( d_data->borderPen );
602 painter->setBrush( d_data->backgroundBrush );
604 if ( d_data->borderRadius == 0 )
610 painter->setRenderHint( QPainter::Antialiasing,
true );
611 painter->drawRoundedRect( rect,
612 d_data->borderRadius, d_data->borderRadius );
621 if ( d_data->paintAttributes & PaintUsingTextFont )
623 painter->setFont( d_data->font );
626 if ( d_data->paintAttributes & PaintUsingTextColor )
628 if ( d_data->color.isValid() )
629 painter->setPen( d_data->color );
632 QRectF expandedRect = rect;
633 if ( d_data->layoutAttributes & MinimumLayout )
638 const QFont font( painter->font(), QApplication::desktop() );
641 d_data->textEngine->textMargins(
642 font, d_data->text, left, right, top, bottom );
644 expandedRect.setTop( rect.top() -
top );
645 expandedRect.setBottom( rect.bottom() + bottom );
646 expandedRect.setLeft( rect.left() -
left );
647 expandedRect.setRight( rect.right() +
right );
650 d_data->textEngine->draw( painter, expandedRect,
651 d_data->renderFlags, d_data->text );
674 return QwtTextEngineDict::dict().textEngine( text, format );
693 QwtTextEngineDict::dict().setTextEngine( format, engine );
706 return QwtTextEngineDict::dict().textEngine( format );
712 return d_data->text.isNull();
718 return d_data->text.isEmpty();
QFlags< LayoutAttribute > LayoutAttributes
Layout attributes.
virtual bool mightRender(const QString &text) const =0
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
QwtText::PaintAttributes paintAttributes
void setFont(const QFont &)
void setRenderFlags(int)
Change the render flags.
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
QWT_CONSTEXPR float qwtMaxF(float a, float b)
void setBorderPen(const QPen &)
static const QwtTextEngine * textEngine(const QString &text, QwtText::TextFormat=AutoText)
Use the Scribe framework (Qt Rich Text) to render the text.
bool operator!=(const QwtText &) const
Relational operator.
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
void draw(QPainter *painter, const QRectF &rect) 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
double heightForWidth(double width) const
QwtText::LayoutAttributes layoutAttributes
PaintAttribute
Paint Attributes.
double borderRadius() const
QFont usedFont(const QFont &) const
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)
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
LayoutAttribute
Layout Attributes The layout attributes affects some aspects of the layout of the text...
void setBorderRadius(double)
QBrush backgroundBrush() const
QFont font() const
Return the font.
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.