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

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1111#include "qwt_text.h"
    1212#include "qwt_painter.h"
     13#include "qwt_math.h"
     14
     15#include <qstyle.h>
     16#include <qstyleoption.h>
    1317#include <qpainter.h>
    1418#include <qevent.h>
    15 #include <qmath.h>
     19#include <qmargins.h>
    1620
    1721class QwtTextLabel::PrivateData
    1822{
    19 public:
    20     PrivateData():
    21         indent( 4 ),
    22         margin( 0 )
     23  public:
     24    PrivateData()
     25        : indent( 4 )
     26        , margin( 0 )
    2327    {
    2428    }
    … …  
    3034
    3135/*!
    32   Constructs an empty label.
    33   \param parent Parent widget
    34 */
    35 QwtTextLabel::QwtTextLabel( QWidget *parent ):
    36     QFrame( parent )
     36   Constructs an empty label.
     37   \param parent Parent widget
     38 */
     39QwtTextLabel::QwtTextLabel( QWidget* parent )
     40    : QFrame( parent )
    3741{
    3842    init();
    … …  
    4044
    4145/*!
    42   Constructs a label that displays the text, text
    43   \param parent Parent widget
    44   \param text Text
    45 */
    46 QwtTextLabel::QwtTextLabel( const QwtText &text, QWidget *parent ):
    47     QFrame( parent )
     46   Constructs a label that displays the text, text
     47   \param parent Parent widget
     48   \param text Text
     49 */
     50QwtTextLabel::QwtTextLabel( const QwtText& text, QWidget* parent )
     51    : QFrame( parent )
    4852{
    4953    init();
    50     d_data->text = text;
     54    m_data->text = text;
    5155}
    5256
    … …  
    5458QwtTextLabel::~QwtTextLabel()
    5559{
    56     delete d_data;
     60    delete m_data;
    5761}
    5862
    5963void QwtTextLabel::init()
    6064{
    61     d_data = new PrivateData();
     65    m_data = new PrivateData();
    6266    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
    6367}
    … …  
    6771   \sa plainText()
    6872 */
    69 void QwtTextLabel::setPlainText( const QString &text )
     73void QwtTextLabel::setPlainText( const QString& text )
    7074{
    7175    setText( QwtText( text ) );
    … …  
    8084QString QwtTextLabel::plainText() const
    8185{
    82     return d_data->text.text();
     86    return m_data->text.text();
    8387}
    8488
    … …  
    8892   \param textFormat Format of text
    8993
    90   \sa QwtText
    91 */
    92 void QwtTextLabel::setText( const QString &text,
     94   \sa QwtText
     95 */
     96void QwtTextLabel::setText( const QString& text,
    9397    QwtText::TextFormat textFormat )
    9498{
    95     d_data->text.setText( text, textFormat );
     99    m_data->text.setText( text, textFormat );
    96100
    97101    update();
    … …  
    102106   Change the label's text
    103107   \param text New text
    104 */
    105 void QwtTextLabel::setText( const QwtText &text )
    106 {
    107     d_data->text = text;
     108 */
     109void QwtTextLabel::setText( const QwtText& text )
     110{
     111    m_data->text = text;
    108112
    109113    update();
    … …  
    112116
    113117//! Return the text
    114 const QwtText &QwtTextLabel::text() const
    115 {
    116     return d_data->text;
     118const QwtText& QwtTextLabel::text() const
     119{
     120    return m_data->text;
    117121}
    118122
    … …  
    120124void QwtTextLabel::clear()
    121125{
    122     d_data->text = QwtText();
     126    m_data->text = QwtText();
    123127
    124128    update();
    … …  
    129133int QwtTextLabel::indent() const
    130134{
    131     return d_data->indent;
    132 }
    133 
    134 /*!
    135   Set label's text indent in pixels
    136   \param indent Indentation in pixels
    137 */
     135    return m_data->indent;
     136}
     137
     138/*!
     139   Set label's text indent in pixels
     140   \param indent Indentation in pixels
     141 */
    138142void QwtTextLabel::setIndent( int indent )
    139143{
    … …  
    141145        indent = 0;
    142146
    143     d_data->indent = indent;
     147    m_data->indent = indent;
    144148
    145149    update();
    … …  
    150154int QwtTextLabel::margin() const
    151155{
    152     return d_data->margin;
    153 }
    154 
    155 /*!
    156   Set label's margin in pixels
    157   \param margin Margin in pixels
    158 */
     156    return m_data->margin;
     157}
     158
     159/*!
     160   Set label's margin in pixels
     161   \param margin Margin in pixels
     162 */
    159163void QwtTextLabel::setMargin( int margin )
    160164{
    161     d_data->margin = margin;
     165    m_data->margin = margin;
    162166
    163167    update();
    … …  
    174178QSize QwtTextLabel::minimumSizeHint() const
    175179{
    176     QSizeF sz = d_data->text.textSize( font() );
    177 
    178     int mw = 2 * ( frameWidth() + d_data->margin );
    179     int mh = mw;
    180 
    181     int indent = d_data->indent;
     180    QSizeF sz = m_data->text.textSize( font() );
     181
     182    const QMargins m = contentsMargins();
     183
     184    int mw = m.left() + m.right() + 2 * m_data->margin;
     185    int mh = m.top() + m.bottom() + 2 * m_data->margin;
     186
     187    int indent = m_data->indent;
    182188    if ( indent <= 0 )
    183189        indent = defaultIndent();
    … …  
    185191    if ( indent > 0 )
    186192    {
    187         const int align = d_data->text.renderFlags();
     193        const int align = m_data->text.renderFlags();
    188194        if ( align & Qt::AlignLeft || align & Qt::AlignRight )
    189             mw += d_data->indent;
     195            mw += m_data->indent;
    190196        else if ( align & Qt::AlignTop || align & Qt::AlignBottom )
    191             mh += d_data->indent;
     197            mh += m_data->indent;
    192198    }
    193199
    194200    sz += QSizeF( mw, mh );
    195201
    196     return QSize( qCeil( sz.width() ), qCeil( sz.height() ) );
     202    return QSize( qwtCeil( sz.width() ), qwtCeil( sz.height() ) );
    197203}
    198204
    … …  
    200206   \param width Width
    201207   \return Preferred height for this widget, given the width.
    202 */
     208 */
    203209int QwtTextLabel::heightForWidth( int width ) const
    204210{
    205     const int renderFlags = d_data->text.renderFlags();
    206 
    207     int indent = d_data->indent;
     211    const int renderFlags = m_data->text.renderFlags();
     212
     213    int indent = m_data->indent;
    208214    if ( indent <= 0 )
    209215        indent = defaultIndent();
    210216
    211     width -= 2 * frameWidth();
     217    const QMargins m = contentsMargins();
     218
     219    width -= m.left() + m.right() - 2 * m_data->margin;
    212220    if ( renderFlags & Qt::AlignLeft || renderFlags & Qt::AlignRight )
    213221        width -= indent;
    214222
    215     int height = qCeil( d_data->text.heightForWidth( width, font() ) );
     223    int height = qwtCeil( m_data->text.heightForWidth( width, font() ) );
    216224    if ( ( renderFlags & Qt::AlignTop ) || ( renderFlags & Qt::AlignBottom ) )
    217225        height += indent;
    218226
    219     height += 2 * frameWidth();
     227    height += m.top() + m.bottom() + 2 * m_data->margin;
    220228
    221229    return height;
    … …  
    225233   Qt paint event
    226234   \param event Paint event
    227 */
    228 void QwtTextLabel::paintEvent( QPaintEvent *event )
     235 */
     236void QwtTextLabel::paintEvent( QPaintEvent* event )
    229237{
    230238    QPainter painter( this );
     239    painter.setClipRegion( event->region() );
     240
     241    QStyleOption opt;
     242    opt.initFrom(this);
     243    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
    231244
    232245    if ( !contentsRect().contains( event->rect() ) )
    233246    {
    234         painter.save();
    235247        painter.setClipRegion( event->region() & frameRect() );
    236248        drawFrame( &painter );
    237         painter.restore();
    238249    }
    239250
    … …  
    244255
    245256//! Redraw the text and focus indicator
    246 void QwtTextLabel::drawContents( QPainter *painter )
     257void QwtTextLabel::drawContents( QPainter* painter )
    247258{
    248259    const QRect r = textRect();
    … …  
    266277
    267278//! Redraw the text
    268 void QwtTextLabel::drawText( QPainter *painter, const QRectF &textRect )
    269 {
    270     d_data->text.draw( painter, textRect );
    271 }
    272 
    273 /*!
    274   Calculate geometry for the text in widget coordinates
    275   \return Geometry for the text
    276 */
     279void QwtTextLabel::drawText( QPainter* painter, const QRectF& textRect )
     280{
     281    m_data->text.draw( painter, textRect );
     282}
     283
     284/*!
     285   Calculate geometry for the text in widget coordinates
     286   \return Geometry for the text
     287 */
    277288QRect QwtTextLabel::textRect() const
    278289{
    279290    QRect r = contentsRect();
    280291
    281     if ( !r.isEmpty() && d_data->margin > 0 )
    282     {
    283         r.setRect( r.x() + d_data->margin, r.y() + d_data->margin,
    284             r.width() - 2 * d_data->margin, r.height() - 2 * d_data->margin );
     292    if ( !r.isEmpty() && m_data->margin > 0 )
     293    {
     294        const int m = m_data->margin;
     295        r.adjust( m, m, -m, -m );
    285296    }
    286297
    287298    if ( !r.isEmpty() )
    288299    {
    289         int indent = d_data->indent;
     300        int indent = m_data->indent;
    290301        if ( indent <= 0 )
    291302            indent = defaultIndent();
    … …  
    293304        if ( indent > 0 )
    294305        {
    295             const int renderFlags = d_data->text.renderFlags();
     306            const int renderFlags = m_data->text.renderFlags();
    296307
    297308            if ( renderFlags & Qt::AlignLeft )
     309            {
    298310                r.setX( r.x() + indent );
     311            }
    299312            else if ( renderFlags & Qt::AlignRight )
     313            {
    300314                r.setWidth( r.width() - indent );
     315            }
    301316            else if ( renderFlags & Qt::AlignTop )
     317            {
    302318                r.setY( r.y() + indent );
     319            }
    303320            else if ( renderFlags & Qt::AlignBottom )
     321            {
    304322                r.setHeight( r.height() - indent );
     323            }
    305324        }
    306325    }
    … …  
    315334
    316335    QFont fnt;
    317     if ( d_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
    318         fnt = d_data->text.font();
     336    if ( m_data->text.testPaintAttribute( QwtText::PaintUsingTextFont ) )
     337        fnt = m_data->text.font();
    319338    else
    320339        fnt = font();
    321340
    322     return QFontMetrics( fnt ).width( 'x' ) / 2;
    323 }
    324 
     341    return QwtPainter::horizontalAdvance( QFontMetrics( fnt ), 'x' ) / 2;
     342}
     343
     344#include "moc_qwt_text_label.cpp"
Note: See TracChangeset for help on using the changeset viewer.