11#include "qwt_painter.h" 
   12#include "qwt_text_engine.h" 
   22#if QT_VERSION >= 0x050200 
   24static QwtText qwtStringToText( 
const QString& text )
 
   33    static const struct RegisterQwtText
 
   35        inline RegisterQwtText()
 
   37            qRegisterMetaType< QwtText >();
 
   39#if QT_VERSION >= 0x050200 
   40            QMetaType::registerConverter< QString, QwtText >( qwtStringToText );
 
   52        static TextEngineDict& dict();
 
   66        inline const QwtTextEngine* engine( EngineMap::const_iterator& it )
 const 
   74    TextEngineDict& TextEngineDict::dict()
 
   76        static TextEngineDict engineDict;
 
   80    TextEngineDict::TextEngineDict()
 
   83    #ifndef QT_NO_RICHTEXT 
   88    TextEngineDict::~TextEngineDict()
 
   90        for ( EngineMap::const_iterator it = m_map.constBegin();
 
   91            it != m_map.constEnd(); ++it )
 
   98    const QwtTextEngine* TextEngineDict::textEngine( 
const QString& text,
 
  103            for ( EngineMap::const_iterator it = m_map.begin();
 
  104                it != m_map.end(); ++it )
 
  115        EngineMap::const_iterator it = m_map.find( format );
 
  116        if ( it != m_map.end() )
 
  136        EngineMap::const_iterator it = m_map.constFind( format );
 
  137        if ( it != m_map.constEnd() )
 
  139            delete this->engine( it );
 
  140            m_map.remove( format );
 
  143        if ( engine != NULL )
 
  144            m_map.insert( format, engine );
 
  152        EngineMap::const_iterator it = m_map.find( format );
 
  153        if ( it != m_map.end() )
 
  160class QwtText::PrivateData
 
  164        renderFlags( Qt::AlignCenter ),
 
  166        borderPen( Qt::NoPen ),
 
  167        backgroundBrush( Qt::NoBrush ),
 
  178    QBrush backgroundBrush;
 
  186class QwtText::LayoutCache
 
  203    m_data = 
new PrivateData;
 
  204    m_data->textEngine = textEngine( m_data->text, PlainText );
 
  206    m_layoutCache = 
new LayoutCache;
 
 
  217    m_data = 
new PrivateData;
 
  219    m_data->textEngine = textEngine( text, textFormat );
 
  221    m_layoutCache = 
new LayoutCache;
 
 
  227    m_data = 
new PrivateData;
 
  228    *m_data = *other.m_data;
 
  230    m_layoutCache = 
new LayoutCache;
 
  231    *m_layoutCache = *other.m_layoutCache;
 
 
  238    delete m_layoutCache;
 
 
  244    *m_data = *other.m_data;
 
  245    *m_layoutCache = *other.m_layoutCache;
 
 
  252    return m_data->renderFlags == other.m_data->renderFlags &&
 
  253           m_data->text == other.m_data->text &&
 
  254           m_data->font == other.m_data->font &&
 
  255           m_data->color == other.m_data->color &&
 
  256           m_data->borderRadius == other.m_data->borderRadius &&
 
  257           m_data->borderPen == other.m_data->borderPen &&
 
  258           m_data->backgroundBrush == other.m_data->backgroundBrush &&
 
  259           m_data->paintAttributes == other.m_data->paintAttributes &&
 
  260           m_data->textEngine == other.m_data->textEngine;
 
 
  266    return !( other == *this );
 
 
  281    m_data->textEngine = textEngine( text, textFormat );
 
  282    m_layoutCache->invalidate();
 
 
  306    if ( renderFlags != m_data->renderFlags )
 
  308        m_data->renderFlags = renderFlags;
 
  309        m_layoutCache->invalidate();
 
 
  319    return m_data->renderFlags;
 
 
  332    setPaintAttribute( PaintUsingTextFont );
 
 
  352    if ( m_data->paintAttributes & PaintUsingTextFont )
 
 
  367    m_data->color = color;
 
  368    setPaintAttribute( PaintUsingTextColor );
 
 
  374    return m_data->color;
 
 
  388    if ( m_data->paintAttributes & PaintUsingTextColor )
 
  389        return m_data->color;
 
 
  402    m_data->borderRadius = qwtMaxF( 0.0, radius );
 
 
  411    return m_data->borderRadius;
 
 
  422    m_data->borderPen = pen;
 
  423    setPaintAttribute( PaintBackground );
 
 
  432    return m_data->borderPen;
 
 
  443    m_data->backgroundBrush = brush;
 
  444    setPaintAttribute( PaintBackground );
 
 
  453    return m_data->backgroundBrush;
 
 
  469        m_data->paintAttributes |= attribute;
 
  471        m_data->paintAttributes &= ~attribute;
 
 
  484    return m_data->paintAttributes & attribute;
 
 
  497        m_data->layoutAttributes |= attribute;
 
  499        m_data->layoutAttributes &= ~attribute;
 
 
  512    return m_data->layoutAttributes | attribute;
 
 
  524    return heightForWidth( width, QFont() );
 
 
  544    if ( m_data->layoutAttributes & MinimumLayout )
 
  546        double left, right, top, bottom;
 
  547        m_data->textEngine->textMargins( font, m_data->text,
 
  548            left, right, top, bottom );
 
  550        h = m_data->textEngine->heightForWidth(
 
  551            font, m_data->renderFlags, m_data->text,
 
  552            width + left + right );
 
  558        h = m_data->textEngine->heightForWidth(
 
  559            font, m_data->renderFlags, m_data->text, width );
 
 
  572    return textSize( QFont() );
 
 
  588    if ( !m_layoutCache->textSize.isValid()
 
  589        || m_layoutCache->font != font )
 
  591        m_layoutCache->textSize = m_data->textEngine->textSize(
 
  592            font, m_data->renderFlags, m_data->text );
 
  593        m_layoutCache->font = font;
 
  596    QSizeF sz = m_layoutCache->textSize;
 
  598    if ( m_data->layoutAttributes & MinimumLayout )
 
  600        double left, right, top, bottom;
 
  601        m_data->textEngine->textMargins( font, m_data->text,
 
  602            left, right, top, bottom );
 
  603        sz -= QSizeF( left + right, top + bottom );
 
 
  617    if ( m_data->paintAttributes & PaintBackground )
 
  619        if ( m_data->borderPen != Qt::NoPen ||
 
  620            m_data->backgroundBrush != Qt::NoBrush )
 
  624            painter->setPen( m_data->borderPen );
 
  625            painter->setBrush( m_data->backgroundBrush );
 
  627            if ( m_data->borderRadius == 0 )
 
  633                painter->setRenderHint( QPainter::Antialiasing, 
true );
 
  634                painter->drawRoundedRect( rect,
 
  635                    m_data->borderRadius, m_data->borderRadius );
 
  644    if ( m_data->paintAttributes & PaintUsingTextFont )
 
  646        painter->setFont( m_data->font );
 
  649    if ( m_data->paintAttributes & PaintUsingTextColor )
 
  651        if ( m_data->color.isValid() )
 
  652            painter->setPen( m_data->color );
 
  655    QRectF expandedRect = rect;
 
  656    if ( m_data->layoutAttributes & MinimumLayout )
 
  663        double left, right, top, bottom;
 
  664        m_data->textEngine->textMargins(
 
  665            font, m_data->text, left, right, top, bottom );
 
  667        expandedRect.setTop( rect.top() - top );
 
  668        expandedRect.setBottom( rect.bottom() + bottom );
 
  669        expandedRect.setLeft( rect.left() - left );
 
  670        expandedRect.setRight( rect.right() + right );
 
  673    m_data->textEngine->draw( painter, expandedRect,
 
  674        m_data->renderFlags, m_data->text );
 
 
  697    return TextEngineDict::dict().textEngine( text, format );
 
 
  716    TextEngineDict::dict().setTextEngine( format, engine );
 
 
  729    return TextEngineDict::dict().textEngine( format );
 
 
  735    return m_data->text.isNull();
 
 
  741    return m_data->text.isEmpty();
 
 
static void drawRect(QPainter *, qreal x, qreal y, qreal w, qreal h)
Wrapper for QPainter::drawRect()
static QFont scaledFont(const QFont &, const QPaintDevice *=NULL)
A text engine for plain texts.
A text engine for Qt rich texts.
Abstract base class for rendering text strings.
virtual bool mightRender(const QString &text) const =0
A class representing a text.
static const QwtTextEngine * textEngine(const QString &text, QwtText::TextFormat=AutoText)
LayoutAttribute
Layout Attributes The layout attributes affects some aspects of the layout of the text.
bool operator==(const QwtText &) const
Relational operator.
QBrush backgroundBrush() const
QColor usedColor(const QColor &) const
void setLayoutAttribute(LayoutAttribute, bool on=true)
bool testPaintAttribute(PaintAttribute) const
double borderRadius() const
@ RichText
Use the Scribe framework (Qt Rich Text) to render the text.
@ PlainText
Draw the text as it is, using a QwtPlainTextEngine.
QFont font() const
Return the font.
QColor color() const
Return the pen color, used for painting the text.
void setBorderRadius(double)
QFlags< LayoutAttribute > LayoutAttributes
PaintAttribute
Paint Attributes.
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
void setPaintAttribute(PaintAttribute, bool on=true)
bool operator!=(const QwtText &) const
Relational operator.
void setColor(const QColor &)
void setBorderPen(const QPen &)
void setFont(const QFont &)
QwtText & operator=(const QwtText &)
Assignment operator.
bool testLayoutAttribute(LayoutAttribute) const
void draw(QPainter *painter, const QRectF &rect) const
QFlags< PaintAttribute > PaintAttributes
static void setTextEngine(QwtText::TextFormat, QwtTextEngine *)
void setBackgroundBrush(const QBrush &)
double heightForWidth(double width) const
void setRenderFlags(int)
Change the render flags.
QFont usedFont(const QFont &) const