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

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1010#include "qwt_legend_label.h"
    1111#include "qwt_legend_data.h"
    12 #include "qwt_math.h"
     12#include "qwt_graphic.h"
    1313#include "qwt_painter.h"
    14 #include "qwt_symbol.h"
    15 #include "qwt_graphic.h"
     14#include "qwt.h"
     15
    1616#include <qpainter.h>
    1717#include <qdrawutil.h>
    1818#include <qstyle.h>
    19 #include <qpen.h>
    2019#include <qevent.h>
    2120#include <qstyleoption.h>
    22 #include <qapplication.h>
    2321
    2422static const int ButtonFrame = 2;
    2523static const int Margin = 2;
    2624
    27 static QSize buttonShift( const QwtLegendLabel *w )
     25static QSize buttonShift( const QwtLegendLabel* w )
    2826{
    2927    QStyleOption option;
    30     option.init( w );
     28    option.initFrom( w );
    3129
    3230    const int ph = w->style()->pixelMetric(
    … …  
    3937class QwtLegendLabel::PrivateData
    4038{
    41 public:
    42     PrivateData():
    43         itemMode( QwtLegendData::ReadOnly ),
    44         isDown( false ),
    45         spacing( Margin )
     39  public:
     40    PrivateData()
     41        : itemMode( QwtLegendData::ReadOnly )
     42        , isDown( false )
     43        , spacing( Margin )
    4644    {
    4745    }
    … …  
    5755
    5856/*!
    59   Set the attributes of the legend label
    60 
    61   \param legendData Attributes of the label
    62   \sa data()
    63  */
    64 void QwtLegendLabel::setData( const QwtLegendData &legendData )
    65 {
    66     d_data->legendData = legendData;
     57   Set the attributes of the legend label
     58
     59   \param legendData Attributes of the label
     60   \sa data()
     61 */
     62void QwtLegendLabel::setData( const QwtLegendData& legendData )
     63{
     64    m_data->legendData = legendData;
    6765
    6866    const bool doUpdate = updatesEnabled();
    69     setUpdatesEnabled( false );
     67    if ( doUpdate )
     68        setUpdatesEnabled( false );
    7069
    7170    setText( legendData.title() );
    … …  
    7675
    7776    if ( doUpdate )
    78     {
    7977        setUpdatesEnabled( true );
    80         update();
    81     }
    82 }
    83 
    84 /*!
    85   \return Attributes of the label
    86   \sa setData(), QwtPlotItem::legendData()
    87  */
    88 const QwtLegendData &QwtLegendLabel::data() const
    89 {
    90     return d_data->legendData;
    91 }
    92 
    93 /*!
    94   \param parent Parent widget
    95 */
    96 QwtLegendLabel::QwtLegendLabel( QWidget *parent ):
    97     QwtTextLabel( parent )
    98 {
    99     d_data = new PrivateData;
     78}
     79
     80/*!
     81   \return Attributes of the label
     82   \sa setData(), QwtPlotItem::legendData()
     83 */
     84const QwtLegendData& QwtLegendLabel::data() const
     85{
     86    return m_data->legendData;
     87}
     88
     89/*!
     90   \param parent Parent widget
     91 */
     92QwtLegendLabel::QwtLegendLabel( QWidget* parent )
     93    : QwtTextLabel( parent )
     94{
     95    m_data = new PrivateData;
    10096    setMargin( Margin );
    10197    setIndent( Margin );
    … …  
    105101QwtLegendLabel::~QwtLegendLabel()
    106102{
    107     delete d_data;
    108     d_data = NULL;
     103    delete m_data;
     104    m_data = NULL;
    109105}
    110106
    … …  
    114110   \param text Text label
    115111    \sa QwtTextLabel::text()
    116 */
    117 void QwtLegendLabel::setText( const QwtText &text )
     112 */
     113void QwtLegendLabel::setText( const QwtText& text )
    118114{
    119115    const int flags = Qt::AlignLeft | Qt::AlignVCenter
    … …  
    132128   \param mode Item mode
    133129   \sa itemMode()
    134 */
     130 */
    135131void QwtLegendLabel::setItemMode( QwtLegendData::Mode mode )
    136132{
    137     if ( mode != d_data->itemMode )
    138     {
    139         d_data->itemMode = mode;
    140         d_data->isDown = false;
     133    if ( mode != m_data->itemMode )
     134    {
     135        m_data->itemMode = mode;
     136        m_data->isDown = false;
    141137
    142138        setFocusPolicy( ( mode != QwtLegendData::ReadOnly )
    … …  
    151147   \return Item mode
    152148   \sa setItemMode()
    153 */
     149 */
    154150QwtLegendData::Mode QwtLegendLabel::itemMode() const
    155151{
    156     return d_data->itemMode;
    157 }
    158 
    159 /*!
    160   Assign the icon
    161 
    162   \param icon Pixmap representing a plot item
    163 
    164   \sa icon(), QwtPlotItem::legendIcon()
    165 */
    166 void QwtLegendLabel::setIcon( const QPixmap &icon )
    167 {
    168     d_data->icon = icon;
    169 
    170     int indent = margin() + d_data->spacing;
     152    return m_data->itemMode;
     153}
     154
     155/*!
     156   Assign the icon
     157
     158   \param icon Pixmap representing a plot item
     159
     160   \sa icon(), QwtPlotItem::legendIcon()
     161 */
     162void QwtLegendLabel::setIcon( const QPixmap& icon )
     163{
     164    m_data->icon = icon;
     165
     166    int indent = margin() + m_data->spacing;
    171167    if ( icon.width() > 0 )
    172         indent += icon.width() + d_data->spacing;
     168    {
     169        const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &icon );
     170        indent += icon.width() / devicePixelRatio + m_data->spacing;
     171    }
    173172
    174173    setIndent( indent );
    … …  
    176175
    177176/*!
    178   \return Pixmap representing a plot item
    179   \sa setIcon()
    180 */
     177   \return Pixmap representing a plot item
     178   \sa setIcon()
     179 */
    181180QPixmap QwtLegendLabel::icon() const
    182181{
    183     return d_data->icon;
     182    return m_data->icon;
    184183}
    185184
    … …  
    189188   \param spacing Spacing
    190189   \sa spacing(), QwtTextLabel::margin()
    191 */
     190 */
    192191void QwtLegendLabel::setSpacing( int spacing )
    193192{
    194193    spacing = qMax( spacing, 0 );
    195     if ( spacing != d_data->spacing )
    196     {
    197         d_data->spacing = spacing;
    198 
    199         int indent = margin() + d_data->spacing;
    200         if ( d_data->icon.width() > 0 )
    201             indent += d_data->icon.width() + d_data->spacing;
     194    if ( spacing != m_data->spacing )
     195    {
     196        m_data->spacing = spacing;
     197
     198        int indent = margin() + m_data->spacing;
     199        if ( m_data->icon.width() > 0 )
     200            indent += m_data->icon.width() + m_data->spacing;
    202201
    203202        setIndent( indent );
    … …  
    208207   \return Spacing between icon and text
    209208   \sa setSpacing(), QwtTextLabel::margin()
    210 */
     209 */
    211210int QwtLegendLabel::spacing() const
    212211{
    213     return d_data->spacing;
     212    return m_data->spacing;
    214213}
    215214
    … …  
    219218    \param on check/uncheck
    220219    \sa setItemMode()
    221 */
     220 */
    222221void QwtLegendLabel::setChecked( bool on )
    223222{
    224     if ( d_data->itemMode == QwtLegendData::Checkable )
     223    if ( m_data->itemMode == QwtLegendData::Checkable )
    225224    {
    226225        const bool isBlocked = signalsBlocked();
    … …  
    236235bool QwtLegendLabel::isChecked() const
    237236{
    238     return d_data->itemMode == QwtLegendData::Checkable && isDown();
     237    return m_data->itemMode == QwtLegendData::Checkable && isDown();
    239238}
    240239
    … …  
    242241void QwtLegendLabel::setDown( bool down )
    243242{
    244     if ( down == d_data->isDown )
     243    if ( down == m_data->isDown )
    245244        return;
    246245
    247     d_data->isDown = down;
     246    m_data->isDown = down;
    248247    update();
    249248
    250     if ( d_data->itemMode == QwtLegendData::Clickable )
    251     {
    252         if ( d_data->isDown )
     249    if ( m_data->itemMode == QwtLegendData::Clickable )
     250    {
     251        if ( m_data->isDown )
    253252            Q_EMIT pressed();
    254253        else
    … …  
    259258    }
    260259
    261     if ( d_data->itemMode == QwtLegendData::Checkable )
    262         Q_EMIT checked( d_data->isDown );
     260    if ( m_data->itemMode == QwtLegendData::Checkable )
     261        Q_EMIT checked( m_data->isDown );
    263262}
    264263
    … …  
    266265bool QwtLegendLabel::isDown() const
    267266{
    268     return d_data->isDown;
     267    return m_data->isDown;
    269268}
    270269
    … …  
    273272{
    274273    QSize sz = QwtTextLabel::sizeHint();
    275     sz.setHeight( qMax( sz.height(), d_data->icon.height() + 4 ) );
    276 
    277     if ( d_data->itemMode != QwtLegendData::ReadOnly )
     274    sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) );
     275
     276    if ( m_data->itemMode != QwtLegendData::ReadOnly )
    278277    {
    279278        sz += buttonShift( this );
    280         sz = sz.expandedTo( QApplication::globalStrut() );
     279        sz = qwtExpandedToGlobalStrut( sz );
    281280    }
    282281
    … …  
    285284
    286285//! Paint event
    287 void QwtLegendLabel::paintEvent( QPaintEvent *e )
     286void QwtLegendLabel::paintEvent( QPaintEvent* e )
    288287{
    289288    const QRect cr = contentsRect();
    … …  
    292291    painter.setClipRegion( e->region() );
    293292
    294     if ( d_data->isDown )
     293    if ( m_data->isDown )
    295294    {
    296295        qDrawWinButton( &painter, 0, 0, width(), height(),
    … …  
    300299    painter.save();
    301300
    302     if ( d_data->isDown )
     301    if ( m_data->isDown )
    303302    {
    304303        const QSize shiftSize = buttonShift( this );
    … …  
    310309    drawContents( &painter );
    311310
    312     if ( !d_data->icon.isNull() )
     311    if ( !m_data->icon.isNull() )
    313312    {
    314313        QRect iconRect = cr;
    315314        iconRect.setX( iconRect.x() + margin() );
    316         if ( d_data->itemMode != QwtLegendData::ReadOnly )
     315        if ( m_data->itemMode != QwtLegendData::ReadOnly )
    317316            iconRect.setX( iconRect.x() + ButtonFrame );
    318317
    319         iconRect.setSize( d_data->icon.size() );
     318        const qreal devicePixelRatio = QwtPainter::devicePixelRatio( &m_data->icon );
     319        iconRect.setSize( m_data->icon.size() / devicePixelRatio );
    320320        iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
    321321
    322         painter.drawPixmap( iconRect, d_data->icon );
     322        painter.drawPixmap( iconRect, m_data->icon );
    323323    }
    324324
    … …  
    327327
    328328//! Handle mouse press events
    329 void QwtLegendLabel::mousePressEvent( QMouseEvent *e )
     329void QwtLegendLabel::mousePressEvent( QMouseEvent* e )
    330330{
    331331    if ( e->button() == Qt::LeftButton )
    332332    {
    333         switch ( d_data->itemMode )
     333        switch ( m_data->itemMode )
    334334        {
    335335            case QwtLegendData::Clickable:
    … …  
    350350
    351351//! Handle mouse release events
    352 void QwtLegendLabel::mouseReleaseEvent( QMouseEvent *e )
     352void QwtLegendLabel::mouseReleaseEvent( QMouseEvent* e )
    353353{
    354354    if ( e->button() == Qt::LeftButton )
    355355    {
    356         switch ( d_data->itemMode )
     356        switch ( m_data->itemMode )
    357357        {
    358358            case QwtLegendData::Clickable:
    … …  
    372372
    373373//! Handle key press events
    374 void QwtLegendLabel::keyPressEvent( QKeyEvent *e )
     374void QwtLegendLabel::keyPressEvent( QKeyEvent* e )
    375375{
    376376    if ( e->key() == Qt::Key_Space )
    377377    {
    378         switch ( d_data->itemMode )
     378        switch ( m_data->itemMode )
    379379        {
    380380            case QwtLegendData::Clickable:
    … …  
    398398
    399399//! Handle key release events
    400 void QwtLegendLabel::keyReleaseEvent( QKeyEvent *e )
     400void QwtLegendLabel::keyReleaseEvent( QKeyEvent* e )
    401401{
    402402    if ( e->key() == Qt::Key_Space )
    403403    {
    404         switch ( d_data->itemMode )
     404        switch ( m_data->itemMode )
    405405        {
    406406            case QwtLegendData::Clickable:
    … …  
    420420    QwtTextLabel::keyReleaseEvent( e );
    421421}
     422
     423#include "moc_qwt_legend_label.cpp"
Note: See TracChangeset for help on using the changeset viewer.