Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_text_engine.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_engine.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_text_engine.h"
    11 #include "qwt_math.h"
    1211#include "qwt_painter.h"
     12
    1313#include <qpainter.h>
    1414#include <qpixmap.h>
    … …  
    2020#include <qabstracttextdocumentlayout.h>
    2121
    22 static QString taggedRichText( const QString &text, int flags )
     22static QString taggedRichText( const QString& text, int flags )
    2323{
    2424    QString richText = text;
    … …  
    2727    if ( flags & Qt::AlignJustify )
    2828    {
    29         richText.prepend( QString::fromLatin1( "<div align=\"justify\">" ) );
    30         richText.append( QString::fromLatin1( "</div>" ) );
     29        richText.prepend( QLatin1String( "<div align=\"justify\">" ) );
     30        richText.append( QLatin1String ( "</div>" ) );
    3131    }
    3232    else if ( flags & Qt::AlignRight )
    3333    {
    34         richText.prepend( QString::fromLatin1( "<div align=\"right\">" ) );
    35         richText.append( QString::fromLatin1( "</div>" ) );
     34        richText.prepend( QLatin1String ( "<div align=\"right\">" ) );
     35        richText.append( QLatin1String ( "</div>" ) );
    3636    }
    3737    else if ( flags & Qt::AlignHCenter )
    3838    {
    39         richText.prepend( QString::fromLatin1( "<div align=\"center\">" ) );
    40         richText.append( QString::fromLatin1( "</div>" ) );
     39        richText.prepend( QLatin1String ( "<div align=\"center\">" ) );
     40        richText.append( QLatin1String ( "</div>" ) );
    4141    }
    4242
    … …  
    4444}
    4545
    46 class QwtRichTextDocument: public QTextDocument
    47 {
    48 public:
    49     QwtRichTextDocument( const QString &text, int flags, const QFont &font )
    50     {
    51         setUndoRedoEnabled( false );
    52         setDefaultFont( font );
    53         setHtml( text );
    54 
    55         // make sure we have a document layout
    56         ( void )documentLayout();
    57 
    58         QTextOption option = defaultTextOption();
    59         if ( flags & Qt::TextWordWrap )
    60             option.setWrapMode( QTextOption::WordWrap );
    61         else
    62             option.setWrapMode( QTextOption::NoWrap );
    63 
    64         option.setAlignment( static_cast<Qt::Alignment>( flags ) );
    65         setDefaultTextOption( option );
    66 
    67         QTextFrame *root = rootFrame();
    68         QTextFrameFormat fm = root->frameFormat();
    69         fm.setBorder( 0 );
    70         fm.setMargin( 0 );
    71         fm.setPadding( 0 );
    72         fm.setBottomMargin( 0 );
    73         fm.setLeftMargin( 0 );
    74         root->setFrameFormat( fm );
    75 
    76         adjustSize();
    77     }
    78 };
     46namespace
     47{
     48    class QwtRichTextDocument : public QTextDocument
     49    {
     50      public:
     51        QwtRichTextDocument( const QString& text, int flags, const QFont& font )
     52        {
     53            setUndoRedoEnabled( false );
     54            setDefaultFont( font );
     55            setHtml( text );
     56
     57            // make sure we have a document layout
     58            ( void )documentLayout();
     59
     60            QTextOption option = defaultTextOption();
     61            if ( flags & Qt::TextWordWrap )
     62                option.setWrapMode( QTextOption::WordWrap );
     63            else
     64                option.setWrapMode( QTextOption::NoWrap );
     65
     66            option.setAlignment( static_cast< Qt::Alignment >( flags ) );
     67            setDefaultTextOption( option );
     68
     69            QTextFrame* root = rootFrame();
     70            QTextFrameFormat fm = root->frameFormat();
     71            fm.setBorder( 0 );
     72            fm.setMargin( 0 );
     73            fm.setPadding( 0 );
     74            fm.setBottomMargin( 0 );
     75            fm.setLeftMargin( 0 );
     76            root->setFrameFormat( fm );
     77
     78            adjustSize();
     79        }
     80    };
     81}
    7982
    8083class QwtPlainTextEngine::PrivateData
    8184{
    82 public:
    83     int effectiveAscent( const QFont &font ) const
     85  public:
     86    int effectiveAscent( const QFont& font ) const
    8487    {
    8588        const QString fontKey = font.key();
    8689
    87         QMap<QString, int>::const_iterator it =
    88             d_ascentCache.constFind( fontKey );
    89 
    90         if ( it != d_ascentCache.constEnd() )
     90        QMap< QString, int >::const_iterator it =
     91            m_ascentCache.constFind( fontKey );
     92
     93        if ( it != m_ascentCache.constEnd() )
    9194            return *it;
    9295
    9396        const int ascent = findAscent( font );
    94         d_ascentCache.insert( fontKey, ascent );
     97        m_ascentCache.insert( fontKey, ascent );
    9598
    9699        return ascent;
    97100    }
    98101
    99 private:
    100     int findAscent( const QFont &font ) const
     102  private:
     103    static int findAscent( const QFont& font )
    101104    {
    102105        static const QString dummy( "E" );
    … …  
    104107
    105108        const QFontMetrics fm( font );
    106         QPixmap pm( fm.width( dummy ), fm.height() );
     109
     110        QPixmap pm( QwtPainter::horizontalAdvance( fm, dummy ), fm.height() );
    107111        pm.fill( white );
    108112
    … …  
    117121        for ( row = 0; row < img.height(); row++ )
    118122        {
    119             const QRgb *line = reinterpret_cast<const QRgb *>(
     123            const QRgb* line = reinterpret_cast< const QRgb* >(
    120124                img.scanLine( row ) );
    121125
    … …  
    131135    }
    132136
    133     mutable QMap<QString, int> d_ascentCache;
     137    mutable QMap< QString, int > m_ascentCache;
    134138};
    135139
    … …  
    147151QwtPlainTextEngine::QwtPlainTextEngine()
    148152{
    149     d_data = new PrivateData;
     153    m_data = new PrivateData;
    150154}
    151155
    … …  
    153157QwtPlainTextEngine::~QwtPlainTextEngine()
    154158{
    155     delete d_data;
     159    delete m_data;
    156160}
    157161
    … …  
    165169
    166170   \return Calculated height
    167 */
     171 */
    168172double QwtPlainTextEngine::heightForWidth( const QFont& font, int flags,
    169         const QString& text, double width ) const
     173    const QString& text, double width ) const
    170174{
    171175    const QFontMetricsF fm( font );
    … …  
    177181
    178182/*!
    179   Returns the size, that is needed to render text
    180 
    181   \param font Font of the text
    182   \param flags Bitwise OR of the flags used like in QPainter::drawText
    183   \param text Text to be rendered
    184 
    185   \return Calculated size
    186 */
    187 QSizeF QwtPlainTextEngine::textSize( const QFont &font,
     183   Returns the size, that is needed to render text
     184
     185   \param font Font of the text
     186   \param flags Bitwise OR of the flags used like in QPainter::drawText
     187   \param text Text to be rendered
     188
     189   \return Calculated size
     190 */
     191QSizeF QwtPlainTextEngine::textSize( const QFont& font,
    188192    int flags, const QString& text ) const
    189193{
    … …  
    196200
    197201/*!
    198   Return margins around the texts
    199 
    200   \param font Font of the text
    201   \param left Return 0
    202   \param right Return 0
    203   \param top Return value for the top margin
    204   \param bottom Return value for the bottom margin
    205 */
    206 void QwtPlainTextEngine::textMargins( const QFont &font, const QString &,
    207     double &left, double &right, double &top, double &bottom ) const
     202   Return margins around the texts
     203
     204   \param font Font of the text
     205   \param left Return 0
     206   \param right Return 0
     207   \param top Return value for the top margin
     208   \param bottom Return value for the bottom margin
     209 */
     210void QwtPlainTextEngine::textMargins( const QFont& font, const QString&,
     211    double& left, double& right, double& top, double& bottom ) const
    208212{
    209213    left = right = top = 0;
    210214
    211215    const QFontMetricsF fm( font );
    212     top = fm.ascent() - d_data->effectiveAscent( font );
     216    top = fm.ascent() - m_data->effectiveAscent( font );
    213217    bottom = fm.descent();
    214218}
    215219
    216220/*!
    217   \brief Draw the text in a clipping rectangle
    218 
    219   A wrapper for QPainter::drawText.
    220 
    221   \param painter Painter
    222   \param rect Clipping rectangle
    223   \param flags Bitwise OR of the flags used like in QPainter::drawText
    224   \param text Text to be rendered
    225 */
    226 void QwtPlainTextEngine::draw( QPainter *painter, const QRectF &rect,
     221   \brief Draw the text in a clipping rectangle
     222
     223   A wrapper for QPainter::drawText.
     224
     225   \param painter Painter
     226   \param rect Clipping rectangle
     227   \param flags Bitwise OR of the flags used like in QPainter::drawText
     228   \param text Text to be rendered
     229 */
     230void QwtPlainTextEngine::draw( QPainter* painter, const QRectF& rect,
    227231    int flags, const QString& text ) const
    228232{
    … …  
    231235
    232236/*!
    233   Test if a string can be rendered by this text engine.
    234   \return Always true. All texts can be rendered by QwtPlainTextEngine
    235 */
    236 bool QwtPlainTextEngine::mightRender( const QString & ) const
     237   Test if a string can be rendered by this text engine.
     238   \return Always true. All texts can be rendered by QwtPlainTextEngine
     239 */
     240bool QwtPlainTextEngine::mightRender( const QString& ) const
    237241{
    238242    return true;
    … …  
    255259
    256260   \return Calculated height
    257 */
     261 */
    258262double QwtRichTextEngine::heightForWidth( const QFont& font, int flags,
    259         const QString& text, double width ) const
     263    const QString& text, double width ) const
    260264{
    261265    QwtRichTextDocument doc( text, flags, font );
    … …  
    266270
    267271/*!
    268   Returns the size, that is needed to render text
    269 
    270   \param font Font of the text
    271   \param flags Bitwise OR of the flags used like in QPainter::drawText()
    272   \param text Text to be rendered
    273 
    274   \return Calculated size
    275 */
    276 
    277 QSizeF QwtRichTextEngine::textSize( const QFont &font,
     272   Returns the size, that is needed to render text
     273
     274   \param font Font of the text
     275   \param flags Bitwise OR of the flags used like in QPainter::drawText()
     276   \param text Text to be rendered
     277
     278   \return Calculated size
     279 */
     280
     281QSizeF QwtRichTextEngine::textSize( const QFont& font,
    278282    int flags, const QString& text ) const
    279283{
    … …  
    292296
    293297/*!
    294   Draw the text in a clipping rectangle
    295 
    296   \param painter Painter
    297   \param rect Clipping rectangle
    298   \param flags Bitwise OR of the flags like in for QPainter::drawText()
    299   \param text Text to be rendered
    300 */
    301 void QwtRichTextEngine::draw( QPainter *painter, const QRectF &rect,
     298   Draw the text in a clipping rectangle
     299
     300   \param painter Painter
     301   \param rect Clipping rectangle
     302   \param flags Bitwise OR of the flags like in for QPainter::drawText()
     303   \param text Text to be rendered
     304 */
     305void QwtRichTextEngine::draw( QPainter* painter, const QRectF& rect,
    302306    int flags, const QString& text ) const
    303307{
    … …  
    313317
    314318   \return Tagged text
    315 */
    316 QString QwtRichTextEngine::taggedText( const QString &text, int flags ) const
     319 */
     320QString QwtRichTextEngine::taggedText( const QString& text, int flags ) const
    317321{
    318322    return taggedRichText( text, flags );
    … …  
    320324
    321325/*!
    322   Test if a string can be rendered by this text engine
    323 
    324   \param text Text to be tested
    325   \return Qt::mightBeRichText(text);
    326 */
    327 bool QwtRichTextEngine::mightRender( const QString &text ) const
     326   Test if a string can be rendered by this text engine
     327
     328   \param text Text to be tested
     329   \return Qt::mightBeRichText(text);
     330 */
     331bool QwtRichTextEngine::mightRender( const QString& text ) const
    328332{
    329333    return Qt::mightBeRichText( text );
    … …  
    331335
    332336/*!
    333   Return margins around the texts
    334 
    335   \param left Return 0
    336   \param right Return 0
    337   \param top Return 0
    338   \param bottom Return 0
    339 */
    340 void QwtRichTextEngine::textMargins( const QFont &, const QString &,
    341     double &left, double &right, double &top, double &bottom ) const
     337   Return margins around the texts
     338
     339   \param left Return 0
     340   \param right Return 0
     341   \param top Return 0
     342   \param bottom Return 0
     343 */
     344void QwtRichTextEngine::textMargins( const QFont&, const QString&,
     345    double& left, double& right, double& top, double& bottom ) const
    342346{
    343347    left = right = top = bottom = 0;
Note: See TracChangeset for help on using the changeset viewer.