Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_text.cpp


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_text.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_painter.h"
    1212#include "qwt_text_engine.h"
     13#include "qwt_math.h"
     14
    1315#include <qmap.h>
    1416#include <qfont.h>
    … …  
    1719#include <qbrush.h>
    1820#include <qpainter.h>
    19 #include <qapplication.h>
    20 #include <qdesktopwidget.h>
    21 #include <qmath.h>
    22 
    23 class QwtTextEngineDict
    24 {
    25 public:
    26     static QwtTextEngineDict &dict();
    27 
    28     void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
    29 
    30     const QwtTextEngine *textEngine( QwtText::TextFormat ) const;
    31     const QwtTextEngine *textEngine( const QString &,
    32         QwtText::TextFormat ) const;
    33 
    34 private:
    35     QwtTextEngineDict();
    36     ~QwtTextEngineDict();
    37 
    38     typedef QMap<int, QwtTextEngine *> EngineMap;
    39 
    40     inline const QwtTextEngine *engine( EngineMap::const_iterator &it ) const
    41     {
    42         return it.value();
    43     }
    44 
    45     EngineMap d_map;
    46 };
    47 
    48 QwtTextEngineDict &QwtTextEngineDict::dict()
    49 {
    50     static QwtTextEngineDict engineDict;
    51     return engineDict;
    52 }
    53 
    54 QwtTextEngineDict::QwtTextEngineDict()
    55 {
    56     d_map.insert( QwtText::PlainText, new QwtPlainTextEngine() );
    57 #ifndef QT_NO_RICHTEXT
    58     d_map.insert( QwtText::RichText, new QwtRichTextEngine() );
     21
     22#if QT_VERSION >= 0x050200
     23
     24static QwtText qwtStringToText( const QString& text )
     25{
     26    return QwtText( text );
     27}
     28
    5929#endif
    60 }
    61 
    62 QwtTextEngineDict::~QwtTextEngineDict()
    63 {
    64     for ( EngineMap::const_iterator it = d_map.constBegin();
    65         it != d_map.constEnd(); ++it )
    66     {
    67         const QwtTextEngine *textEngine = engine( it );
    68         delete textEngine;
    69     }
    70 }
    71 
    72 const QwtTextEngine *QwtTextEngineDict::textEngine( const QString& text,
    73     QwtText::TextFormat format ) const
    74 {
    75     if ( format == QwtText::AutoText )
    76     {
    77         for ( EngineMap::const_iterator it = d_map.begin();
    78             it != d_map.end(); ++it )
     30
     31namespace
     32{
     33    static const struct RegisterQwtText
     34    {
     35        inline RegisterQwtText()
    7936        {
    80             if ( it.key() != QwtText::PlainText )
     37            qRegisterMetaType< QwtText >();
     38
     39#if QT_VERSION >= 0x050200
     40            QMetaType::registerConverter< QString, QwtText >( qwtStringToText );
     41#endif
     42        }
     43
     44    } qwtRegisterQwtText;
     45}
     46
     47namespace
     48{
     49    class TextEngineDict
     50    {
     51      public:
     52        static TextEngineDict& dict();
     53
     54        void setTextEngine( QwtText::TextFormat, QwtTextEngine* );
     55
     56        const QwtTextEngine* textEngine( QwtText::TextFormat ) const;
     57        const QwtTextEngine* textEngine( const QString&,
     58            QwtText::TextFormat ) const;
     59
     60      private:
     61        TextEngineDict();
     62        ~TextEngineDict();
     63
     64        typedef QMap< int, QwtTextEngine* > EngineMap;
     65
     66        inline const QwtTextEngine* engine( EngineMap::const_iterator& it ) const
     67        {
     68            return it.value();
     69        }
     70
     71        EngineMap m_map;
     72    };
     73
     74    TextEngineDict& TextEngineDict::dict()
     75    {
     76        static TextEngineDict engineDict;
     77        return engineDict;
     78    }
     79
     80    TextEngineDict::TextEngineDict()
     81    {
     82        m_map.insert( QwtText::PlainText, new QwtPlainTextEngine() );
     83    #ifndef QT_NO_RICHTEXT
     84        m_map.insert( QwtText::RichText, new QwtRichTextEngine() );
     85    #endif
     86    }
     87
     88    TextEngineDict::~TextEngineDict()
     89    {
     90        for ( EngineMap::const_iterator it = m_map.constBegin();
     91            it != m_map.constEnd(); ++it )
     92        {
     93            const QwtTextEngine* textEngine = engine( it );
     94            delete textEngine;
     95        }
     96    }
     97
     98    const QwtTextEngine* TextEngineDict::textEngine( const QString& text,
     99        QwtText::TextFormat format ) const
     100    {
     101        if ( format == QwtText::AutoText )
     102        {
     103            for ( EngineMap::const_iterator it = m_map.begin();
     104                it != m_map.end(); ++it )
    81105            {
    82                 const QwtTextEngine *e = engine( it );
    83                 if ( e && e->mightRender( text ) )
    84                     return e;
     106                if ( it.key() != QwtText::PlainText )
     107                {
     108                    const QwtTextEngine* e = engine( it );
     109                    if ( e && e->mightRender( text ) )
     110                        return e;
     111                }
    85112            }
    86113        }
    87     }
    88 
    89     EngineMap::const_iterator it = d_map.find( format );
    90     if ( it != d_map.end() )
    91     {
    92         const QwtTextEngine *e = engine( it );
    93         if ( e )
    94             return e;
    95     }
    96 
    97     it = d_map.find( QwtText::PlainText );
    98     return engine( it );
    99 }
    100 
    101 void QwtTextEngineDict::setTextEngine( QwtText::TextFormat format,
    102     QwtTextEngine *engine )
    103 {
    104     if ( format == QwtText::AutoText )
    105         return;
    106 
    107     if ( format == QwtText::PlainText && engine == NULL )
    108         return;
    109 
    110     EngineMap::const_iterator it = d_map.constFind( format );
    111     if ( it != d_map.constEnd() )
    112     {
    113         delete this->engine( it );
    114         d_map.remove( format );
    115     }
    116 
    117     if ( engine != NULL )
    118         d_map.insert( format, engine );
    119 }
    120 
    121 const QwtTextEngine *QwtTextEngineDict::textEngine(
    122     QwtText::TextFormat format ) const
    123 {
    124     const QwtTextEngine *e = NULL;
    125 
    126     EngineMap::const_iterator it = d_map.find( format );
    127     if ( it != d_map.end() )
    128         e = engine( it );
    129 
    130     return e;
     114
     115        EngineMap::const_iterator it = m_map.find( format );
     116        if ( it != m_map.end() )
     117        {
     118            const QwtTextEngine* e = engine( it );
     119            if ( e )
     120                return e;
     121        }
     122
     123        it = m_map.find( QwtText::PlainText );
     124        return engine( it );
     125    }
     126
     127    void TextEngineDict::setTextEngine( QwtText::TextFormat format,
     128        QwtTextEngine* engine )
     129    {
     130        if ( format == QwtText::AutoText )
     131            return;
     132
     133        if ( format == QwtText::PlainText && engine == NULL )
     134            return;
     135
     136        EngineMap::const_iterator it = m_map.constFind( format );
     137        if ( it != m_map.constEnd() )
     138        {
     139            delete this->engine( it );
     140            m_map.remove( format );
     141        }
     142
     143        if ( engine != NULL )
     144            m_map.insert( format, engine );
     145    }
     146
     147    const QwtTextEngine* TextEngineDict::textEngine(
     148        QwtText::TextFormat format ) const
     149    {
     150        const QwtTextEngine* e = NULL;
     151
     152        EngineMap::const_iterator it = m_map.find( format );
     153        if ( it != m_map.end() )
     154            e = engine( it );
     155
     156        return e;
     157    }
    131158}
    132159
    133160class QwtText::PrivateData
    134161{
    135 public:
     162  public:
    136163    PrivateData():
    137164        renderFlags( Qt::AlignCenter ),
    … …  
    139166        borderPen( Qt::NoPen ),
    140167        backgroundBrush( Qt::NoBrush ),
    141         paintAttributes( 0 ),
    142         layoutAttributes( 0 ),
    143168        textEngine( NULL )
    144169    {
    … …  
    156181    QwtText::LayoutAttributes layoutAttributes;
    157182
    158     const QwtTextEngine *textEngine;
     183    const QwtTextEngine* textEngine;
    159184};
    160185
    161186class QwtText::LayoutCache
    162187{
    163 public:
     188  public:
    164189    void invalidate()
    165190    {
    … …  
    173198/*!
    174199   Constructor
     200 */
     201QwtText::QwtText()
     202{
     203    m_data = new PrivateData;
     204    m_data->textEngine = textEngine( m_data->text, PlainText );
     205
     206    m_layoutCache = new LayoutCache;
     207}
     208
     209/*!
     210   Constructor
    175211
    176212   \param text Text content
    177213   \param textFormat Text format
    178 */
    179 QwtText::QwtText( const QString &text, QwtText::TextFormat textFormat )
    180 {
    181     d_data = new PrivateData;
    182     d_data->text = text;
    183     d_data->textEngine = textEngine( text, textFormat );
    184 
    185     d_layoutCache = new LayoutCache;
     214 */
     215QwtText::QwtText( const QString& text, QwtText::TextFormat textFormat )
     216{
     217    m_data = new PrivateData;
     218    m_data->text = text;
     219    m_data->textEngine = textEngine( text, textFormat );
     220
     221    m_layoutCache = new LayoutCache;
    186222}
    187223
    188224//! Copy constructor
    189 QwtText::QwtText( const QwtText &other )
    190 {
    191     d_data = new PrivateData;
    192     *d_data = *other.d_data;
    193 
    194     d_layoutCache = new LayoutCache;
    195     *d_layoutCache = *other.d_layoutCache;
     225QwtText::QwtText( const QwtText& other )
     226{
     227    m_data = new PrivateData;
     228    *m_data = *other.m_data;
     229
     230    m_layoutCache = new LayoutCache;
     231    *m_layoutCache = *other.m_layoutCache;
    196232}
    197233
    … …  
    199235QwtText::~QwtText()
    200236{
    201     delete d_data;
    202     delete d_layoutCache;
     237    delete m_data;
     238    delete m_layoutCache;
    203239}
    204240
    205241//! Assignment operator
    206 QwtText &QwtText::operator=( const QwtText & other )
    207 {
    208     *d_data = *other.d_data;
    209     *d_layoutCache = *other.d_layoutCache;
     242QwtText& QwtText::operator=( const QwtText& other )
     243{
     244    *m_data = *other.m_data;
     245    *m_layoutCache = *other.m_layoutCache;
    210246    return *this;
    211247}
    212248
    213249//! Relational operator
    214 bool QwtText::operator==( const QwtText &other ) const
    215 {
    216     return d_data->renderFlags == other.d_data->renderFlags &&
    217         d_data->text == other.d_data->text &&
    218         d_data->font == other.d_data->font &&
    219         d_data->color == other.d_data->color &&
    220         d_data->borderRadius == other.d_data->borderRadius &&
    221         d_data->borderPen == other.d_data->borderPen &&
    222         d_data->backgroundBrush == other.d_data->backgroundBrush &&
    223         d_data->paintAttributes == other.d_data->paintAttributes &&
    224         d_data->textEngine == other.d_data->textEngine;
     250bool QwtText::operator==( const QwtText& other ) const
     251{
     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;
    225261}
    226262
    227263//! Relational operator
    228 bool QwtText::operator!=( const QwtText &other ) const // invalidate
     264bool QwtText::operator!=( const QwtText& other ) const // invalidate
    229265{
    230266    return !( other == *this );
    … …  
    238274
    239275   \sa text()
    240 */
    241 void QwtText::setText( const QString &text,
     276 */
     277void QwtText::setText( const QString& text,
    242278    QwtText::TextFormat textFormat )
    243279{
    244     d_data->text = text;
    245     d_data->textEngine = textEngine( text, textFormat );
    246     d_layoutCache->invalidate();
     280    m_data->text = text;
     281    m_data->textEngine = textEngine( text, textFormat );
     282    m_layoutCache->invalidate();
    247283}
    248284
    … …  
    250286   \return Text as QString.
    251287   \sa setText()
    252 */
     288 */
    253289QString QwtText::text() const
    254290{
    255     return d_data->text;
     291    return m_data->text;
    256292}
    257293
    … …  
    265301   \sa renderFlags(), QwtTextEngine::draw()
    266302   \note Some renderFlags might have no effect, depending on the text format.
    267 */
     303 */
    268304void QwtText::setRenderFlags( int renderFlags )
    269305{
    270     if ( renderFlags != d_data->renderFlags )
    271     {
    272         d_data->renderFlags = renderFlags;
    273         d_layoutCache->invalidate();
     306    if ( renderFlags != m_data->renderFlags )
     307    {
     308        m_data->renderFlags = renderFlags;
     309        m_layoutCache->invalidate();
    274310    }
    275311}
    … …  
    278314   \return Render flags
    279315   \sa setRenderFlags()
    280 */
     316 */
    281317int QwtText::renderFlags() const
    282318{
    283     return d_data->renderFlags;
     319    return m_data->renderFlags;
    284320}
    285321
    … …  
    290326   \note Setting the font might have no effect, when
    291327         the text contains control sequences for setting fonts.
    292 */
    293 void QwtText::setFont( const QFont &font )
    294 {
    295     d_data->font = font;
     328 */
     329void QwtText::setFont( const QFont& font )
     330{
     331    m_data->font = font;
    296332    setPaintAttribute( PaintUsingTextFont );
    297333}
    … …  
    300336QFont QwtText::font() const
    301337{
    302     return d_data->font;
     338    return m_data->font;
    303339}
    304340
    … …  
    311347
    312348   \sa setFont(), font(), PaintAttributes
    313 */
    314 QFont QwtText::usedFont( const QFont &defaultFont ) const
    315 {
    316     if ( d_data->paintAttributes & PaintUsingTextFont )
    317         return d_data->font;
     349 */
     350QFont QwtText::usedFont( const QFont& defaultFont ) const
     351{
     352    if ( m_data->paintAttributes & PaintUsingTextFont )
     353        return m_data->font;
    318354
    319355    return defaultFont;
    … …  
    326362   \note Setting the color might have no effect, when
    327363         the text contains control sequences for setting colors.
    328 */
    329 void QwtText::setColor( const QColor &color )
    330 {
    331     d_data->color = color;
     364 */
     365void QwtText::setColor( const QColor& color )
     366{
     367    m_data->color = color;
    332368    setPaintAttribute( PaintUsingTextColor );
    333369}
    … …  
    336372QColor QwtText::color() const
    337373{
    338     return d_data->color;
    339 }
    340 
    341 /*!
    342   Return the color of the text, if it has one.
    343   Otherwise return defaultColor.
    344 
    345   \param defaultColor Default color
    346   \return Color used for drawing the text
    347 
    348   \sa setColor(), color(), PaintAttributes
    349 */
    350 QColor QwtText::usedColor( const QColor &defaultColor ) const
    351 {
    352     if ( d_data->paintAttributes & PaintUsingTextColor )
    353         return d_data->color;
     374    return m_data->color;
     375}
     376
     377/*!
     378   Return the color of the text, if it has one.
     379   Otherwise return defaultColor.
     380
     381   \param defaultColor Default color
     382   \return Color used for drawing the text
     383
     384   \sa setColor(), color(), PaintAttributes
     385 */
     386QColor QwtText::usedColor( const QColor& defaultColor ) const
     387{
     388    if ( m_data->paintAttributes & PaintUsingTextColor )
     389        return m_data->color;
    354390
    355391    return defaultColor;
    … …  
    357393
    358394/*!
    359   Set the radius for the corners of the border frame
    360 
    361   \param radius Radius of a rounded corner
    362   \sa borderRadius(), setBorderPen(), setBackgroundBrush()
    363 */
     395   Set the radius for the corners of the border frame
     396
     397   \param radius Radius of a rounded corner
     398   \sa borderRadius(), setBorderPen(), setBackgroundBrush()
     399 */
    364400void QwtText::setBorderRadius( double radius )
    365401{
    366     d_data->borderRadius = qMax( 0.0, radius );
    367 }
    368 
    369 /*!
    370   \return Radius for the corners of the border frame
    371   \sa setBorderRadius(), borderPen(), backgroundBrush()
    372 */
     402    m_data->borderRadius = qwtMaxF( 0.0, radius );
     403}
     404
     405/*!
     406   \return Radius for the corners of the border frame
     407   \sa setBorderRadius(), borderPen(), backgroundBrush()
     408 */
    373409double QwtText::borderRadius() const
    374410{
    375     return d_data->borderRadius;
     411    return m_data->borderRadius;
    376412}
    377413
    … …  
    381417   \param pen Background pen
    382418   \sa borderPen(), setBackgroundBrush()
    383 */
    384 void QwtText::setBorderPen( const QPen &pen )
    385 {
    386     d_data->borderPen = pen;
     419 */
     420void QwtText::setBorderPen( const QPen& pen )
     421{
     422    m_data->borderPen = pen;
    387423    setPaintAttribute( PaintBackground );
    388424}
    … …  
    391427   \return Background pen
    392428   \sa setBorderPen(), backgroundBrush()
    393 */
     429 */
    394430QPen QwtText::borderPen() const
    395431{
    396     return d_data->borderPen;
     432    return m_data->borderPen;
    397433}
    398434
    … …  
    402438   \param brush Background brush
    403439   \sa backgroundBrush(), setBorderPen()
    404 */
    405 void QwtText::setBackgroundBrush( const QBrush &brush )
    406 {
    407     d_data->backgroundBrush = brush;
     440 */
     441void QwtText::setBackgroundBrush( const QBrush& brush )
     442{
     443    m_data->backgroundBrush = brush;
    408444    setPaintAttribute( PaintBackground );
    409445}
    … …  
    412448   \return Background brush
    413449   \sa setBackgroundBrush(), borderPen()
    414 */
     450 */
    415451QBrush QwtText::backgroundBrush() const
    416452{
    417     return d_data->backgroundBrush;
     453    return m_data->backgroundBrush;
    418454}
    419455
    … …  
    427463         setBorderPen() and setBackgroundBrush()
    428464   \sa testPaintAttribute()
    429 */
     465 */
    430466void QwtText::setPaintAttribute( PaintAttribute attribute, bool on )
    431467{
    432468    if ( on )
    433         d_data->paintAttributes |= attribute;
     469        m_data->paintAttributes |= attribute;
    434470    else
    435         d_data->paintAttributes &= ~attribute;
     471        m_data->paintAttributes &= ~attribute;
    436472}
    437473
    … …  
    443479
    444480   \sa setPaintAttribute()
    445 */
     481 */
    446482bool QwtText::testPaintAttribute( PaintAttribute attribute ) const
    447483{
    448     return d_data->paintAttributes & attribute;
     484    return m_data->paintAttributes & attribute;
    449485}
    450486
    … …  
    455491   \param on On/Off
    456492   \sa testLayoutAttribute()
    457 */
     493 */
    458494void QwtText::setLayoutAttribute( LayoutAttribute attribute, bool on )
    459495{
    460496    if ( on )
    461         d_data->layoutAttributes |= attribute;
     497        m_data->layoutAttributes |= attribute;
    462498    else
    463         d_data->layoutAttributes &= ~attribute;
     499        m_data->layoutAttributes &= ~attribute;
    464500}
    465501
    … …  
    471507
    472508   \sa setLayoutAttribute()
    473 */
     509 */
    474510bool QwtText::testLayoutAttribute( LayoutAttribute attribute ) const
    475511{
    476     return d_data->layoutAttributes | attribute;
     512    return m_data->layoutAttributes | attribute;
     513}
     514
     515/*!
     516   Find the height for a given width
     517
     518   \param width Width
     519   \return Calculated height
     520 */
     521
     522double QwtText::heightForWidth( double width ) const
     523{
     524    return heightForWidth( width, QFont() );
    477525}
    478526
    … …  
    484532
    485533   \return Calculated height
    486 */
    487 double QwtText::heightForWidth( double width, const QFont &defaultFont ) const
     534 */
     535double QwtText::heightForWidth( double width, const QFont& defaultFont ) const
    488536{
    489537    // We want to calculate in screen metrics. So
    490538    // we need a font that uses screen metrics
    491539
    492     const QFont font( usedFont( defaultFont ), QApplication::desktop() );
     540    const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) );
    493541
    494542    double h = 0;
    495543
    496     if ( d_data->layoutAttributes & MinimumLayout )
     544    if ( m_data->layoutAttributes & MinimumLayout )
    497545    {
    498546        double left, right, top, bottom;
    499         d_data->textEngine->textMargins( font, d_data->text,
     547        m_data->textEngine->textMargins( font, m_data->text,
    500548            left, right, top, bottom );
    501549
    502         h = d_data->textEngine->heightForWidth(
    503             font, d_data->renderFlags, d_data->text,
     550        h = m_data->textEngine->heightForWidth(
     551            font, m_data->renderFlags, m_data->text,
    504552            width + left + right );
    505553
    … …  
    508556    else
    509557    {
    510         h = d_data->textEngine->heightForWidth(
    511             font, d_data->renderFlags, d_data->text, width );
     558        h = m_data->textEngine->heightForWidth(
     559            font, m_data->renderFlags, m_data->text, width );
    512560    }
    513561
    514562    return h;
     563}
     564
     565/*!
     566   Returns the size, that is needed to render text
     567
     568   \return Calculated size
     569 */
     570QSizeF QwtText::textSize() const
     571{
     572    return textSize( QFont() );
    515573}
    516574
    … …  
    520578   \param defaultFont Font of the text
    521579   \return Calculated size
    522 */
    523 QSizeF QwtText::textSize( const QFont &defaultFont ) const
     580 */
     581QSizeF QwtText::textSize( const QFont& defaultFont ) const
    524582{
    525583    // We want to calculate in screen metrics. So
    526584    // we need a font that uses screen metrics
    527585
    528     const QFont font( usedFont( defaultFont ), QApplication::desktop() );
    529 
    530     if ( !d_layoutCache->textSize.isValid()
    531         || d_layoutCache->font != font )
    532     {
    533         d_layoutCache->textSize = d_data->textEngine->textSize(
    534             font, d_data->renderFlags, d_data->text );
    535         d_layoutCache->font = font;
    536     }
    537 
    538     QSizeF sz = d_layoutCache->textSize;
    539 
    540     if ( d_data->layoutAttributes & MinimumLayout )
     586    const QFont font = QwtPainter::scaledFont( usedFont( defaultFont ) );
     587
     588    if ( !m_layoutCache->textSize.isValid()
     589        || m_layoutCache->font != font )
     590    {
     591        m_layoutCache->textSize = m_data->textEngine->textSize(
     592            font, m_data->renderFlags, m_data->text );
     593        m_layoutCache->font = font;
     594    }
     595
     596    QSizeF sz = m_layoutCache->textSize;
     597
     598    if ( m_data->layoutAttributes & MinimumLayout )
    541599    {
    542600        double left, right, top, bottom;
    543         d_data->textEngine->textMargins( font, d_data->text,
     601        m_data->textEngine->textMargins( font, m_data->text,
    544602            left, right, top, bottom );
    545603        sz -= QSizeF( left + right, top + bottom );
    … …  
    554612   \param painter Painter
    555613   \param rect Rectangle
    556 */
    557 void QwtText::draw( QPainter *painter, const QRectF &rect ) const
    558 {
    559     if ( d_data->paintAttributes & PaintBackground )
    560     {
    561         if ( d_data->borderPen != Qt::NoPen ||
    562             d_data->backgroundBrush != Qt::NoBrush )
     614 */
     615void QwtText::draw( QPainter* painter, const QRectF& rect ) const
     616{
     617    if ( m_data->paintAttributes & PaintBackground )
     618    {
     619        if ( m_data->borderPen != Qt::NoPen ||
     620            m_data->backgroundBrush != Qt::NoBrush )
    563621        {
    564622            painter->save();
    565623
    566             painter->setPen( d_data->borderPen );
    567             painter->setBrush( d_data->backgroundBrush );
    568 
    569             if ( d_data->borderRadius == 0 )
     624            painter->setPen( m_data->borderPen );
     625            painter->setBrush( m_data->backgroundBrush );
     626
     627            if ( m_data->borderRadius == 0 )
    570628            {
    571629                QwtPainter::drawRect( painter, rect );
    … …  
    575633                painter->setRenderHint( QPainter::Antialiasing, true );
    576634                painter->drawRoundedRect( rect,
    577                     d_data->borderRadius, d_data->borderRadius );
     635                    m_data->borderRadius, m_data->borderRadius );
    578636            }
    579637
    … …  
    584642    painter->save();
    585643
    586     if ( d_data->paintAttributes & PaintUsingTextFont )
    587     {
    588         painter->setFont( d_data->font );
    589     }
    590 
    591     if ( d_data->paintAttributes & PaintUsingTextColor )
    592     {
    593         if ( d_data->color.isValid() )
    594             painter->setPen( d_data->color );
     644    if ( m_data->paintAttributes & PaintUsingTextFont )
     645    {
     646        painter->setFont( m_data->font );
     647    }
     648
     649    if ( m_data->paintAttributes & PaintUsingTextColor )
     650    {
     651        if ( m_data->color.isValid() )
     652            painter->setPen( m_data->color );
    595653    }
    596654
    597655    QRectF expandedRect = rect;
    598     if ( d_data->layoutAttributes & MinimumLayout )
     656    if ( m_data->layoutAttributes & MinimumLayout )
    599657    {
    600658        // We want to calculate in screen metrics. So
    601659        // we need a font that uses screen metrics
    602660
    603         const QFont font( painter->font(), QApplication::desktop() );
     661        const QFont font = QwtPainter::scaledFont( painter->font() );
    604662
    605663        double left, right, top, bottom;
    606         d_data->textEngine->textMargins(
    607             font, d_data->text, left, right, top, bottom );
     664        m_data->textEngine->textMargins(
     665            font, m_data->text, left, right, top, bottom );
    608666
    609667        expandedRect.setTop( rect.top() - top );
    … …  
    613671    }
    614672
    615     d_data->textEngine->draw( painter, expandedRect,
    616         d_data->renderFlags, d_data->text );
     673    m_data->textEngine->draw( painter, expandedRect,
     674        m_data->renderFlags, m_data->text );
    617675
    618676    painter->restore();
    … …  
    627685
    628686   If no text engine is registered for the format QwtPlainTextEngine
    629    is returnd.
     687   is returned.
    630688
    631689   \param text Text, needed in case of AutoText
    … …  
    633691
    634692   \return Corresponding text engine
    635 */
    636 const QwtTextEngine *QwtText::textEngine( const QString &text,
     693 */
     694const QwtTextEngine* QwtText::textEngine( const QString& text,
    637695    QwtText::TextFormat format )
    638696{
    639     return QwtTextEngineDict::dict().textEngine( text, format );
     697    return TextEngineDict::dict().textEngine( text, format );
    640698}
    641699
    … …  
    651709   \param engine Text engine
    652710
    653    \sa QwtMathMLTextEngine
    654711   \warning Using QwtText::AutoText does nothing.
    655 */
     712 */
    656713void QwtText::setTextEngine( QwtText::TextFormat format,
    657     QwtTextEngine *engine )
    658 {
    659     QwtTextEngineDict::dict().setTextEngine( format, engine );
     714    QwtTextEngine* engine )
     715{
     716    TextEngineDict::dict().setTextEngine( format, engine );
    660717}
    661718
    … …  
    667724   \param format Text format
    668725   \return The text engine, or NULL if no engine is available.
    669 */
    670 const QwtTextEngine *QwtText::textEngine( QwtText::TextFormat format )
    671 {
    672     return  QwtTextEngineDict::dict().textEngine( format );
    673 }
     726 */
     727const QwtTextEngine* QwtText::textEngine( QwtText::TextFormat format )
     728{
     729    return TextEngineDict::dict().textEngine( format );
     730}
     731
     732//! \return text().isNull()
     733bool QwtText::isNull() const
     734{
     735    return m_data->text.isNull();
     736}
     737
     738//! \return text().isEmpty()
     739bool QwtText::isEmpty() const
     740{
     741    return m_data->text.isEmpty();
     742}
     743
Note: See TracChangeset for help on using the changeset viewer.