Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_counter.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_counter.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_arrow_button.h"
     11#include "qwt_counter.h"
     12#include "qwt_painter.h"
    1113#include "qwt_math.h"
    12 #include "qwt_counter.h"
     14
    1315#include <qlayout.h>
    1416#include <qlineedit.h>
    … …  
    1921class QwtCounter::PrivateData
    2022{
    21 public:
    22     PrivateData():
    23         minimum( 0.0 ),
    24         maximum( 0.0 ),
    25         singleStep( 1.0 ),
    26         isValid( false ),
    27         value( 0.0 ),
    28         wrapping( false )
     23  public:
     24    PrivateData()
     25        : minimum( 0.0 )
     26        , maximum( 0.0 )
     27        , singleStep( 1.0 )
     28        , isValid( false )
     29        , value( 0.0 )
     30        , wrapping( false )
    2931    {
    3032        increment[Button1] = 1;
    … …  
    3335    }
    3436
    35     QwtArrowButton *buttonDown[ButtonCnt];
    36     QwtArrowButton *buttonUp[ButtonCnt];
    37     QLineEdit *valueEdit;
     37    QwtArrowButton* buttonDown[ButtonCnt];
     38    QwtArrowButton* buttonUp[ButtonCnt];
     39    QLineEdit* valueEdit;
    3840
    3941    int increment[ButtonCnt];
    … …  
    5153
    5254/*!
    53   The counter is initialized with a range is set to [0.0, 1.0] with
    54   0.01 as single step size. The value is invalid.
    55 
    56   The default number of buttons is set to 2. The default increments are:
    57   \li Button 1: 1 step
    58   \li Button 2: 10 steps
    59   \li Button 3: 100 steps
    60 
    61   \param parent
    62  */
    63 QwtCounter::QwtCounter( QWidget *parent ):
    64     QWidget( parent )
     55   The counter is initialized with a range is set to [0.0, 1.0] with
     56   0.01 as single step size. The value is invalid.
     57
     58   The default number of buttons is set to 2. The default increments are:
     59   \li Button 1: 1 step
     60   \li Button 2: 10 steps
     61   \li Button 3: 100 steps
     62
     63   \param parent
     64 */
     65QwtCounter::QwtCounter( QWidget* parent )
     66    : QWidget( parent )
    6567{
    6668    initCounter();
    … …  
    6971void QwtCounter::initCounter()
    7072{
    71     d_data = new PrivateData;
    72 
    73     QHBoxLayout *layout = new QHBoxLayout( this );
     73    m_data = new PrivateData;
     74
     75    QHBoxLayout* layout = new QHBoxLayout( this );
    7476    layout->setSpacing( 0 );
    75     layout->setMargin( 0 );
     77    layout->setContentsMargins( QMargins() );
    7678
    7779    for ( int i = ButtonCnt - 1; i >= 0; i-- )
    7880    {
    79         QwtArrowButton *btn =
     81        QwtArrowButton* btn =
    8082            new QwtArrowButton( i + 1, Qt::DownArrow, this );
    8183        btn->setFocusPolicy( Qt::NoFocus );
    82         btn->installEventFilter( this );
    8384        layout->addWidget( btn );
    8485
    … …  
    8687        connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
    8788
    88         d_data->buttonDown[i] = btn;
    89     }
    90 
    91     d_data->valueEdit = new QLineEdit( this );
    92     d_data->valueEdit->setReadOnly( false );
    93     d_data->valueEdit->setValidator( new QDoubleValidator( d_data->valueEdit ) );
    94     layout->addWidget( d_data->valueEdit );
    95 
    96     connect( d_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
    97 
    98     layout->setStretchFactor( d_data->valueEdit, 10 );
     89        m_data->buttonDown[i] = btn;
     90    }
     91
     92    m_data->valueEdit = new QLineEdit( this );
     93    m_data->valueEdit->setReadOnly( false );
     94    m_data->valueEdit->setValidator( new QDoubleValidator( m_data->valueEdit ) );
     95    layout->addWidget( m_data->valueEdit );
     96
     97    connect( m_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
     98
     99    layout->setStretchFactor( m_data->valueEdit, 10 );
    99100
    100101    for ( int i = 0; i < ButtonCnt; i++ )
    101102    {
    102         QwtArrowButton *btn =
     103        QwtArrowButton* btn =
    103104            new QwtArrowButton( i + 1, Qt::UpArrow, this );
    104105        btn->setFocusPolicy( Qt::NoFocus );
    105         btn->installEventFilter( this );
    106106        layout->addWidget( btn );
    107107
    … …  
    109109        connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
    110110
    111         d_data->buttonUp[i] = btn;
     111        m_data->buttonUp[i] = btn;
    112112    }
    113113
    … …  
    120120        QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) );
    121121
    122     setFocusProxy( d_data->valueEdit );
     122    setFocusProxy( m_data->valueEdit );
    123123    setFocusPolicy( Qt::StrongFocus );
    124124}
    … …  
    127127QwtCounter::~QwtCounter()
    128128{
    129     delete d_data;
    130 }
    131 
    132 /*!
    133   Set the counter to be in valid/invalid state
    134 
    135   When the counter is set to invalid, no numbers are displayed and
    136   the buttons are disabled.
    137 
    138   \param on If true the counter will be set as valid
    139 
    140   \sa setValue(), isValid()
    141 */
     129    delete m_data;
     130}
     131
     132/*!
     133   Set the counter to be in valid/invalid state
     134
     135   When the counter is set to invalid, no numbers are displayed and
     136   the buttons are disabled.
     137
     138   \param on If true the counter will be set as valid
     139
     140   \sa setValue(), isValid()
     141 */
    142142void QwtCounter::setValid( bool on )
    143143{
    144     if ( on != d_data->isValid )
    145     {
    146         d_data->isValid = on;
     144    if ( on != m_data->isValid )
     145    {
     146        m_data->isValid = on;
    147147
    148148        updateButtons();
    149149
    150         if ( d_data->isValid )
     150        if ( m_data->isValid )
    151151        {
    152152            showNumber( value() );
    … …  
    155155        else
    156156        {
    157             d_data->valueEdit->setText( QString() );
    158         }
    159     }
    160 }
    161 
    162 /*!
    163   \return True, if the value is valid
    164   \sa setValid(), setValue()
     157            m_data->valueEdit->setText( QString() );
     158        }
     159    }
     160}
     161
     162/*!
     163   \return True, if the value is valid
     164   \sa setValid(), setValue()
    165165 */
    166166bool QwtCounter::isValid() const
    167167{
    168     return d_data->isValid;
    169 }
    170 
    171 /*!
    172   \brief Allow/disallow the user to manually edit the value
    173 
    174   \param on True disable editing
    175   \sa isReadOnly()
    176 */
     168    return m_data->isValid;
     169}
     170
     171/*!
     172   \brief Allow/disallow the user to manually edit the value
     173
     174   \param on True disable editing
     175   \sa isReadOnly()
     176 */
    177177void QwtCounter::setReadOnly( bool on )
    178178{
    179     d_data->valueEdit->setReadOnly( on );
     179    m_data->valueEdit->setReadOnly( on );
    180180}
    181181
    182182/*!
    183183   \return True, when the line line edit is read only. (default is no)
    184   \sa setReadOnly()
     184   \sa setReadOnly()
    185185 */
    186186bool QwtCounter::isReadOnly() const
    187187{
    188     return d_data->valueEdit->isReadOnly();
    189 }
    190 
    191 /*!
    192   \brief Set a new value without adjusting to the step raster
    193 
    194   The state of the counter is set to be valid.
    195 
    196   \param value New value
    197 
    198   \sa isValid(), value(), valueChanged()
    199   \warning The value is clipped when it lies outside the range.
    200 */
     188    return m_data->valueEdit->isReadOnly();
     189}
     190
     191/*!
     192   \brief Set a new value without adjusting to the step raster
     193
     194   The state of the counter is set to be valid.
     195
     196   \param value New value
     197
     198   \sa isValid(), value(), valueChanged()
     199   \warning The value is clipped when it lies outside the range.
     200 */
    201201
    202202void QwtCounter::setValue( double value )
    203203{
    204     const double vmin = qMin( d_data->minimum, d_data->maximum );
    205     const double vmax = qMax( d_data->minimum, d_data->maximum );
     204    const double vmin = qwtMinF( m_data->minimum, m_data->maximum );
     205    const double vmax = qwtMaxF( m_data->minimum, m_data->maximum );
    206206
    207207    value = qBound( vmin, value, vmax );
    208208
    209     if ( !d_data->isValid || value != d_data->value )
    210     {
    211         d_data->isValid = true;
    212         d_data->value = value;
     209    if ( !m_data->isValid || value != m_data->value )
     210    {
     211        m_data->isValid = true;
     212        m_data->value = value;
    213213
    214214        showNumber( value );
    … …  
    220220
    221221/*!
    222   \return Current value of the counter
    223   \sa setValue(), valueChanged()
     222   \return Current value of the counter
     223   \sa setValue(), valueChanged()
    224224 */
    225225double QwtCounter::value() const
    226226{
    227     return d_data->value;
    228 }
    229 
    230 /*!
    231   \brief Set the minimum and maximum values
    232 
    233   The maximum is adjusted if necessary to ensure that the range remains valid.
    234   The value might be modified to be inside of the range.
    235 
    236   \param min Minimum value
    237   \param max Maximum value
    238 
    239   \sa minimum(), maximum()
     227    return m_data->value;
     228}
     229
     230/*!
     231   \brief Set the minimum and maximum values
     232
     233   The maximum is adjusted if necessary to ensure that the range remains valid.
     234   The value might be modified to be inside of the range.
     235
     236   \param min Minimum value
     237   \param max Maximum value
     238
     239   \sa minimum(), maximum()
    240240 */
    241241void QwtCounter::setRange( double min, double max )
    242242{
    243     max = qMax( min, max );
    244 
    245     if ( d_data->maximum == max && d_data->minimum == min )
     243    max = qwtMaxF( min, max );
     244
     245    if ( m_data->maximum == max && m_data->minimum == min )
    246246        return;
    247247
    248     d_data->minimum = min;
    249     d_data->maximum = max;
     248    m_data->minimum = min;
     249    m_data->maximum = max;
    250250
    251251    setSingleStep( singleStep() );
    252252
    253     const double value = qBound( min, d_data->value, max );
    254 
    255     if ( value != d_data->value )
    256     {
    257         d_data->value = value;
    258 
    259         if ( d_data->isValid )
     253    const double value = qBound( min, m_data->value, max );
     254
     255    if ( value != m_data->value )
     256    {
     257        m_data->value = value;
     258
     259        if ( m_data->isValid )
    260260        {
    261261            showNumber( value );
    … …  
    268268
    269269/*!
    270   Set the minimum value of the range
    271 
    272   \param value Minimum value
    273   \sa setRange(), setMaximum(), minimum()
    274 
    275   \note The maximum is adjusted if necessary to ensure that the range remains valid.
    276 */
     270   Set the minimum value of the range
     271
     272   \param value Minimum value
     273   \sa setRange(), setMaximum(), minimum()
     274
     275   \note The maximum is adjusted if necessary to ensure that the range remains valid.
     276 */
    277277void QwtCounter::setMinimum( double value )
    278278{
    … …  
    281281
    282282/*!
    283   \return The minimum of the range
    284   \sa setRange(), setMinimum(), maximum()
    285 */
     283   \return The minimum of the range
     284   \sa setRange(), setMinimum(), maximum()
     285 */
    286286double QwtCounter::minimum() const
    287287{
    288     return d_data->minimum;
    289 }
    290 
    291 /*!
    292   Set the maximum value of the range
    293 
    294   \param value Maximum value
    295   \sa setRange(), setMinimum(), maximum()
    296 */
     288    return m_data->minimum;
     289}
     290
     291/*!
     292   Set the maximum value of the range
     293
     294   \param value Maximum value
     295   \sa setRange(), setMinimum(), maximum()
     296 */
    297297void QwtCounter::setMaximum( double value )
    298298{
    … …  
    301301
    302302/*!
    303   \return The maximum of the range
    304   \sa setRange(), setMaximum(), minimum()
    305 */
     303   \return The maximum of the range
     304   \sa setRange(), setMaximum(), minimum()
     305 */
    306306double QwtCounter::maximum() const
    307307{
    308     return d_data->maximum;
    309 }
    310 
    311 /*!
    312   \brief Set the step size of the counter
    313 
    314   A value <= 0.0 disables stepping
    315 
    316   \param stepSize Single step size
    317   \sa singleStep()
    318 */
     308    return m_data->maximum;
     309}
     310
     311/*!
     312   \brief Set the step size of the counter
     313
     314   A value <= 0.0 disables stepping
     315
     316   \param stepSize Single step size
     317   \sa singleStep()
     318 */
    319319void QwtCounter::setSingleStep( double stepSize )
    320320{
    321     d_data->singleStep = qMax( stepSize, 0.0 );
    322 }
    323 
    324 /*!
    325   \return Single step size
    326   \sa setSingleStep()
     321    m_data->singleStep = qwtMaxF( stepSize, 0.0 );
     322}
     323
     324/*!
     325   \return Single step size
     326   \sa setSingleStep()
    327327 */
    328328double QwtCounter::singleStep() const
    329329{
    330     return d_data->singleStep;
    331 }
    332 
    333 /*!
    334   \brief En/Disable wrapping
    335 
    336   If wrapping is true stepping up from maximum() value will take
    337   you to the minimum() value and vice versa.
    338 
    339   \param on En/Disable wrapping
    340   \sa wrapping()
     330    return m_data->singleStep;
     331}
     332
     333/*!
     334   \brief En/Disable wrapping
     335
     336   If wrapping is true stepping up from maximum() value will take
     337   you to the minimum() value and vice versa.
     338
     339   \param on En/Disable wrapping
     340   \sa wrapping()
    341341 */
    342342void QwtCounter::setWrapping( bool on )
    343343{
    344     d_data->wrapping = on;
    345 }
    346 
    347 /*!
    348   \return True, when wrapping is set
    349   \sa setWrapping()
     344    m_data->wrapping = on;
     345}
     346
     347/*!
     348   \return True, when wrapping is set
     349   \sa setWrapping()
    350350 */
    351351bool QwtCounter::wrapping() const
    352352{
    353     return d_data->wrapping;
    354 }
    355 
    356 /*!
    357   Specify the number of buttons on each side of the label
    358 
    359   \param numButtons Number of buttons
    360   \sa numButtons()
    361 */
     353    return m_data->wrapping;
     354}
     355
     356/*!
     357   Specify the number of buttons on each side of the label
     358
     359   \param numButtons Number of buttons
     360   \sa numButtons()
     361 */
    362362void QwtCounter::setNumButtons( int numButtons )
    363363{
    … …  
    369369        if ( i < numButtons )
    370370        {
    371             d_data->buttonDown[i]->show();
    372             d_data->buttonUp[i]->show();
     371            m_data->buttonDown[i]->show();
     372            m_data->buttonUp[i]->show();
    373373        }
    374374        else
    375375        {
    376             d_data->buttonDown[i]->hide();
    377             d_data->buttonUp[i]->hide();
    378         }
    379     }
    380 
    381     d_data->numButtons = numButtons;
    382 }
    383 
    384 /*!
    385   \return The number of buttons on each side of the widget.
    386   \sa setNumButtons()
    387 */
     376            m_data->buttonDown[i]->hide();
     377            m_data->buttonUp[i]->hide();
     378        }
     379    }
     380
     381    m_data->numButtons = numButtons;
     382}
     383
     384/*!
     385   \return The number of buttons on each side of the widget.
     386   \sa setNumButtons()
     387 */
    388388int QwtCounter::numButtons() const
    389389{
    390     return d_data->numButtons;
    391 }
    392 
    393 /*!
    394   Specify the number of steps by which the value
    395   is incremented or decremented when a specified button
    396   is pushed.
    397 
    398   \param button Button index
    399   \param numSteps Number of steps
    400 
    401   \sa incSteps()
    402 */
     390    return m_data->numButtons;
     391}
     392
     393/*!
     394   Specify the number of steps by which the value
     395   is incremented or decremented when a specified button
     396   is pushed.
     397
     398   \param button Button index
     399   \param numSteps Number of steps
     400
     401   \sa incSteps()
     402 */
    403403void QwtCounter::setIncSteps( QwtCounter::Button button, int numSteps )
    404404{
    405405    if ( button >= 0 && button < QwtCounter::ButtonCnt )
    406         d_data->increment[ button ] = numSteps;
    407 }
    408 
    409 /*!
    410   \return The number of steps by which a specified button increments the value
     406        m_data->increment[ button ] = numSteps;
     407}
     408
     409/*!
     410   \return The number of steps by which a specified button increments the value
    411411          or 0 if the button is invalid.
    412   \param button Button index
    413 
    414   \sa setIncSteps()
    415 */
     412   \param button Button index
     413
     414   \sa setIncSteps()
     415 */
    416416int QwtCounter::incSteps( QwtCounter::Button button ) const
    417417{
    418418    if ( button >= 0 && button < QwtCounter::ButtonCnt )
    419         return d_data->increment[ button ];
     419        return m_data->increment[ button ];
    420420
    421421    return 0;
    … …  
    424424
    425425/*!
    426   Set the number of increment steps for button 1
    427   \param nSteps Number of steps
    428 */
     426   Set the number of increment steps for button 1
     427   \param nSteps Number of steps
     428 */
    429429void QwtCounter::setStepButton1( int nSteps )
    430430{
    … …  
    439439
    440440/*!
    441   Set the number of increment steps for button 2
    442   \param nSteps Number of steps
    443 */
     441   Set the number of increment steps for button 2
     442   \param nSteps Number of steps
     443 */
    444444void QwtCounter::setStepButton2( int nSteps )
    445445{
    … …  
    454454
    455455/*!
    456   Set the number of increment steps for button 3
    457   \param nSteps Number of steps
    458 */
     456   Set the number of increment steps for button 3
     457   \param nSteps Number of steps
     458 */
    459459void QwtCounter::setStepButton3( int nSteps )
    460460{
    … …  
    473473    bool converted = false;
    474474
    475     const double value = d_data->valueEdit->text().toDouble( &converted );
     475    const double value = m_data->valueEdit->text().toDouble( &converted );
    476476    if ( converted )
    477477        setValue( value );
    … …  
    482482   \param event Event
    483483   \return see QWidget::event()
    484 */
    485 bool QwtCounter::event( QEvent *event )
     484 */
     485bool QwtCounter::event( QEvent* event )
    486486{
    487487    if ( event->type() == QEvent::PolishRequest )
    488488    {
    489         const int w = d_data->valueEdit->fontMetrics().width( "W" ) + 8;
     489        const QFontMetrics fm = m_data->valueEdit->fontMetrics();
     490
     491        const int w = QwtPainter::horizontalAdvance( fm, "W" ) + 8;
    490492        for ( int i = 0; i < ButtonCnt; i++ )
    491493        {
    492             d_data->buttonDown[i]->setMinimumWidth( w );
    493             d_data->buttonUp[i]->setMinimumWidth( w );
     494            m_data->buttonDown[i]->setMinimumWidth( w );
     495            m_data->buttonUp[i]->setMinimumWidth( w );
    494496        }
    495497    }
    … …  
    499501
    500502/*!
    501   Handle key events
    502 
    503   - Ctrl + Qt::Key_Home\n
     503   Handle key events
     504
     505   - Ctrl + Qt::Key_Home\n
    504506    Step to minimum()
    505   - Ctrl + Qt::Key_End\n
     507   - Ctrl + Qt::Key_End\n
    506508    Step to maximum()
    507   - Qt::Key_Up\n
     509   - Qt::Key_Up\n
    508510    Increment by incSteps(QwtCounter::Button1)
    509   - Qt::Key_Down\n
     511   - Qt::Key_Down\n
    510512    Decrement by incSteps(QwtCounter::Button1)
    511   - Qt::Key_PageUp\n
     513   - Qt::Key_PageUp\n
    512514    Increment by incSteps(QwtCounter::Button2)
    513   - Qt::Key_PageDown\n
     515   - Qt::Key_PageDown\n
    514516    Decrement by incSteps(QwtCounter::Button2)
    515   - Shift + Qt::Key_PageUp\n
     517   - Shift + Qt::Key_PageUp\n
    516518    Increment by incSteps(QwtCounter::Button3)
    517   - Shift + Qt::Key_PageDown\n
     519   - Shift + Qt::Key_PageDown\n
    518520    Decrement by incSteps(QwtCounter::Button3)
    519521
    520   \param event Key event
    521 */
    522 void QwtCounter::keyPressEvent ( QKeyEvent *event )
     522   \param event Key event
     523 */
     524void QwtCounter::keyPressEvent ( QKeyEvent* event )
    523525{
    524526    bool accepted = true;
    … …  
    544546        case Qt::Key_Up:
    545547        {
    546             incrementValue( d_data->increment[0] );
     548            incrementValue( m_data->increment[0] );
    547549            break;
    548550        }
    549551        case Qt::Key_Down:
    550552        {
    551             incrementValue( -d_data->increment[0] );
     553            incrementValue( -m_data->increment[0] );
    552554            break;
    553555        }
    … …  
    555557        case Qt::Key_PageDown:
    556558        {
    557             int increment = d_data->increment[0];
    558             if ( d_data->numButtons >= 2 )
    559                 increment = d_data->increment[1];
    560             if ( d_data->numButtons >= 3 )
     559            int increment = m_data->increment[0];
     560            if ( m_data->numButtons >= 2 )
     561                increment = m_data->increment[1];
     562            if ( m_data->numButtons >= 3 )
    561563            {
    562564                if ( event->modifiers() & Qt::ShiftModifier )
    563                     increment = d_data->increment[2];
     565                    increment = m_data->increment[2];
    564566            }
    565567            if ( event->key() == Qt::Key_PageDown )
    … …  
    584586
    585587/*!
    586   Handle wheel events
    587   \param event Wheel event
    588 */
    589 void QwtCounter::wheelEvent( QWheelEvent *event )
     588   Handle wheel events
     589   \param event Wheel event
     590 */
     591void QwtCounter::wheelEvent( QWheelEvent* event )
    590592{
    591593    event->accept();
    592594
    593     if ( d_data->numButtons <= 0 )
     595    if ( m_data->numButtons <= 0 )
    594596        return;
    595597
    596     int increment = d_data->increment[0];
    597     if ( d_data->numButtons >= 2 )
     598    int increment = m_data->increment[0];
     599    if ( m_data->numButtons >= 2 )
    598600    {
    599601        if ( event->modifiers() & Qt::ControlModifier )
    600             increment = d_data->increment[1];
    601     }
    602     if ( d_data->numButtons >= 3 )
     602            increment = m_data->increment[1];
     603    }
     604    if ( m_data->numButtons >= 3 )
    603605    {
    604606        if ( event->modifiers() & Qt::ShiftModifier )
    605             increment = d_data->increment[2];
    606     }
    607 
    608     for ( int i = 0; i < d_data->numButtons; i++ )
    609     {
    610         if ( d_data->buttonDown[i]->geometry().contains( event->pos() ) ||
    611             d_data->buttonUp[i]->geometry().contains( event->pos() ) )
    612         {
    613             increment = d_data->increment[i];
    614         }
    615     }
    616 
    617     const int wheel_delta = 120;
     607            increment = m_data->increment[2];
     608    }
     609
     610#if QT_VERSION < 0x050e00
     611    const QPoint wheelPos = event->pos();
     612    const int wheelDelta = event->delta();
     613#else
     614    const QPoint wheelPos = event->position().toPoint();
     615
     616    const QPoint delta = event->angleDelta();
     617    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
     618        ? delta.x() : delta.y();
     619#endif
     620
     621    for ( int i = 0; i < m_data->numButtons; i++ )
     622    {
     623        if ( m_data->buttonDown[i]->geometry().contains( wheelPos ) ||
     624            m_data->buttonUp[i]->geometry().contains( wheelPos ) )
     625        {
     626            increment = m_data->increment[i];
     627        }
     628    }
     629
     630    incrementValue( wheelDelta / 120 * increment );
     631}
     632
     633void QwtCounter::incrementValue( int numSteps )
     634{
     635    const double min = m_data->minimum;
     636    const double max = m_data->maximum;
     637    double stepSize = m_data->singleStep;
     638
     639    if ( !m_data->isValid || min >= max || stepSize <= 0.0 )
     640        return;
     641
    618642
    619643#if 1
    620     int delta = event->delta();
    621     if ( delta >= 2 * wheel_delta )
    622         delta /= 2; // Never saw an abs(delta) < 240
     644    stepSize = qwtMaxF( stepSize, 1.0e-10 * ( max - min ) );
    623645#endif
    624646
    625     incrementValue( delta / wheel_delta * increment );
    626 }
    627 
    628 void QwtCounter::incrementValue( int numSteps )
    629 {
    630     const double min = d_data->minimum;
    631     const double max = d_data->maximum;
    632     double stepSize = d_data->singleStep;
    633 
    634     if ( !d_data->isValid || min >= max || stepSize <= 0.0 )
    635         return;
    636 
    637 
    638 #if 1
    639     stepSize = qMax( stepSize, 1.0e-10 * ( max - min ) );
    640 #endif
    641 
    642     double value = d_data->value + numSteps * stepSize;
    643 
    644     if ( d_data->wrapping )
     647    double value = m_data->value + numSteps * stepSize;
     648
     649    if ( m_data->wrapping )
    645650    {
    646651        const double range = max - min;
    … …  
    648653        if ( value < min )
    649654        {
    650             value += ::ceil( ( min - value ) / range ) * range;
     655            value += std::ceil( ( min - value ) / range ) * range;
    651656        }
    652657        else if ( value > max )
    653658        {
    654             value -= ::ceil( ( value - max ) / range ) * range;
     659            value -= std::ceil( ( value - max ) / range ) * range;
    655660        }
    656661    }
    … …  
    676681    }
    677682
    678     if ( value != d_data->value )
    679     {
    680         d_data->value = value;
    681         showNumber( d_data->value );
     683    if ( value != m_data->value )
     684    {
     685        m_data->value = value;
     686        showNumber( m_data->value );
    682687        updateButtons();
    683688
    684         Q_EMIT valueChanged( d_data->value );
    685     }
    686 }
    687 
    688 
    689 /*!
    690   \brief Update buttons according to the current value
    691 
    692   When the QwtCounter under- or over-flows, the focus is set to the smallest
    693   up- or down-button and counting is disabled.
    694 
    695   Counting is re-enabled on a button release event (mouse or space bar).
    696 */
     689        Q_EMIT valueChanged( m_data->value );
     690    }
     691}
     692
     693
     694/*!
     695   \brief Update buttons according to the current value
     696
     697   When the QwtCounter under- or over-flows, the focus is set to the smallest
     698   up- or down-button and counting is disabled.
     699
     700   Counting is re-enabled on a button release event (mouse or space bar).
     701 */
    697702void QwtCounter::updateButtons()
    698703{
    699     if ( d_data->isValid )
     704    if ( m_data->isValid )
    700705    {
    701706        // 1. save enabled state of the smallest down- and up-button
    … …  
    704709        for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
    705710        {
    706             d_data->buttonDown[i]->setEnabled( value() > minimum() );
    707             d_data->buttonUp[i]->setEnabled( value() < maximum() );
     711            m_data->buttonDown[i]->setEnabled( value() > minimum() );
     712            m_data->buttonUp[i]->setEnabled( value() < maximum() );
    708713        }
    709714    }
    … …  
    712717        for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
    713718        {
    714             d_data->buttonDown[i]->setEnabled( false );
    715             d_data->buttonUp[i]->setEnabled( false );
    716         }
    717     }
    718 }
    719 /*!
    720   Display number string
    721 
    722   \param number Number
    723 */
     719            m_data->buttonDown[i]->setEnabled( false );
     720            m_data->buttonUp[i]->setEnabled( false );
     721        }
     722    }
     723}
     724/*!
     725   Display number string
     726
     727   \param number Number
     728 */
    724729void QwtCounter::showNumber( double number )
    725730{
    … …  
    727732    text.setNum( number );
    728733
    729     const int cursorPos = d_data->valueEdit->cursorPosition();
    730     d_data->valueEdit->setText( text );
    731     d_data->valueEdit->setCursorPosition( cursorPos );
     734    const int cursorPos = m_data->valueEdit->cursorPosition();
     735    m_data->valueEdit->setText( text );
     736    m_data->valueEdit->setCursorPosition( cursorPos );
    732737}
    733738
    … …  
    737742    for ( int i = 0; i < ButtonCnt; i++ )
    738743    {
    739         if ( d_data->buttonUp[i] == sender() )
    740             incrementValue( d_data->increment[i] );
    741 
    742         if ( d_data->buttonDown[i] == sender() )
    743             incrementValue( -d_data->increment[i] );
     744        if ( m_data->buttonUp[i] == sender() )
     745            incrementValue( m_data->increment[i] );
     746
     747        if ( m_data->buttonDown[i] == sender() )
     748            incrementValue( -m_data->increment[i] );
    744749    }
    745750}
    … …  
    769774    tmp.fill( '9', w );
    770775
    771     QFontMetrics fm( d_data->valueEdit->font() );
    772     w = fm.width( tmp ) + 2;
    773     if ( d_data->valueEdit->hasFrame() )
     776    w = QwtPainter::horizontalAdvance( m_data->valueEdit->fontMetrics(), tmp ) + 2;
     777
     778    if ( m_data->valueEdit->hasFrame() )
    774779        w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
    775780
    776     // Now we replace default sizeHint contribution of d_data->valueEdit by
     781    // Now we replace default sizeHint contribution of m_data->valueEdit by
    777782    // what we really need.
    778783
    779     w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();
     784    w += QWidget::sizeHint().width() - m_data->valueEdit->sizeHint().width();
    780785
    781786    const int h = qMin( QWidget::sizeHint().height(),
    782         d_data->valueEdit->minimumSizeHint().height() );
     787        m_data->valueEdit->minimumSizeHint().height() );
     788
    783789    return QSize( w, h );
    784790}
     791
     792#include "moc_qwt_counter.cpp"
Note: See TracChangeset for help on using the changeset viewer.