Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_counter.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_counter.cpp (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_counter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_arrow_button.h" 11 #include "qwt_counter.h" 12 #include "qwt_painter.h" 11 13 #include "qwt_math.h" 12 #include "qwt_counter.h" 14 13 15 #include <qlayout.h> 14 16 #include <qlineedit.h> … … 19 21 class QwtCounter::PrivateData 20 22 { 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 ) 29 31 { 30 32 increment[Button1] = 1; … … 33 35 } 34 36 35 QwtArrowButton *buttonDown[ButtonCnt];36 QwtArrowButton *buttonUp[ButtonCnt];37 QLineEdit *valueEdit;37 QwtArrowButton* buttonDown[ButtonCnt]; 38 QwtArrowButton* buttonUp[ButtonCnt]; 39 QLineEdit* valueEdit; 38 40 39 41 int increment[ButtonCnt]; … … 51 53 52 54 /*! 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 */ 65 QwtCounter::QwtCounter( QWidget* parent ) 66 : QWidget( parent ) 65 67 { 66 68 initCounter(); … … 69 71 void QwtCounter::initCounter() 70 72 { 71 d_data = new PrivateData;72 73 QHBoxLayout *layout = new QHBoxLayout( this );73 m_data = new PrivateData; 74 75 QHBoxLayout* layout = new QHBoxLayout( this ); 74 76 layout->setSpacing( 0 ); 75 layout->set Margin( 0);77 layout->setContentsMargins( QMargins() ); 76 78 77 79 for ( int i = ButtonCnt - 1; i >= 0; i-- ) 78 80 { 79 QwtArrowButton *btn =81 QwtArrowButton* btn = 80 82 new QwtArrowButton( i + 1, Qt::DownArrow, this ); 81 83 btn->setFocusPolicy( Qt::NoFocus ); 82 btn->installEventFilter( this );83 84 layout->addWidget( btn ); 84 85 … … 86 87 connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) ); 87 88 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 ); 99 100 100 101 for ( int i = 0; i < ButtonCnt; i++ ) 101 102 { 102 QwtArrowButton *btn =103 QwtArrowButton* btn = 103 104 new QwtArrowButton( i + 1, Qt::UpArrow, this ); 104 105 btn->setFocusPolicy( Qt::NoFocus ); 105 btn->installEventFilter( this );106 106 layout->addWidget( btn ); 107 107 … … 109 109 connect( btn, SIGNAL(clicked()), SLOT(btnClicked()) ); 110 110 111 d_data->buttonUp[i] = btn;111 m_data->buttonUp[i] = btn; 112 112 } 113 113 … … 120 120 QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); 121 121 122 setFocusProxy( d_data->valueEdit );122 setFocusProxy( m_data->valueEdit ); 123 123 setFocusPolicy( Qt::StrongFocus ); 124 124 } … … 127 127 QwtCounter::~QwtCounter() 128 128 { 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 */ 142 142 void QwtCounter::setValid( bool on ) 143 143 { 144 if ( on != d_data->isValid )145 { 146 d_data->isValid = on;144 if ( on != m_data->isValid ) 145 { 146 m_data->isValid = on; 147 147 148 148 updateButtons(); 149 149 150 if ( d_data->isValid )150 if ( m_data->isValid ) 151 151 { 152 152 showNumber( value() ); … … 155 155 else 156 156 { 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() 165 165 */ 166 166 bool QwtCounter::isValid() const 167 167 { 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 */ 177 177 void QwtCounter::setReadOnly( bool on ) 178 178 { 179 d_data->valueEdit->setReadOnly( on );179 m_data->valueEdit->setReadOnly( on ); 180 180 } 181 181 182 182 /*! 183 183 \return True, when the line line edit is read only. (default is no) 184 \sa setReadOnly() 184 \sa setReadOnly() 185 185 */ 186 186 bool QwtCounter::isReadOnly() const 187 187 { 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 */ 201 201 202 202 void QwtCounter::setValue( double value ) 203 203 { 204 const double vmin = q Min( d_data->minimum,d_data->maximum );205 const double vmax = q Max( 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 ); 206 206 207 207 value = qBound( vmin, value, vmax ); 208 208 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; 213 213 214 214 showNumber( value ); … … 220 220 221 221 /*! 222 \return Current value of the counter 223 \sa setValue(), valueChanged() 222 \return Current value of the counter 223 \sa setValue(), valueChanged() 224 224 */ 225 225 double QwtCounter::value() const 226 226 { 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() 240 240 */ 241 241 void QwtCounter::setRange( double min, double max ) 242 242 { 243 max = q Max( 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 ) 246 246 return; 247 247 248 d_data->minimum = min;249 d_data->maximum = max;248 m_data->minimum = min; 249 m_data->maximum = max; 250 250 251 251 setSingleStep( singleStep() ); 252 252 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 ) 260 260 { 261 261 showNumber( value ); … … 268 268 269 269 /*! 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 */ 277 277 void QwtCounter::setMinimum( double value ) 278 278 { … … 281 281 282 282 /*! 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 */ 286 286 double QwtCounter::minimum() const 287 287 { 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 */ 297 297 void QwtCounter::setMaximum( double value ) 298 298 { … … 301 301 302 302 /*! 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 */ 306 306 double QwtCounter::maximum() const 307 307 { 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 */ 319 319 void QwtCounter::setSingleStep( double stepSize ) 320 320 { 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() 327 327 */ 328 328 double QwtCounter::singleStep() const 329 329 { 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() 341 341 */ 342 342 void QwtCounter::setWrapping( bool on ) 343 343 { 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() 350 350 */ 351 351 bool QwtCounter::wrapping() const 352 352 { 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 */ 362 362 void QwtCounter::setNumButtons( int numButtons ) 363 363 { … … 369 369 if ( i < numButtons ) 370 370 { 371 d_data->buttonDown[i]->show();372 d_data->buttonUp[i]->show();371 m_data->buttonDown[i]->show(); 372 m_data->buttonUp[i]->show(); 373 373 } 374 374 else 375 375 { 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 */ 388 388 int QwtCounter::numButtons() const 389 389 { 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 */ 403 403 void QwtCounter::setIncSteps( QwtCounter::Button button, int numSteps ) 404 404 { 405 405 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 411 411 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 */ 416 416 int QwtCounter::incSteps( QwtCounter::Button button ) const 417 417 { 418 418 if ( button >= 0 && button < QwtCounter::ButtonCnt ) 419 return d_data->increment[ button ];419 return m_data->increment[ button ]; 420 420 421 421 return 0; … … 424 424 425 425 /*! 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 */ 429 429 void QwtCounter::setStepButton1( int nSteps ) 430 430 { … … 439 439 440 440 /*! 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 */ 444 444 void QwtCounter::setStepButton2( int nSteps ) 445 445 { … … 454 454 455 455 /*! 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 */ 459 459 void QwtCounter::setStepButton3( int nSteps ) 460 460 { … … 473 473 bool converted = false; 474 474 475 const double value = d_data->valueEdit->text().toDouble( &converted );475 const double value = m_data->valueEdit->text().toDouble( &converted ); 476 476 if ( converted ) 477 477 setValue( value ); … … 482 482 \param event Event 483 483 \return see QWidget::event() 484 */ 485 bool QwtCounter::event( QEvent *event )484 */ 485 bool QwtCounter::event( QEvent* event ) 486 486 { 487 487 if ( event->type() == QEvent::PolishRequest ) 488 488 { 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; 490 492 for ( int i = 0; i < ButtonCnt; i++ ) 491 493 { 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 ); 494 496 } 495 497 } … … 499 501 500 502 /*! 501 Handle key events 502 503 - Ctrl + Qt::Key_Home\n 503 Handle key events 504 505 - Ctrl + Qt::Key_Home\n 504 506 Step to minimum() 505 - Ctrl + Qt::Key_End\n 507 - Ctrl + Qt::Key_End\n 506 508 Step to maximum() 507 - Qt::Key_Up\n 509 - Qt::Key_Up\n 508 510 Increment by incSteps(QwtCounter::Button1) 509 - Qt::Key_Down\n 511 - Qt::Key_Down\n 510 512 Decrement by incSteps(QwtCounter::Button1) 511 - Qt::Key_PageUp\n 513 - Qt::Key_PageUp\n 512 514 Increment by incSteps(QwtCounter::Button2) 513 - Qt::Key_PageDown\n 515 - Qt::Key_PageDown\n 514 516 Decrement by incSteps(QwtCounter::Button2) 515 - Shift + Qt::Key_PageUp\n 517 - Shift + Qt::Key_PageUp\n 516 518 Increment by incSteps(QwtCounter::Button3) 517 - Shift + Qt::Key_PageDown\n 519 - Shift + Qt::Key_PageDown\n 518 520 Decrement by incSteps(QwtCounter::Button3) 519 521 520 \param event Key event 521 */ 522 void QwtCounter::keyPressEvent ( QKeyEvent *event )522 \param event Key event 523 */ 524 void QwtCounter::keyPressEvent ( QKeyEvent* event ) 523 525 { 524 526 bool accepted = true; … … 544 546 case Qt::Key_Up: 545 547 { 546 incrementValue( d_data->increment[0] );548 incrementValue( m_data->increment[0] ); 547 549 break; 548 550 } 549 551 case Qt::Key_Down: 550 552 { 551 incrementValue( - d_data->increment[0] );553 incrementValue( -m_data->increment[0] ); 552 554 break; 553 555 } … … 555 557 case Qt::Key_PageDown: 556 558 { 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 ) 561 563 { 562 564 if ( event->modifiers() & Qt::ShiftModifier ) 563 increment = d_data->increment[2];565 increment = m_data->increment[2]; 564 566 } 565 567 if ( event->key() == Qt::Key_PageDown ) … … 584 586 585 587 /*! 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 */ 591 void QwtCounter::wheelEvent( QWheelEvent* event ) 590 592 { 591 593 event->accept(); 592 594 593 if ( d_data->numButtons <= 0 )595 if ( m_data->numButtons <= 0 ) 594 596 return; 595 597 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 ) 598 600 { 599 601 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 ) 603 605 { 604 606 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 633 void 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 618 642 619 643 #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 ) ); 623 645 #endif 624 646 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 ) 645 650 { 646 651 const double range = max - min; … … 648 653 if ( value < min ) 649 654 { 650 value += ::ceil( ( min - value ) / range ) * range; 655 value += std::ceil( ( min - value ) / range ) * range; 651 656 } 652 657 else if ( value > max ) 653 658 { 654 value -= ::ceil( ( value - max ) / range ) * range; 659 value -= std::ceil( ( value - max ) / range ) * range; 655 660 } 656 661 } … … 676 681 } 677 682 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 ); 682 687 updateButtons(); 683 688 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 */ 697 702 void QwtCounter::updateButtons() 698 703 { 699 if ( d_data->isValid )704 if ( m_data->isValid ) 700 705 { 701 706 // 1. save enabled state of the smallest down- and up-button … … 704 709 for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) 705 710 { 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() ); 708 713 } 709 714 } … … 712 717 for ( int i = 0; i < QwtCounter::ButtonCnt; i++ ) 713 718 { 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 */ 724 729 void QwtCounter::showNumber( double number ) 725 730 { … … 727 732 text.setNum( number ); 728 733 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 ); 732 737 } 733 738 … … 737 742 for ( int i = 0; i < ButtonCnt; i++ ) 738 743 { 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] ); 744 749 } 745 750 } … … 769 774 tmp.fill( '9', w ); 770 775 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() ) 774 779 w += 2 * style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); 775 780 776 // Now we replace default sizeHint contribution of d_data->valueEdit by781 // Now we replace default sizeHint contribution of m_data->valueEdit by 777 782 // what we really need. 778 783 779 w += QWidget::sizeHint().width() - d_data->valueEdit->sizeHint().width();784 w += QWidget::sizeHint().width() - m_data->valueEdit->sizeHint().width(); 780 785 781 786 const int h = qMin( QWidget::sizeHint().height(), 782 d_data->valueEdit->minimumSizeHint().height() ); 787 m_data->valueEdit->minimumSizeHint().height() ); 788 783 789 return QSize( w, h ); 784 790 } 791 792 #include "moc_qwt_counter.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
