Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_slider.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_slider.cpp (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_slider.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 12 12 #include "qwt_scale_draw.h" 13 13 #include "qwt_scale_map.h" 14 #include "qwt_math.h" 15 #include "qwt.h" 16 14 17 #include <qevent.h> 15 18 #include <qdrawutil.h> 16 19 #include <qpainter.h> 17 #include <qalgorithms.h>18 #include <qmath.h>19 20 #include <qstyle.h> 20 21 #include <qstyleoption.h> 21 #include <q application.h>22 23 static QSize qwtHandleSize( const QSize &size,22 #include <qmargins.h> 23 24 static QSize qwtHandleSize( const QSize& size, 24 25 Qt::Orientation orientation, bool hasTrough ) 25 26 { … … 69 70 class QwtSlider::PrivateData 70 71 { 71 public: 72 PrivateData() :73 repeatTimerId( 0 ) ,74 updateInterval( 150 ) ,75 stepsIncrement( 0 ) ,76 pendingValueChange( false ) ,77 borderWidth( 2 ) ,78 spacing( 4 ) ,79 scalePosition( QwtSlider::TrailingScale ) ,80 hasTrough( true ) ,81 hasGroove( false ) ,82 mouseOffset( 0 ) 72 public: 73 PrivateData() 74 : repeatTimerId( 0 ) 75 , updateInterval( 150 ) 76 , stepsIncrement( 0 ) 77 , pendingValueChange( false ) 78 , borderWidth( 2 ) 79 , spacing( 4 ) 80 , scalePosition( QwtSlider::TrailingScale ) 81 , hasTrough( true ) 82 , hasGroove( false ) 83 , mouseOffset( 0 ) 83 84 { 84 85 } … … 107 108 }; 108 109 /*! 109 Construct vertical slider in QwtSlider::Trough style 110 with a scale to the left. 111 112 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 113 114 \param parent Parent widget 115 116 \sa setOrientation(), setScalePosition(), setBackgroundStyle() 117 */ 118 QwtSlider::QwtSlider( QWidget *parent ):119 QwtAbstractSlider( parent ) 110 Construct vertical slider in QwtSlider::Trough style 111 with a scale to the left. 112 113 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 114 115 \param parent Parent widget 116 117 \sa setOrientation(), setScalePosition(), setBackgroundStyle() 118 */ 119 QwtSlider::QwtSlider( QWidget* parent ) 120 : QwtAbstractSlider( parent ) 120 121 { 121 122 initSlider( Qt::Vertical ); … … 123 124 124 125 /*! 125 Construct a slider in QwtSlider::Trough style 126 127 When orientation is Qt::Vertical the scale will be aligned to 128 the left - otherwise at the the top of the slider. 129 130 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 131 132 \param parent Parent widget 133 \param orientation Orientation of the slider. 134 */ 135 QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget *parent ):136 QwtAbstractSlider( parent ) 126 Construct a slider in QwtSlider::Trough style 127 128 When orientation is Qt::Vertical the scale will be aligned to 129 the left - otherwise at the the top of the slider. 130 131 The scale is initialized to [0.0, 100.0] and the value set to 0.0. 132 133 \param parent Parent widget 134 \param orientation Orientation of the slider. 135 */ 136 QwtSlider::QwtSlider( Qt::Orientation orientation, QWidget* parent ) 137 : QwtAbstractSlider( parent ) 137 138 { 138 139 initSlider( orientation ); … … 142 143 QwtSlider::~QwtSlider() 143 144 { 144 delete d_data;145 delete m_data; 145 146 } 146 147 … … 154 155 setAttribute( Qt::WA_WState_OwnSizePolicy, false ); 155 156 156 d_data = new QwtSlider::PrivateData;157 158 d_data->orientation = orientation;157 m_data = new QwtSlider::PrivateData; 158 159 m_data->orientation = orientation; 159 160 160 161 scaleDraw()->setAlignment( 161 qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );162 qwtScaleDrawAlignment( orientation, m_data->scalePosition ) ); 162 163 scaleDraw()->setLength( 100 ); 163 164 … … 167 168 168 169 /*! 169 \brief Set the orientation. 170 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 171 172 \sa orientation(), scalePosition() 173 */ 170 \brief Set the orientation. 171 \param orientation Allowed values are Qt::Horizontal and Qt::Vertical. 172 173 \sa orientation(), scalePosition() 174 */ 174 175 void QwtSlider::setOrientation( Qt::Orientation orientation ) 175 176 { 176 if ( orientation == d_data->orientation )177 if ( orientation == m_data->orientation ) 177 178 return; 178 179 179 d_data->orientation = orientation;180 m_data->orientation = orientation; 180 181 181 182 scaleDraw()->setAlignment( 182 qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );183 qwtScaleDrawAlignment( orientation, m_data->scalePosition ) ); 183 184 184 185 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) … … 196 197 197 198 /*! 198 \return Orientation 199 \sa setOrientation() 200 */ 199 \return Orientation 200 \sa setOrientation() 201 */ 201 202 Qt::Orientation QwtSlider::orientation() const 202 203 { 203 return d_data->orientation;204 } 205 206 /*! 207 \brief Change the position of the scale 208 \param scalePosition Position of the scale. 209 210 \sa ScalePosition, scalePosition() 211 */ 204 return m_data->orientation; 205 } 206 207 /*! 208 \brief Change the position of the scale 209 \param scalePosition Position of the scale. 210 211 \sa ScalePosition, scalePosition() 212 */ 212 213 void QwtSlider::setScalePosition( ScalePosition scalePosition ) 213 214 { 214 if ( d_data->scalePosition == scalePosition )215 if ( m_data->scalePosition == scalePosition ) 215 216 return; 216 217 217 d_data->scalePosition = scalePosition;218 m_data->scalePosition = scalePosition; 218 219 scaleDraw()->setAlignment( 219 qwtScaleDrawAlignment( d_data->orientation, scalePosition ) );220 qwtScaleDrawAlignment( m_data->orientation, scalePosition ) ); 220 221 221 222 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 224 225 225 226 /*! 226 \return Position of the scale 227 \sa setScalePosition() 227 \return Position of the scale 228 \sa setScalePosition() 228 229 */ 229 230 QwtSlider::ScalePosition QwtSlider::scalePosition() const 230 231 { 231 return d_data->scalePosition;232 } 233 234 /*! 235 \brief Change the slider's border width 236 237 The border width is used for drawing the slider handle and the 238 trough. 239 240 \param width Border width 241 \sa borderWidth() 242 */ 232 return m_data->scalePosition; 233 } 234 235 /*! 236 \brief Change the slider's border width 237 238 The border width is used for drawing the slider handle and the 239 trough. 240 241 \param width Border width 242 \sa borderWidth() 243 */ 243 244 void QwtSlider::setBorderWidth( int width ) 244 245 { … … 246 247 width = 0; 247 248 248 if ( width != d_data->borderWidth )249 { 250 d_data->borderWidth = width;249 if ( width != m_data->borderWidth ) 250 { 251 m_data->borderWidth = width; 251 252 252 253 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 256 257 257 258 /*! 258 \return the border width. 259 \sa setBorderWidth() 260 */ 259 \return the border width. 260 \sa setBorderWidth() 261 */ 261 262 int QwtSlider::borderWidth() const 262 263 { 263 return d_data->borderWidth;264 } 265 266 /*! 267 \brief Change the spacing between trough and scale 268 269 A spacing of 0 means, that the backbone of the scale is covered 270 by the trough. 271 272 The default setting is 4 pixels. 273 274 \param spacing Number of pixels 275 \sa spacing(); 276 */ 264 return m_data->borderWidth; 265 } 266 267 /*! 268 \brief Change the spacing between trough and scale 269 270 A spacing of 0 means, that the backbone of the scale is covered 271 by the trough. 272 273 The default setting is 4 pixels. 274 275 \param spacing Number of pixels 276 \sa spacing(); 277 */ 277 278 void QwtSlider::setSpacing( int spacing ) 278 279 { … … 280 281 spacing = 0; 281 282 282 if ( spacing != d_data->spacing )283 { 284 d_data->spacing = spacing;283 if ( spacing != m_data->spacing ) 284 { 285 m_data->spacing = spacing; 285 286 286 287 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 290 291 291 292 /*! 292 \return Number of pixels between slider and scale 293 \sa setSpacing() 294 */ 293 \return Number of pixels between slider and scale 294 \sa setSpacing() 295 */ 295 296 int QwtSlider::spacing() const 296 297 { 297 return d_data->spacing;298 } 299 300 /*! 301 \brief Set the slider's handle size 302 303 When the size is empty the slider handle will be painted with a 304 default size depending on its orientation() and backgroundStyle(). 305 306 \param size New size 307 308 \sa handleSize() 309 */ 310 void QwtSlider::setHandleSize( const QSize &size )311 { 312 if ( size != d_data->handleSize )313 { 314 d_data->handleSize = size;298 return m_data->spacing; 299 } 300 301 /*! 302 \brief Set the slider's handle size 303 304 When the size is empty the slider handle will be painted with a 305 default size depending on its orientation() and backgroundStyle(). 306 307 \param size New size 308 309 \sa handleSize() 310 */ 311 void QwtSlider::setHandleSize( const QSize& size ) 312 { 313 if ( size != m_data->handleSize ) 314 { 315 m_data->handleSize = size; 315 316 316 317 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 320 321 321 322 /*! 322 \return Size of the handle. 323 \sa setHandleSize() 324 */ 323 \return Size of the handle. 324 \sa setHandleSize() 325 */ 325 326 QSize QwtSlider::handleSize() const 326 327 { 327 return d_data->handleSize;328 } 329 330 /*! 331 \brief Set a scale draw 332 333 For changing the labels of the scales, it 334 is necessary to derive from QwtScaleDraw and 335 overload QwtScaleDraw::label(). 336 337 \param scaleDraw ScaleDraw object, that has to be created with 328 return m_data->handleSize; 329 } 330 331 /*! 332 \brief Set a scale draw 333 334 For changing the labels of the scales, it 335 is necessary to derive from QwtScaleDraw and 336 overload QwtScaleDraw::label(). 337 338 \param scaleDraw ScaleDraw object, that has to be created with 338 339 new and will be deleted in ~QwtSlider() or the next 339 340 call of setScaleDraw(). 340 341 341 \sa scaleDraw() 342 */ 343 void QwtSlider::setScaleDraw( QwtScaleDraw *scaleDraw )344 { 345 const QwtScaleDraw *previousScaleDraw = this->scaleDraw();342 \sa scaleDraw() 343 */ 344 void QwtSlider::setScaleDraw( QwtScaleDraw* scaleDraw ) 345 { 346 const QwtScaleDraw* previousScaleDraw = this->scaleDraw(); 346 347 if ( scaleDraw == NULL || scaleDraw == previousScaleDraw ) 347 348 return; … … 357 358 358 359 /*! 359 \return the scale draw of the slider 360 \sa setScaleDraw() 361 */ 362 const QwtScaleDraw *QwtSlider::scaleDraw() const363 { 364 return static_cast<const QwtScaleDraw *>( abstractScaleDraw() );365 } 366 367 /*! 368 \return the scale draw of the slider 369 \sa setScaleDraw() 370 */ 371 QwtScaleDraw *QwtSlider::scaleDraw()372 { 373 return static_cast<QwtScaleDraw *>( abstractScaleDraw() );360 \return the scale draw of the slider 361 \sa setScaleDraw() 362 */ 363 const QwtScaleDraw* QwtSlider::scaleDraw() const 364 { 365 return static_cast< const QwtScaleDraw* >( abstractScaleDraw() ); 366 } 367 368 /*! 369 \return the scale draw of the slider 370 \sa setScaleDraw() 371 */ 372 QwtScaleDraw* QwtSlider::scaleDraw() 373 { 374 return static_cast< QwtScaleDraw* >( abstractScaleDraw() ); 374 375 } 375 376 … … 384 385 385 386 /*! 386 \brief Specify the update interval for automatic scrolling 387 388 The minimal accepted value is 50 ms. 389 390 \param interval Update interval in milliseconds 391 392 \sa setUpdateInterval() 393 */ 387 \brief Specify the update interval for automatic scrolling 388 389 The minimal accepted value is 50 ms. 390 391 \param interval Update interval in milliseconds 392 393 \sa setUpdateInterval() 394 */ 394 395 void QwtSlider::setUpdateInterval( int interval ) 395 396 { 396 d_data->updateInterval = qMax( interval, 50 );397 } 398 399 /*! 400 \return Update interval in milliseconds for automatic scrolling 401 \sa setUpdateInterval() 397 m_data->updateInterval = qMax( interval, 50 ); 398 } 399 400 /*! 401 \return Update interval in milliseconds for automatic scrolling 402 \sa setUpdateInterval() 402 403 */ 403 404 int QwtSlider::updateInterval() const 404 405 { 405 return d_data->updateInterval;406 return m_data->updateInterval; 406 407 } 407 408 … … 411 412 \param painter Painter 412 413 \param sliderRect Bounding rectangle of the slider 413 */ 414 */ 414 415 void QwtSlider::drawSlider( 415 QPainter *painter, const QRect&sliderRect ) const416 QPainter* painter, const QRect& sliderRect ) const 416 417 { 417 418 QRect innerRect( sliderRect ); 418 419 419 if ( d_data->hasTrough )420 { 421 const int bw = d_data->borderWidth;420 if ( m_data->hasTrough ) 421 { 422 const int bw = m_data->borderWidth; 422 423 innerRect = sliderRect.adjusted( bw, bw, -bw, -bw ); 423 424 … … 426 427 } 427 428 428 const QSize handleSize = qwtHandleSize( d_data->handleSize,429 d_data->orientation, d_data->hasTrough );430 431 if ( d_data->hasGroove )432 { 429 if ( m_data->hasGroove ) 430 { 431 const QSize handleSize = qwtHandleSize( m_data->handleSize, 432 m_data->orientation, m_data->hasTrough ); 433 433 434 const int slotExtent = 4; 434 435 const int slotMargin = 4; … … 456 457 457 458 QBrush brush = palette().brush( QPalette::Dark ); 458 qDrawShadePanel( painter, slotRect, palette(), true, 1 , &brush );459 qDrawShadePanel( painter, slotRect, palette(), true, 1, &brush ); 459 460 } 460 461 … … 464 465 465 466 /*! 466 Draw the thumb at a position 467 468 \param painter Painter 469 \param handleRect Bounding rectangle of the handle 470 \param pos Position of the handle marker in widget coordinates 471 */ 472 void QwtSlider::drawHandle( QPainter *painter,473 const QRect &handleRect, int pos ) const474 { 475 const int bw = d_data->borderWidth;467 Draw the thumb at a position 468 469 \param painter Painter 470 \param handleRect Bounding rectangle of the handle 471 \param pos Position of the handle marker in widget coordinates 472 */ 473 void QwtSlider::drawHandle( QPainter* painter, 474 const QRect& handleRect, int pos ) const 475 { 476 const int bw = m_data->borderWidth; 476 477 477 478 qDrawShadePanel( painter, … … 493 494 494 495 /*! 495 \brief Determine what to do when the user presses a mouse button. 496 497 \param pos Mouse position 498 499 \retval True, when handleRect() contains pos 500 \sa scrolledTo() 501 */ 502 bool QwtSlider::isScrollPosition( const QPoint &pos ) const496 \brief Determine what to do when the user presses a mouse button. 497 498 \param pos Mouse position 499 500 \retval True, when handleRect() contains pos 501 \sa scrolledTo() 502 */ 503 bool QwtSlider::isScrollPosition( const QPoint& pos ) const 503 504 { 504 505 if ( handleRect().contains( pos ) ) … … 507 508 ? pos.x() : pos.y(); 508 509 509 d_data->mouseOffset = v - transform( value() );510 m_data->mouseOffset = v - transform( value() ); 510 511 return true; 511 512 } … … 515 516 516 517 /*! 517 \brief Determine the value for a new position of the 518 \brief Determine the value for a new position of the 518 519 slider handle. 519 520 520 \param pos Mouse position 521 522 \return Value for the mouse position 523 \sa isScrollPosition() 524 */ 525 double QwtSlider::scrolledTo( const QPoint &pos ) const521 \param pos Mouse position 522 523 \return Value for the mouse position 524 \sa isScrollPosition() 525 */ 526 double QwtSlider::scrolledTo( const QPoint& pos ) const 526 527 { 527 528 int p = ( orientation() == Qt::Horizontal ) 528 529 ? pos.x() : pos.y(); 529 530 530 p -= d_data->mouseOffset;531 p -= m_data->mouseOffset; 531 532 532 533 int min = transform( lowerBound() ); … … 543 544 Mouse press event handler 544 545 \param event Mouse event 545 */ 546 void QwtSlider::mousePressEvent( QMouseEvent *event )546 */ 547 void QwtSlider::mousePressEvent( QMouseEvent* event ) 547 548 { 548 549 if ( isReadOnly() ) … … 554 555 const QPoint pos = event->pos(); 555 556 556 if ( isValid() && d_data->sliderRect.contains( pos ) )557 if ( isValid() && m_data->sliderRect.contains( pos ) ) 557 558 { 558 559 if ( !handleRect().contains( pos ) ) … … 560 561 const int markerPos = transform( value() ); 561 562 562 d_data->stepsIncrement = pageSteps();563 564 if ( d_data->orientation == Qt::Horizontal )563 m_data->stepsIncrement = pageSteps(); 564 565 if ( m_data->orientation == Qt::Horizontal ) 565 566 { 566 567 if ( pos.x() < markerPos ) 567 d_data->stepsIncrement = -d_data->stepsIncrement;568 m_data->stepsIncrement = -m_data->stepsIncrement; 568 569 } 569 570 else 570 571 { 571 572 if ( pos.y() < markerPos ) 572 d_data->stepsIncrement = -d_data->stepsIncrement;573 m_data->stepsIncrement = -m_data->stepsIncrement; 573 574 } 574 575 575 576 if ( isInverted() ) 576 d_data->stepsIncrement = -d_data->stepsIncrement;577 m_data->stepsIncrement = -m_data->stepsIncrement; 577 578 578 579 const double v = value(); 579 incrementValue( d_data->stepsIncrement );580 incrementValue( m_data->stepsIncrement ); 580 581 581 582 if ( v != value() ) … … 584 585 Q_EMIT valueChanged( value() ); 585 586 else 586 d_data->pendingValueChange = true;587 m_data->pendingValueChange = true; 587 588 588 589 Q_EMIT sliderMoved( value() ); 589 590 } 590 591 591 d_data->timerTick = false;592 d_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) );592 m_data->timerTick = false; 593 m_data->repeatTimerId = startTimer( qMax( 250, 2 * updateInterval() ) ); 593 594 594 595 return; … … 602 603 Mouse release event handler 603 604 \param event Mouse event 604 */ 605 void QwtSlider::mouseReleaseEvent( QMouseEvent *event )606 { 607 if ( d_data->repeatTimerId > 0 )608 { 609 killTimer( d_data->repeatTimerId );610 d_data->repeatTimerId = 0;611 d_data->timerTick = false;612 d_data->stepsIncrement = 0;613 } 614 615 if ( d_data->pendingValueChange )616 { 617 d_data->pendingValueChange = false;605 */ 606 void QwtSlider::mouseReleaseEvent( QMouseEvent* event ) 607 { 608 if ( m_data->repeatTimerId > 0 ) 609 { 610 killTimer( m_data->repeatTimerId ); 611 m_data->repeatTimerId = 0; 612 m_data->timerTick = false; 613 m_data->stepsIncrement = 0; 614 } 615 616 if ( m_data->pendingValueChange ) 617 { 618 m_data->pendingValueChange = false; 618 619 Q_EMIT valueChanged( value() ); 619 620 } … … 629 630 630 631 \param event Mouse event 631 */ 632 void QwtSlider::timerEvent( QTimerEvent *event )633 { 634 if ( event->timerId() != d_data->repeatTimerId )632 */ 633 void QwtSlider::timerEvent( QTimerEvent* event ) 634 { 635 if ( event->timerId() != m_data->repeatTimerId ) 635 636 { 636 637 QwtAbstractSlider::timerEvent( event ); … … 640 641 if ( !isValid() ) 641 642 { 642 killTimer( d_data->repeatTimerId );643 d_data->repeatTimerId = 0;643 killTimer( m_data->repeatTimerId ); 644 m_data->repeatTimerId = 0; 644 645 return; 645 646 } 646 647 647 648 const double v = value(); 648 incrementValue( d_data->stepsIncrement );649 incrementValue( m_data->stepsIncrement ); 649 650 650 651 if ( v != value() ) … … 653 654 Q_EMIT valueChanged( value() ); 654 655 else 655 d_data->pendingValueChange = true;656 m_data->pendingValueChange = true; 656 657 657 658 Q_EMIT sliderMoved( value() ); 658 659 } 659 660 660 if ( ! d_data->timerTick )661 if ( !m_data->timerTick ) 661 662 { 662 663 // restart the timer with a shorter interval 663 killTimer( d_data->repeatTimerId );664 d_data->repeatTimerId = startTimer( updateInterval() );665 666 d_data->timerTick = true;664 killTimer( m_data->repeatTimerId ); 665 m_data->repeatTimerId = startTimer( updateInterval() ); 666 667 m_data->timerTick = true; 667 668 } 668 669 } … … 671 672 Qt paint event handler 672 673 \param event Paint event 673 */ 674 void QwtSlider::paintEvent( QPaintEvent *event )674 */ 675 void QwtSlider::paintEvent( QPaintEvent* event ) 675 676 { 676 677 QPainter painter( this ); … … 678 679 679 680 QStyleOption opt; 680 opt.init(this); 681 opt.initFrom(this); 681 682 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 682 683 683 if ( d_data->scalePosition != QwtSlider::NoScale )684 { 685 if ( ! d_data->sliderRect.contains( event->rect() ) )684 if ( m_data->scalePosition != QwtSlider::NoScale ) 685 { 686 if ( !m_data->sliderRect.contains( event->rect() ) ) 686 687 scaleDraw()->draw( &painter, palette() ); 687 688 } 688 689 689 drawSlider( &painter, d_data->sliderRect );690 drawSlider( &painter, m_data->sliderRect ); 690 691 691 692 if ( hasFocus() ) 692 QwtPainter::drawFocusRect( &painter, this, d_data->sliderRect );693 QwtPainter::drawFocusRect( &painter, this, m_data->sliderRect ); 693 694 } 694 695 … … 696 697 Qt resize event handler 697 698 \param event Resize event 698 */ 699 void QwtSlider::resizeEvent( QResizeEvent *event ) 700 { 701 Q_UNUSED( event ); 702 699 */ 700 void QwtSlider::resizeEvent( QResizeEvent* event ) 701 { 703 702 layoutSlider( false ); 703 QwtAbstractSlider::resizeEvent( event ); 704 } 705 706 /*! 707 Qt event handler 708 \param event Event 709 710 \return true, if event was recognized and processed 711 */ 712 bool QwtSlider::event( QEvent* event ) 713 { 714 if ( event->type() == QEvent::PolishRequest ) 715 layoutSlider( false ); 716 717 return QwtAbstractSlider::event( event ); 704 718 } 705 719 … … 707 721 Handles QEvent::StyleChange and QEvent::FontChange events 708 722 \param event Change event 709 */ 710 void QwtSlider::changeEvent( QEvent *event )723 */ 724 void QwtSlider::changeEvent( QEvent* event ) 711 725 { 712 726 if ( event->type() == QEvent::StyleChange || … … 721 735 722 736 /*! 723 Recalculate the slider's geometry and layout based on 724 the current geometry and fonts. 725 726 \param update_geometry notify the layout system and call update 737 Recalculate the slider's geometry and layout based on 738 the current geometry and fonts. 739 740 \param update_geometry notify the layout system and call update 727 741 to redraw the scale 728 */ 742 */ 729 743 void QwtSlider::layoutSlider( bool update_geometry ) 730 744 { 731 745 int bw = 0; 732 if ( d_data->hasTrough )733 bw = d_data->borderWidth;734 735 const QSize handleSize = qwtHandleSize( d_data->handleSize,736 d_data->orientation,d_data->hasTrough );746 if ( m_data->hasTrough ) 747 bw = m_data->borderWidth; 748 749 const QSize handleSize = qwtHandleSize( m_data->handleSize, 750 m_data->orientation, m_data->hasTrough ); 737 751 738 752 QRect sliderRect = contentsRect(); … … 752 766 753 767 int scaleMargin = 0; 754 if ( d_data->scalePosition != QwtSlider::NoScale )768 if ( m_data->scalePosition != QwtSlider::NoScale ) 755 769 { 756 770 int d1, d2; … … 762 776 int scaleX, scaleY, scaleLength; 763 777 764 if ( d_data->orientation == Qt::Horizontal )778 if ( m_data->orientation == Qt::Horizontal ) 765 779 { 766 780 const int handleMargin = handleSize.width() / 2 - 1; … … 791 805 // now align slider and scale according to the ScalePosition 792 806 793 if ( d_data->orientation == Qt::Horizontal )807 if ( m_data->orientation == Qt::Horizontal ) 794 808 { 795 809 const int h = handleSize.height() + 2 * bw; 796 810 797 if ( d_data->scalePosition == QwtSlider::TrailingScale )811 if ( m_data->scalePosition == QwtSlider::TrailingScale ) 798 812 { 799 813 sliderRect.setTop( sliderRect.bottom() + 1 - h ); 800 scaleY = sliderRect.top() - d_data->spacing;814 scaleY = sliderRect.top() - m_data->spacing; 801 815 } 802 816 else 803 817 { 804 818 sliderRect.setHeight( h ); 805 scaleY = sliderRect.bottom() + 1 + d_data->spacing;819 scaleY = sliderRect.bottom() + 1 + m_data->spacing; 806 820 } 807 821 } … … 810 824 const int w = handleSize.width() + 2 * bw; 811 825 812 if ( d_data->scalePosition == QwtSlider::LeadingScale )826 if ( m_data->scalePosition == QwtSlider::LeadingScale ) 813 827 { 814 828 sliderRect.setWidth( w ); 815 scaleX = sliderRect.right() + 1 + d_data->spacing;829 scaleX = sliderRect.right() + 1 + m_data->spacing; 816 830 } 817 831 else 818 832 { 819 833 sliderRect.setLeft( sliderRect.right() + 1 - w ); 820 scaleX = sliderRect.left() - d_data->spacing;834 scaleX = sliderRect.left() - m_data->spacing; 821 835 } 822 836 } 823 837 824 d_data->sliderRect = sliderRect;838 m_data->sliderRect = sliderRect; 825 839 826 840 scaleDraw()->move( scaleX, scaleY ); … … 829 843 if ( update_geometry ) 830 844 { 831 d_data->sizeHintCache = QSize(); // invalidate845 m_data->sizeHintCache = QSize(); // invalidate 832 846 updateGeometry(); 833 847 update(); … … 836 850 837 851 /*! 838 En/Disable the trough 839 840 The slider can be cutomized by showing a trough for the 841 handle. 842 843 \param on When true, the groove is visible 844 \sa hasTrough(), setGroove() 852 En/Disable the trough 853 854 The slider can be customized by showing a trough for the 855 handle. 856 857 \param on When true, the groove is visible 858 \sa hasTrough(), setGroove() 845 859 */ 846 860 void QwtSlider::setTrough( bool on ) 847 861 { 848 if ( d_data->hasTrough != on )849 { 850 d_data->hasTrough = on;862 if ( m_data->hasTrough != on ) 863 { 864 m_data->hasTrough = on; 851 865 852 866 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 856 870 857 871 /*! 858 \return True, when the trough is visi sble859 \sa setTrough(), hasGroove() 872 \return True, when the trough is visible 873 \sa setTrough(), hasGroove() 860 874 */ 861 875 bool QwtSlider::hasTrough() const 862 876 { 863 return d_data->hasTrough;864 } 865 866 /*! 867 En/Disable the groove 868 869 The slider can be cutomized by showing a groove for the 870 handle. 871 872 \param on When true, the groove is visible 873 \sa hasGroove(), setThrough() 877 return m_data->hasTrough; 878 } 879 880 /*! 881 En/Disable the groove 882 883 The slider can be customized by showing a groove for the 884 handle. 885 886 \param on When true, the groove is visible 887 \sa hasGroove(), setThrough() 874 888 */ 875 889 void QwtSlider::setGroove( bool on ) 876 890 { 877 if ( d_data->hasGroove != on )878 { 879 d_data->hasGroove = on;891 if ( m_data->hasGroove != on ) 892 { 893 m_data->hasGroove = on; 880 894 881 895 if ( testAttribute( Qt::WA_WState_Polished ) ) … … 885 899 886 900 /*! 887 \return True, when the groove is visi sble888 \sa setGroove(), hasTrough() 901 \return True, when the groove is visible 902 \sa setGroove(), hasTrough() 889 903 */ 890 904 bool QwtSlider::hasGroove() const 891 905 { 892 return d_data->hasGroove;893 } 894 895 /*! 896 \return minimumSizeHint() 897 */ 906 return m_data->hasGroove; 907 } 908 909 /*! 910 \return minimumSizeHint() 911 */ 898 912 QSize QwtSlider::sizeHint() const 899 913 { 900 914 const QSize hint = minimumSizeHint(); 901 return hint.expandedTo( QApplication::globalStrut());902 } 903 904 /*! 905 \return Minimum size hint 906 \sa sizeHint() 907 */ 915 return qwtExpandedToGlobalStrut( hint ); 916 } 917 918 /*! 919 \return Minimum size hint 920 \sa sizeHint() 921 */ 908 922 QSize QwtSlider::minimumSizeHint() const 909 923 { 910 if ( ! d_data->sizeHintCache.isEmpty() )911 return d_data->sizeHintCache;912 913 const QSize handleSize = qwtHandleSize( d_data->handleSize,914 d_data->orientation,d_data->hasTrough );924 if ( !m_data->sizeHintCache.isEmpty() ) 925 return m_data->sizeHintCache; 926 927 const QSize handleSize = qwtHandleSize( m_data->handleSize, 928 m_data->orientation, m_data->hasTrough ); 915 929 916 930 int bw = 0; 917 if ( d_data->hasTrough )918 bw = d_data->borderWidth;931 if ( m_data->hasTrough ) 932 bw = m_data->borderWidth; 919 933 920 934 int sliderLength = 0; 921 935 int scaleExtent = 0; 922 936 923 if ( d_data->scalePosition != QwtSlider::NoScale )937 if ( m_data->scalePosition != QwtSlider::NoScale ) 924 938 { 925 939 int d1, d2; … … 929 943 930 944 int handleBorderDist; 931 if ( d_data->orientation == Qt::Horizontal )945 if ( m_data->orientation == Qt::Horizontal ) 932 946 handleBorderDist = handleSize.width(); 933 947 else … … 941 955 } 942 956 943 scaleExtent += d_data->spacing;944 scaleExtent += qCeil( scaleDraw()->extent( font() ) ); 957 scaleExtent += m_data->spacing; 958 scaleExtent += qwtCeil( scaleDraw()->extent( font() ) ); 945 959 } 946 960 … … 950 964 int h = 0; 951 965 952 if ( d_data->orientation == Qt::Horizontal )966 if ( m_data->orientation == Qt::Horizontal ) 953 967 { 954 968 w = sliderLength; … … 962 976 963 977 // finally add margins 964 int left, right, top, bottom; 965 getContentsMargins( &left, &top, &right, &bottom ); 966 967 w += left + right; 968 h += top + bottom; 969 970 d_data->sizeHintCache = QSize( w, h ); 971 return d_data->sizeHintCache; 978 const QMargins m = contentsMargins(); 979 980 w += m.left() + m.right(); 981 h += m.top() + m.bottom(); 982 983 m_data->sizeHintCache = QSize( w, h ); 984 return m_data->sizeHintCache; 972 985 } 973 986 … … 982 995 const int markerPos = transform( value() ); 983 996 984 QPoint center = d_data->sliderRect.center();985 if ( d_data->orientation == Qt::Horizontal )997 QPoint center = m_data->sliderRect.center(); 998 if ( m_data->orientation == Qt::Horizontal ) 986 999 center.setX( markerPos ); 987 1000 else … … 989 1002 990 1003 QRect rect; 991 rect.setSize( qwtHandleSize( d_data->handleSize,992 d_data->orientation,d_data->hasTrough ) );1004 rect.setSize( qwtHandleSize( m_data->handleSize, 1005 m_data->orientation, m_data->hasTrough ) ); 993 1006 rect.moveCenter( center ); 994 1007 … … 997 1010 998 1011 /*! 999 \return Bounding rectangle of the slider - without the scale 1012 \return Bounding rectangle of the slider - without the scale 1000 1013 */ 1001 1014 QRect QwtSlider::sliderRect() const 1002 1015 { 1003 return d_data->sliderRect; 1004 } 1016 return m_data->sliderRect; 1017 } 1018 1019 #include "moc_qwt_slider.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
