Index: trunk/BNC/qwt/qwt_counter.cpp
===================================================================
--- trunk/BNC/qwt/qwt_counter.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_counter.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -9,6 +9,8 @@
 
 #include "qwt_arrow_button.h"
+#include "qwt_counter.h"
+#include "qwt_painter.h"
 #include "qwt_math.h"
-#include "qwt_counter.h"
+
 #include <qlayout.h>
 #include <qlineedit.h>
@@ -19,12 +21,12 @@
 class QwtCounter::PrivateData
 {
-public:
-    PrivateData():
-        minimum( 0.0 ),
-        maximum( 0.0 ),
-        singleStep( 1.0 ),
-        isValid( false ),
-        value( 0.0 ),
-        wrapping( false )
+  public:
+    PrivateData()
+        : minimum( 0.0 )
+        , maximum( 0.0 )
+        , singleStep( 1.0 )
+        , isValid( false )
+        , value( 0.0 )
+        , wrapping( false )
     {
         increment[Button1] = 1;
@@ -33,7 +35,7 @@
     }
 
-    QwtArrowButton *buttonDown[ButtonCnt];
-    QwtArrowButton *buttonUp[ButtonCnt];
-    QLineEdit *valueEdit;
+    QwtArrowButton* buttonDown[ButtonCnt];
+    QwtArrowButton* buttonUp[ButtonCnt];
+    QLineEdit* valueEdit;
 
     int increment[ButtonCnt];
@@ -51,16 +53,16 @@
 
 /*!
-  The counter is initialized with a range is set to [0.0, 1.0] with
-  0.01 as single step size. The value is invalid.
-
-  The default number of buttons is set to 2. The default increments are:
-  \li Button 1: 1 step
-  \li Button 2: 10 steps
-  \li Button 3: 100 steps
-
-  \param parent
- */
-QwtCounter::QwtCounter( QWidget *parent ):
-    QWidget( parent )
+   The counter is initialized with a range is set to [0.0, 1.0] with
+   0.01 as single step size. The value is invalid.
+
+   The default number of buttons is set to 2. The default increments are:
+   \li Button 1: 1 step
+   \li Button 2: 10 steps
+   \li Button 3: 100 steps
+
+   \param parent
+ */
+QwtCounter::QwtCounter( QWidget* parent )
+    : QWidget( parent )
 {
     initCounter();
@@ -69,16 +71,15 @@
 void QwtCounter::initCounter()
 {
-    d_data = new PrivateData;
-
-    QHBoxLayout *layout = new QHBoxLayout( this );
+    m_data = new PrivateData;
+
+    QHBoxLayout* layout = new QHBoxLayout( this );
     layout->setSpacing( 0 );
-    layout->setMargin( 0 );
+    layout->setContentsMargins( QMargins() );
 
     for ( int i = ButtonCnt - 1; i >= 0; i-- )
     {
-        QwtArrowButton *btn =
+        QwtArrowButton* btn =
             new QwtArrowButton( i + 1, Qt::DownArrow, this );
         btn->setFocusPolicy( Qt::NoFocus );
-        btn->installEventFilter( this );
         layout->addWidget( btn );
 
@@ -86,22 +87,21 @@
         connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
 
-        d_data->buttonDown[i] = btn;
-    }
-
-    d_data->valueEdit = new QLineEdit( this );
-    d_data->valueEdit->setReadOnly( false );
-    d_data->valueEdit->setValidator( new QDoubleValidator( d_data->valueEdit ) );
-    layout->addWidget( d_data->valueEdit );
-
-    connect( d_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
-
-    layout->setStretchFactor( d_data->valueEdit, 10 );
+        m_data->buttonDown[i] = btn;
+    }
+
+    m_data->valueEdit = new QLineEdit( this );
+    m_data->valueEdit->setReadOnly( false );
+    m_data->valueEdit->setValidator( new QDoubleValidator( m_data->valueEdit ) );
+    layout->addWidget( m_data->valueEdit );
+
+    connect( m_data->valueEdit, SIGNAL(editingFinished()), SLOT(textChanged()) );
+
+    layout->setStretchFactor( m_data->valueEdit, 10 );
 
     for ( int i = 0; i < ButtonCnt; i++ )
     {
-        QwtArrowButton *btn =
+        QwtArrowButton* btn =
             new QwtArrowButton( i + 1, Qt::UpArrow, this );
         btn->setFocusPolicy( Qt::NoFocus );
-        btn->installEventFilter( this );
         layout->addWidget( btn );
 
@@ -109,5 +109,5 @@
         connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) );
 
-        d_data->buttonUp[i] = btn;
+        m_data->buttonUp[i] = btn;
     }
 
@@ -120,5 +120,5 @@
         QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) );
 
-    setFocusProxy( d_data->valueEdit );
+    setFocusProxy( m_data->valueEdit );
     setFocusPolicy( Qt::StrongFocus );
 }
@@ -127,26 +127,26 @@
 QwtCounter::~QwtCounter()
 {
-    delete d_data;
-}
-
-/*!
-  Set the counter to be in valid/invalid state
-
-  When the counter is set to invalid, no numbers are displayed and
-  the buttons are disabled.
-
-  \param on If true the counter will be set as valid
-
-  \sa setValue(), isValid()
-*/
+    delete m_data;
+}
+
+/*!
+   Set the counter to be in valid/invalid state
+
+   When the counter is set to invalid, no numbers are displayed and
+   the buttons are disabled.
+
+   \param on If true the counter will be set as valid
+
+   \sa setValue(), isValid()
+ */
 void QwtCounter::setValid( bool on )
 {
-    if ( on != d_data->isValid )
-    {
-        d_data->isValid = on;
+    if ( on != m_data->isValid )
+    {
+        m_data->isValid = on;
 
         updateButtons();
 
-        if ( d_data->isValid )
+        if ( m_data->isValid )
         {
             showNumber( value() );
@@ -155,60 +155,60 @@
         else
         {
-            d_data->valueEdit->setText( QString() );
-        }
-    }
-}
-
-/*!
-  \return True, if the value is valid
-  \sa setValid(), setValue()
+            m_data->valueEdit->setText( QString() );
+        }
+    }
+}
+
+/*!
+   \return True, if the value is valid
+   \sa setValid(), setValue()
  */
 bool QwtCounter::isValid() const
 {
-    return d_data->isValid;
-}
-
-/*!
-  \brief Allow/disallow the user to manually edit the value
-
-  \param on True disable editing
-  \sa isReadOnly()
-*/
+    return m_data->isValid;
+}
+
+/*!
+   \brief Allow/disallow the user to manually edit the value
+
+   \param on True disable editing
+   \sa isReadOnly()
+ */
 void QwtCounter::setReadOnly( bool on )
 {
-    d_data->valueEdit->setReadOnly( on );
+    m_data->valueEdit->setReadOnly( on );
 }
 
 /*!
    \return True, when the line line edit is read only. (default is no)
-  \sa setReadOnly()
+   \sa setReadOnly()
  */
 bool QwtCounter::isReadOnly() const
 {
-    return d_data->valueEdit->isReadOnly();
-}
-
-/*!
-  \brief Set a new value without adjusting to the step raster
-
-  The state of the counter is set to be valid.
-
-  \param value New value
-
-  \sa isValid(), value(), valueChanged()
-  \warning The value is clipped when it lies outside the range.
-*/
+    return m_data->valueEdit->isReadOnly();
+}
+
+/*!
+   \brief Set a new value without adjusting to the step raster
+
+   The state of the counter is set to be valid.
+
+   \param value New value
+
+   \sa isValid(), value(), valueChanged()
+   \warning The value is clipped when it lies outside the range.
+ */
 
 void QwtCounter::setValue( double value )
 {
-    const double vmin = qMin( d_data->minimum, d_data->maximum );
-    const double vmax = qMax( d_data->minimum, d_data->maximum );
+    const double vmin = qwtMinF( m_data->minimum, m_data->maximum );
+    const double vmax = qwtMaxF( m_data->minimum, m_data->maximum );
 
     value = qBound( vmin, value, vmax );
 
-    if ( !d_data->isValid || value != d_data->value )
-    {
-        d_data->isValid = true;
-        d_data->value = value;
+    if ( !m_data->isValid || value != m_data->value )
+    {
+        m_data->isValid = true;
+        m_data->value = value;
 
         showNumber( value );
@@ -220,42 +220,42 @@
 
 /*!
-  \return Current value of the counter
-  \sa setValue(), valueChanged()
+   \return Current value of the counter
+   \sa setValue(), valueChanged()
  */
 double QwtCounter::value() const
 {
-    return d_data->value;
-}
-
-/*!
-  \brief Set the minimum and maximum values
-
-  The maximum is adjusted if necessary to ensure that the range remains valid.
-  The value might be modified to be inside of the range.
-
-  \param min Minimum value
-  \param max Maximum value
-
-  \sa minimum(), maximum()
+    return m_data->value;
+}
+
+/*!
+   \brief Set the minimum and maximum values
+
+   The maximum is adjusted if necessary to ensure that the range remains valid.
+   The value might be modified to be inside of the range.
+
+   \param min Minimum value
+   \param max Maximum value
+
+   \sa minimum(), maximum()
  */
 void QwtCounter::setRange( double min, double max )
 {
-    max = qMax( min, max );
-
-    if ( d_data->maximum == max && d_data->minimum == min )
+    max = qwtMaxF( min, max );
+
+    if ( m_data->maximum == max && m_data->minimum == min )
         return;
 
-    d_data->minimum = min;
-    d_data->maximum = max;
+    m_data->minimum = min;
+    m_data->maximum = max;
 
     setSingleStep( singleStep() );
 
-    const double value = qBound( min, d_data->value, max );
-
-    if ( value != d_data->value )
-    {
-        d_data->value = value;
-
-        if ( d_data->isValid )
+    const double value = qBound( min, m_data->value, max );
+
+    if ( value != m_data->value )
+    {
+        m_data->value = value;
+
+        if ( m_data->isValid )
         {
             showNumber( value );
@@ -268,11 +268,11 @@
 
 /*!
-  Set the minimum value of the range
-
-  \param value Minimum value
-  \sa setRange(), setMaximum(), minimum()
-
-  \note The maximum is adjusted if necessary to ensure that the range remains valid.
-*/
+   Set the minimum value of the range
+
+   \param value Minimum value
+   \sa setRange(), setMaximum(), minimum()
+
+   \note The maximum is adjusted if necessary to ensure that the range remains valid.
+ */
 void QwtCounter::setMinimum( double value )
 {
@@ -281,18 +281,18 @@
 
 /*!
-  \return The minimum of the range
-  \sa setRange(), setMinimum(), maximum()
-*/
+   \return The minimum of the range
+   \sa setRange(), setMinimum(), maximum()
+ */
 double QwtCounter::minimum() const
 {
-    return d_data->minimum;
-}
-
-/*!
-  Set the maximum value of the range
-
-  \param value Maximum value
-  \sa setRange(), setMinimum(), maximum()
-*/
+    return m_data->minimum;
+}
+
+/*!
+   Set the maximum value of the range
+
+   \param value Maximum value
+   \sa setRange(), setMinimum(), maximum()
+ */
 void QwtCounter::setMaximum( double value )
 {
@@ -301,63 +301,63 @@
 
 /*!
-  \return The maximum of the range
-  \sa setRange(), setMaximum(), minimum()
-*/
+   \return The maximum of the range
+   \sa setRange(), setMaximum(), minimum()
+ */
 double QwtCounter::maximum() const
 {
-    return d_data->maximum;
-}
-
-/*!
-  \brief Set the step size of the counter
-
-  A value <= 0.0 disables stepping
-
-  \param stepSize Single step size
-  \sa singleStep()
-*/
+    return m_data->maximum;
+}
+
+/*!
+   \brief Set the step size of the counter
+
+   A value <= 0.0 disables stepping
+
+   \param stepSize Single step size
+   \sa singleStep()
+ */
 void QwtCounter::setSingleStep( double stepSize )
 {
-    d_data->singleStep = qMax( stepSize, 0.0 );
-}
-
-/*!
-  \return Single step size
-  \sa setSingleStep()
+    m_data->singleStep = qwtMaxF( stepSize, 0.0 );
+}
+
+/*!
+   \return Single step size
+   \sa setSingleStep()
  */
 double QwtCounter::singleStep() const
 {
-    return d_data->singleStep;
-}
-
-/*!
-  \brief En/Disable wrapping
-
-  If wrapping is true stepping up from maximum() value will take
-  you to the minimum() value and vice versa.
-
-  \param on En/Disable wrapping
-  \sa wrapping()
+    return m_data->singleStep;
+}
+
+/*!
+   \brief En/Disable wrapping
+
+   If wrapping is true stepping up from maximum() value will take
+   you to the minimum() value and vice versa.
+
+   \param on En/Disable wrapping
+   \sa wrapping()
  */
 void QwtCounter::setWrapping( bool on )
 {
-    d_data->wrapping = on;
-}
-
-/*!
-  \return True, when wrapping is set
-  \sa setWrapping()
+    m_data->wrapping = on;
+}
+
+/*!
+   \return True, when wrapping is set
+   \sa setWrapping()
  */
 bool QwtCounter::wrapping() const
 {
-    return d_data->wrapping;
-}
-
-/*!
-  Specify the number of buttons on each side of the label
-
-  \param numButtons Number of buttons
-  \sa numButtons()
-*/
+    return m_data->wrapping;
+}
+
+/*!
+   Specify the number of buttons on each side of the label
+
+   \param numButtons Number of buttons
+   \sa numButtons()
+ */
 void QwtCounter::setNumButtons( int numButtons )
 {
@@ -369,53 +369,53 @@
         if ( i < numButtons )
         {
-            d_data->buttonDown[i]->show();
-            d_data->buttonUp[i]->show();
+            m_data->buttonDown[i]->show();
+            m_data->buttonUp[i]->show();
         }
         else
         {
-            d_data->buttonDown[i]->hide();
-            d_data->buttonUp[i]->hide();
-        }
-    }
-
-    d_data->numButtons = numButtons;
-}
-
-/*!
-  \return The number of buttons on each side of the widget.
-  \sa setNumButtons()
-*/
+            m_data->buttonDown[i]->hide();
+            m_data->buttonUp[i]->hide();
+        }
+    }
+
+    m_data->numButtons = numButtons;
+}
+
+/*!
+   \return The number of buttons on each side of the widget.
+   \sa setNumButtons()
+ */
 int QwtCounter::numButtons() const
 {
-    return d_data->numButtons;
-}
-
-/*!
-  Specify the number of steps by which the value
-  is incremented or decremented when a specified button
-  is pushed.
-
-  \param button Button index
-  \param numSteps Number of steps
-
-  \sa incSteps()
-*/
+    return m_data->numButtons;
+}
+
+/*!
+   Specify the number of steps by which the value
+   is incremented or decremented when a specified button
+   is pushed.
+
+   \param button Button index
+   \param numSteps Number of steps
+
+   \sa incSteps()
+ */
 void QwtCounter::setIncSteps( QwtCounter::Button button, int numSteps )
 {
     if ( button >= 0 && button < QwtCounter::ButtonCnt )
-        d_data->increment[ button ] = numSteps;
-}
-
-/*!
-  \return The number of steps by which a specified button increments the value
+        m_data->increment[ button ] = numSteps;
+}
+
+/*!
+   \return The number of steps by which a specified button increments the value
           or 0 if the button is invalid.
-  \param button Button index
-
-  \sa setIncSteps()
-*/
+   \param button Button index
+
+   \sa setIncSteps()
+ */
 int QwtCounter::incSteps( QwtCounter::Button button ) const
 {
     if ( button >= 0 && button < QwtCounter::ButtonCnt )
-        return d_data->increment[ button ];
+        return m_data->increment[ button ];
 
     return 0;
@@ -424,7 +424,7 @@
 
 /*!
-  Set the number of increment steps for button 1
-  \param nSteps Number of steps
-*/
+   Set the number of increment steps for button 1
+   \param nSteps Number of steps
+ */
 void QwtCounter::setStepButton1( int nSteps )
 {
@@ -439,7 +439,7 @@
 
 /*!
-  Set the number of increment steps for button 2
-  \param nSteps Number of steps
-*/
+   Set the number of increment steps for button 2
+   \param nSteps Number of steps
+ */
 void QwtCounter::setStepButton2( int nSteps )
 {
@@ -454,7 +454,7 @@
 
 /*!
-  Set the number of increment steps for button 3
-  \param nSteps Number of steps
-*/
+   Set the number of increment steps for button 3
+   \param nSteps Number of steps
+ */
 void QwtCounter::setStepButton3( int nSteps )
 {
@@ -473,5 +473,5 @@
     bool converted = false;
 
-    const double value = d_data->valueEdit->text().toDouble( &converted );
+    const double value = m_data->valueEdit->text().toDouble( &converted );
     if ( converted )
         setValue( value );
@@ -482,14 +482,16 @@
    \param event Event
    \return see QWidget::event()
-*/
-bool QwtCounter::event( QEvent *event )
+ */
+bool QwtCounter::event( QEvent* event )
 {
     if ( event->type() == QEvent::PolishRequest )
     {
-        const int w = d_data->valueEdit->fontMetrics().width( "W" ) + 8;
+        const QFontMetrics fm = m_data->valueEdit->fontMetrics();
+
+        const int w = QwtPainter::horizontalAdvance( fm, "W" ) + 8;
         for ( int i = 0; i < ButtonCnt; i++ )
         {
-            d_data->buttonDown[i]->setMinimumWidth( w );
-            d_data->buttonUp[i]->setMinimumWidth( w );
+            m_data->buttonDown[i]->setMinimumWidth( w );
+            m_data->buttonUp[i]->setMinimumWidth( w );
         }
     }
@@ -499,26 +501,26 @@
 
 /*!
-  Handle key events
-
-  - Ctrl + Qt::Key_Home\n
+   Handle key events
+
+   - Ctrl + Qt::Key_Home\n
     Step to minimum()
-  - Ctrl + Qt::Key_End\n
+   - Ctrl + Qt::Key_End\n
     Step to maximum()
-  - Qt::Key_Up\n
+   - Qt::Key_Up\n
     Increment by incSteps(QwtCounter::Button1)
-  - Qt::Key_Down\n
+   - Qt::Key_Down\n
     Decrement by incSteps(QwtCounter::Button1)
-  - Qt::Key_PageUp\n
+   - Qt::Key_PageUp\n
     Increment by incSteps(QwtCounter::Button2)
-  - Qt::Key_PageDown\n
+   - Qt::Key_PageDown\n
     Decrement by incSteps(QwtCounter::Button2)
-  - Shift + Qt::Key_PageUp\n
+   - Shift + Qt::Key_PageUp\n
     Increment by incSteps(QwtCounter::Button3)
-  - Shift + Qt::Key_PageDown\n
+   - Shift + Qt::Key_PageDown\n
     Decrement by incSteps(QwtCounter::Button3)
 
-  \param event Key event
-*/
-void QwtCounter::keyPressEvent ( QKeyEvent *event )
+   \param event Key event
+ */
+void QwtCounter::keyPressEvent ( QKeyEvent* event )
 {
     bool accepted = true;
@@ -544,10 +546,10 @@
         case Qt::Key_Up:
         {
-            incrementValue( d_data->increment[0] );
+            incrementValue( m_data->increment[0] );
             break;
         }
         case Qt::Key_Down:
         {
-            incrementValue( -d_data->increment[0] );
+            incrementValue( -m_data->increment[0] );
             break;
         }
@@ -555,11 +557,11 @@
         case Qt::Key_PageDown:
         {
-            int increment = d_data->increment[0];
-            if ( d_data->numButtons >= 2 )
-                increment = d_data->increment[1];
-            if ( d_data->numButtons >= 3 )
+            int increment = m_data->increment[0];
+            if ( m_data->numButtons >= 2 )
+                increment = m_data->increment[1];
+            if ( m_data->numButtons >= 3 )
             {
                 if ( event->modifiers() & Qt::ShiftModifier )
-                    increment = d_data->increment[2];
+                    increment = m_data->increment[2];
             }
             if ( event->key() == Qt::Key_PageDown )
@@ -584,63 +586,66 @@
 
 /*!
-  Handle wheel events
-  \param event Wheel event
-*/
-void QwtCounter::wheelEvent( QWheelEvent *event )
+   Handle wheel events
+   \param event Wheel event
+ */
+void QwtCounter::wheelEvent( QWheelEvent* event )
 {
     event->accept();
 
-    if ( d_data->numButtons <= 0 )
+    if ( m_data->numButtons <= 0 )
         return;
 
-    int increment = d_data->increment[0];
-    if ( d_data->numButtons >= 2 )
+    int increment = m_data->increment[0];
+    if ( m_data->numButtons >= 2 )
     {
         if ( event->modifiers() & Qt::ControlModifier )
-            increment = d_data->increment[1];
-    }
-    if ( d_data->numButtons >= 3 )
+            increment = m_data->increment[1];
+    }
+    if ( m_data->numButtons >= 3 )
     {
         if ( event->modifiers() & Qt::ShiftModifier )
-            increment = d_data->increment[2];
-    }
-
-    for ( int i = 0; i < d_data->numButtons; i++ )
-    {
-        if ( d_data->buttonDown[i]->geometry().contains( event->pos() ) ||
-            d_data->buttonUp[i]->geometry().contains( event->pos() ) )
-        {
-            increment = d_data->increment[i];
-        }
-    }
-
-    const int wheel_delta = 120;
+            increment = m_data->increment[2];
+    }
+
+#if QT_VERSION < 0x050e00
+    const QPoint wheelPos = event->pos();
+    const int wheelDelta = event->delta();
+#else
+    const QPoint wheelPos = event->position().toPoint();
+
+    const QPoint delta = event->angleDelta();
+    const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
+        ? delta.x() : delta.y();
+#endif
+
+    for ( int i = 0; i < m_data->numButtons; i++ )
+    {
+        if ( m_data->buttonDown[i]->geometry().contains( wheelPos ) ||
+            m_data->buttonUp[i]->geometry().contains( wheelPos ) )
+        {
+            increment = m_data->increment[i];
+        }
+    }
+
+    incrementValue( wheelDelta / 120 * increment );
+}
+
+void QwtCounter::incrementValue( int numSteps )
+{
+    const double min = m_data->minimum;
+    const double max = m_data->maximum;
+    double stepSize = m_data->singleStep;
+
+    if ( !m_data->isValid || min >= max || stepSize <= 0.0 )
+        return;
+
 
 #if 1
-    int delta = event->delta();
-    if ( delta >= 2 * wheel_delta )
-        delta /= 2; // Never saw an abs(delta) < 240
+    stepSize = qwtMaxF( stepSize, 1.0e-10 * ( max - min ) );
 #endif
 
-    incrementValue( delta / wheel_delta * increment );
-}
-
-void QwtCounter::incrementValue( int numSteps )
-{
-    const double min = d_data->minimum;
-    const double max = d_data->maximum;
-    double stepSize = d_data->singleStep;
-
-    if ( !d_data->isValid || min >= max || stepSize <= 0.0 )
-        return;
-
-
-#if 1
-    stepSize = qMax( stepSize, 1.0e-10 * ( max - min ) );
-#endif
-
-    double value = d_data->value + numSteps * stepSize;
-
-    if ( d_data->wrapping )
+    double value = m_data->value + numSteps * stepSize;
+
+    if ( m_data->wrapping )
     {
         const double range = max - min;
@@ -648,9 +653,9 @@
         if ( value < min )
         {
-            value += ::ceil( ( min - value ) / range ) * range;
+            value += std::ceil( ( min - value ) / range ) * range;
         }
         else if ( value > max )
         {
-            value -= ::ceil( ( value - max ) / range ) * range;
+            value -= std::ceil( ( value - max ) / range ) * range;
         }
     }
@@ -676,26 +681,26 @@
     }
 
-    if ( value != d_data->value )
-    {
-        d_data->value = value;
-        showNumber( d_data->value );
+    if ( value != m_data->value )
+    {
+        m_data->value = value;
+        showNumber( m_data->value );
         updateButtons();
 
-        Q_EMIT valueChanged( d_data->value );
-    }
-}
-
-
-/*!
-  \brief Update buttons according to the current value
-
-  When the QwtCounter under- or over-flows, the focus is set to the smallest
-  up- or down-button and counting is disabled.
-
-  Counting is re-enabled on a button release event (mouse or space bar).
-*/
+        Q_EMIT valueChanged( m_data->value );
+    }
+}
+
+
+/*!
+   \brief Update buttons according to the current value
+
+   When the QwtCounter under- or over-flows, the focus is set to the smallest
+   up- or down-button and counting is disabled.
+
+   Counting is re-enabled on a button release event (mouse or space bar).
+ */
 void QwtCounter::updateButtons()
 {
-    if ( d_data->isValid )
+    if ( m_data->isValid )
     {
         // 1. save enabled state of the smallest down- and up-button
@@ -704,6 +709,6 @@
         for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
         {
-            d_data->buttonDown[i]->setEnabled( value() > minimum() );
-            d_data->buttonUp[i]->setEnabled( value() < maximum() );
+            m_data->buttonDown[i]->setEnabled( value() > minimum() );
+            m_data->buttonUp[i]->setEnabled( value() < maximum() );
         }
     }
@@ -712,14 +717,14 @@
         for ( int i = 0; i < QwtCounter::ButtonCnt; i++ )
         {
-            d_data->buttonDown[i]->setEnabled( false );
-            d_data->buttonUp[i]->setEnabled( false );
-        }
-    }
-}
-/*!
-  Display number string
-
-  \param number Number
-*/
+            m_data->buttonDown[i]->setEnabled( false );
+            m_data->buttonUp[i]->setEnabled( false );
+        }
+    }
+}
+/*!
+   Display number string
+
+   \param number Number
+ */
 void QwtCounter::showNumber( double number )
 {
@@ -727,7 +732,7 @@
     text.setNum( number );
 
-    const int cursorPos = d_data->valueEdit->cursorPosition();
-    d_data->valueEdit->setText( text );
-    d_data->valueEdit->setCursorPosition( cursorPos );
+    const int cursorPos = m_data->valueEdit->cursorPosition();
+    m_data->valueEdit->setText( text );
+    m_data->valueEdit->setCursorPosition( cursorPos );
 }
 
@@ -737,9 +742,9 @@
     for ( int i = 0; i < ButtonCnt; i++ )
     {
-        if ( d_data->buttonUp[i] == sender() )
-            incrementValue( d_data->increment[i] );
-
-        if ( d_data->buttonDown[i] == sender() )
-            incrementValue( -d_data->increment[i] );
+        if ( m_data->buttonUp[i] == sender() )
+            incrementValue( m_data->increment[i] );
+
+        if ( m_data->buttonDown[i] == sender() )
+            incrementValue( -m_data->increment[i] );
     }
 }
@@ -769,16 +774,19 @@
     tmp.fill( '9', w );
 
-    QFontMetrics fm( d_data->valueEdit->font() );
-    w = fm.width( tmp ) + 2;
-    if ( d_data->valueEdit->hasFrame() )
+    w = QwtPainter::horizontalAdvance( m_data->valueEdit->fontMetrics(), tmp ) + 2;
+
+    if ( m_data->valueEdit->hasFrame() )
         w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
 
-    // Now we replace default sizeHint contribution of d_data->valueEdit by
+    // Now we replace default sizeHint contribution of m_data->valueEdit by
     // what we really need.
 
-    w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();
+    w += QWidget::sizeHint().width() - m_data->valueEdit->sizeHint().width();
 
     const int h = qMin( QWidget::sizeHint().height(),
-        d_data->valueEdit->minimumSizeHint().height() );
+        m_data->valueEdit->minimumSizeHint().height() );
+
     return QSize( w, h );
 }
+
+#include "moc_qwt_counter.cpp"
