Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_scale_widget.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_scale_widget.cpp (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_scale_widget.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 15 15 #include "qwt_scale_div.h" 16 16 #include "qwt_text.h" 17 #include "qwt_interval.h" 17 18 #include "qwt_scale_engine.h" 19 18 20 #include <qpainter.h> 19 21 #include <qevent.h> 20 #include <qmath.h>21 22 #include <qstyle.h> 22 23 #include <qstyleoption.h> 23 24 #include <qapplication.h> 25 #include <qmargins.h> 24 26 25 27 class QwtScaleWidget::PrivateData 26 28 { 27 public: 28 PrivateData() :29 scaleDraw( NULL ) 29 public: 30 PrivateData() 31 : scaleDraw( NULL ) 30 32 { 31 33 colorBar.colorMap = NULL; … … 38 40 } 39 41 40 QwtScaleDraw *scaleDraw;42 QwtScaleDraw* scaleDraw; 41 43 42 44 int borderDist[2]; … … 56 58 int width; 57 59 QwtInterval interval; 58 QwtColorMap *colorMap;60 QwtColorMap* colorMap; 59 61 } colorBar; 60 62 }; 61 63 62 64 /*! 63 \brief Create a scale with the position QwtScaleWidget::Left 64 \param parent Parent widget 65 */ 66 QwtScaleWidget::QwtScaleWidget( QWidget *parent ):67 QWidget( parent ) 65 \brief Create a scale with the position QwtScaleWidget::Left 66 \param parent Parent widget 67 */ 68 QwtScaleWidget::QwtScaleWidget( QWidget* parent ) 69 : QWidget( parent ) 68 70 { 69 71 initScale( QwtScaleDraw::LeftScale ); … … 71 73 72 74 /*! 73 \brief Constructor 74 \param align Alignment. 75 \param parent Parent widget 76 */ 77 QwtScaleWidget::QwtScaleWidget( 78 QwtScaleDraw::Alignment align, QWidget *parent ): 79 QWidget( parent ) 75 \brief Constructor 76 \param align Alignment. 77 \param parent Parent widget 78 */ 79 QwtScaleWidget::QwtScaleWidget( QwtScaleDraw::Alignment align, QWidget* parent ) 80 : QWidget( parent ) 80 81 { 81 82 initScale( align ); … … 85 86 QwtScaleWidget::~QwtScaleWidget() 86 87 { 87 delete d_data;88 delete m_data; 88 89 } 89 90 … … 91 92 void QwtScaleWidget::initScale( QwtScaleDraw::Alignment align ) 92 93 { 93 d_data = new PrivateData; 94 95 d_data->layoutFlags = 0; 94 m_data = new PrivateData; 95 96 96 if ( align == QwtScaleDraw::RightScale ) 97 d_data->layoutFlags |= TitleInverted;98 99 d_data->borderDist[0] = 0;100 d_data->borderDist[1] = 0;101 d_data->minBorderDist[0] = 0;102 d_data->minBorderDist[1] = 0;103 d_data->margin = 4;104 d_data->titleOffset = 0;105 d_data->spacing = 2;106 107 d_data->scaleDraw = new QwtScaleDraw;108 d_data->scaleDraw->setAlignment( align );109 d_data->scaleDraw->setLength( 10 );110 111 d_data->scaleDraw->setScaleDiv(97 m_data->layoutFlags |= TitleInverted; 98 99 m_data->borderDist[0] = 0; 100 m_data->borderDist[1] = 0; 101 m_data->minBorderDist[0] = 0; 102 m_data->minBorderDist[1] = 0; 103 m_data->margin = 4; 104 m_data->titleOffset = 0; 105 m_data->spacing = 2; 106 107 m_data->scaleDraw = new QwtScaleDraw; 108 m_data->scaleDraw->setAlignment( align ); 109 m_data->scaleDraw->setLength( 10 ); 110 111 m_data->scaleDraw->setScaleDiv( 112 112 QwtLinearScaleEngine().divideScale( 0.0, 100.0, 10, 5 ) ); 113 113 114 d_data->colorBar.colorMap = new QwtLinearColorMap();115 d_data->colorBar.isEnabled = false;116 d_data->colorBar.width = 10;114 m_data->colorBar.colorMap = new QwtLinearColorMap(); 115 m_data->colorBar.isEnabled = false; 116 m_data->colorBar.width = 10; 117 117 118 118 const int flags = Qt::AlignHCenter 119 119 | Qt::TextExpandTabs | Qt::TextWordWrap; 120 d_data->title.setRenderFlags( flags );121 d_data->title.setFont( font() );120 m_data->title.setRenderFlags( flags ); 121 m_data->title.setFont( font() ); 122 122 123 123 QSizePolicy policy( QSizePolicy::MinimumExpanding, 124 124 QSizePolicy::Fixed ); 125 if ( d_data->scaleDraw->orientation() == Qt::Vertical )125 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 126 126 policy.transpose(); 127 127 … … 138 138 139 139 \sa testLayoutFlag(), LayoutFlag 140 */ 140 */ 141 141 void QwtScaleWidget::setLayoutFlag( LayoutFlag flag, bool on ) 142 142 { 143 if ( ( ( d_data->layoutFlags & flag ) != 0 ) != on )143 if ( ( ( m_data->layoutFlags & flag ) != 0 ) != on ) 144 144 { 145 145 if ( on ) 146 d_data->layoutFlags |= flag;146 m_data->layoutFlags |= flag; 147 147 else 148 d_data->layoutFlags &= ~flag;148 m_data->layoutFlags &= ~flag; 149 149 150 150 update(); … … 158 158 \return true/false 159 159 \sa setLayoutFlag(), LayoutFlag 160 */ 160 */ 161 161 bool QwtScaleWidget::testLayoutFlag( LayoutFlag flag ) const 162 162 { 163 return ( d_data->layoutFlags & flag );164 } 165 166 /*! 167 Give title new text contents 168 169 \param title New title 170 \sa title(), setTitle(const QwtText &); 171 */ 172 void QwtScaleWidget::setTitle( const QString &title )173 { 174 if ( d_data->title.text() != title )175 { 176 d_data->title.setText( title );163 return ( m_data->layoutFlags & flag ); 164 } 165 166 /*! 167 Give title new text contents 168 169 \param title New title 170 \sa title(), setTitle(const QwtText &); 171 */ 172 void QwtScaleWidget::setTitle( const QString& title ) 173 { 174 if ( m_data->title.text() != title ) 175 { 176 m_data->title.setText( title ); 177 177 layoutScale(); 178 178 } … … 180 180 181 181 /*! 182 Give title new text contents 183 184 \param title New title 185 \sa title() 186 \warning The title flags are interpreted in 182 Give title new text contents 183 184 \param title New title 185 \sa title() 186 \warning The title flags are interpreted in 187 187 direction of the label, AlignTop, AlignBottom can't be set 188 188 as the title will always be aligned to the scale. 189 */ 190 void QwtScaleWidget::setTitle( const QwtText &title )189 */ 190 void QwtScaleWidget::setTitle( const QwtText& title ) 191 191 { 192 192 QwtText t = title; … … 194 194 t.setRenderFlags( flags ); 195 195 196 if ( t != d_data->title )197 { 198 d_data->title = t;196 if ( t != m_data->title ) 197 { 198 m_data->title = t; 199 199 layoutScale(); 200 200 } … … 202 202 203 203 /*! 204 Change the alignment 205 206 \param alignment New alignment 207 \sa alignment() 208 */ 204 Change the alignment 205 206 \param alignment New alignment 207 \sa alignment() 208 */ 209 209 void QwtScaleWidget::setAlignment( QwtScaleDraw::Alignment alignment ) 210 210 { 211 if ( d_data->scaleDraw ) 212 d_data->scaleDraw->setAlignment( alignment ); 211 if ( m_data->scaleDraw == NULL ) 212 return; 213 214 m_data->scaleDraw->setAlignment( alignment ); 213 215 214 216 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) ) 215 217 { 216 QSizePolicy policy( QSizePolicy::MinimumExpanding, 217 QSizePolicy::Fixed ); 218 if ( d_data->scaleDraw->orientation() == Qt::Vertical ) 218 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ); 219 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 219 220 policy.transpose(); 220 221 … … 231 232 \return position 232 233 \sa setPosition() 233 */ 234 */ 234 235 QwtScaleDraw::Alignment QwtScaleWidget::alignment() const 235 236 { … … 241 242 242 243 /*! 243 Specify distances of the scale's endpoints from the 244 widget's borders. The actual borders will never be less 245 than minimum border distance. 246 \param dist1 Left or top Distance 247 \param dist2 Right or bottom distance 248 \sa borderDist() 249 */ 244 Specify distances of the scale's endpoints from the 245 widget's borders. The actual borders will never be less 246 than minimum border distance. 247 \param dist1 Left or top Distance 248 \param dist2 Right or bottom distance 249 \sa borderDist() 250 */ 250 251 void QwtScaleWidget::setBorderDist( int dist1, int dist2 ) 251 252 { 252 if ( dist1 != d_data->borderDist[0] || dist2 !=d_data->borderDist[1] )253 { 254 d_data->borderDist[0] = dist1;255 d_data->borderDist[1] = dist2;253 if ( dist1 != m_data->borderDist[0] || dist2 != m_data->borderDist[1] ) 254 { 255 m_data->borderDist[0] = dist1; 256 m_data->borderDist[1] = dist2; 256 257 layoutScale(); 257 258 } … … 259 260 260 261 /*! 261 \brief Specify the margin to the colorBar/base line. 262 \param margin Margin 263 \sa margin() 264 */ 262 \brief Specify the margin to the colorBar/base line. 263 \param margin Margin 264 \sa margin() 265 */ 265 266 void QwtScaleWidget::setMargin( int margin ) 266 267 { 267 268 margin = qMax( 0, margin ); 268 if ( margin != d_data->margin )269 { 270 d_data->margin = margin;269 if ( margin != m_data->margin ) 270 { 271 m_data->margin = margin; 271 272 layoutScale(); 272 273 } … … 274 275 275 276 /*! 276 \brief Specify the distance between color bar, scale and title 277 \param spacing Spacing 278 \sa spacing() 279 */ 277 \brief Specify the distance between color bar, scale and title 278 \param spacing Spacing 279 \sa spacing() 280 */ 280 281 void QwtScaleWidget::setSpacing( int spacing ) 281 282 { 282 283 spacing = qMax( 0, spacing ); 283 if ( spacing != d_data->spacing )284 { 285 d_data->spacing = spacing;284 if ( spacing != m_data->spacing ) 285 { 286 m_data->spacing = spacing; 286 287 layoutScale(); 287 288 } … … 289 290 290 291 /*! 291 \brief Change the alignment for the labels. 292 293 \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation() 294 */ 292 \brief Change the alignment for the labels. 293 294 \sa QwtScaleDraw::setLabelAlignment(), setLabelRotation() 295 */ 295 296 void QwtScaleWidget::setLabelAlignment( Qt::Alignment alignment ) 296 297 { 297 d_data->scaleDraw->setLabelAlignment( alignment );298 m_data->scaleDraw->setLabelAlignment( alignment ); 298 299 layoutScale(); 299 300 } 300 301 301 302 /*! 302 \brief Change the rotation for the labels. 303 See QwtScaleDraw::setLabelRotation(). 304 305 \param rotation Rotation 306 \sa QwtScaleDraw::setLabelRotation(), setLabelFlags() 307 */ 303 \brief Change the rotation for the labels. 304 See QwtScaleDraw::setLabelRotation(). 305 306 \param rotation Rotation 307 \sa QwtScaleDraw::setLabelRotation(), setLabelFlags() 308 */ 308 309 void QwtScaleWidget::setLabelRotation( double rotation ) 309 310 { 310 d_data->scaleDraw->setLabelRotation( rotation );311 m_data->scaleDraw->setLabelRotation( rotation ); 311 312 layoutScale(); 312 313 } 313 314 314 315 /*! 315 Set a scale draw 316 317 scaleDraw has to be created with new and will be deleted in 318 ~QwtScaleWidget() or the next call of setScaleDraw(). 319 scaleDraw will be initialized with the attributes of 320 the previous scaleDraw object. 321 322 \param scaleDraw ScaleDraw object 323 \sa scaleDraw() 324 */ 325 void QwtScaleWidget::setScaleDraw( QwtScaleDraw *scaleDraw )326 { 327 if ( ( scaleDraw == NULL ) || ( scaleDraw == d_data->scaleDraw ) )316 Set a scale draw 317 318 scaleDraw has to be created with new and will be deleted in 319 ~QwtScaleWidget() or the next call of setScaleDraw(). 320 scaleDraw will be initialized with the attributes of 321 the previous scaleDraw object. 322 323 \param scaleDraw ScaleDraw object 324 \sa scaleDraw() 325 */ 326 void QwtScaleWidget::setScaleDraw( QwtScaleDraw* scaleDraw ) 327 { 328 if ( ( scaleDraw == NULL ) || ( scaleDraw == m_data->scaleDraw ) ) 328 329 return; 329 330 330 const QwtScaleDraw* sd = d_data->scaleDraw;331 const QwtScaleDraw* sd = m_data->scaleDraw; 331 332 if ( sd ) 332 333 { … … 334 335 scaleDraw->setScaleDiv( sd->scaleDiv() ); 335 336 336 QwtTransform *transform = NULL;337 QwtTransform* transform = NULL; 337 338 if ( sd->scaleMap().transformation() ) 338 339 transform = sd->scaleMap().transformation()->copy(); … … 341 342 } 342 343 343 delete d_data->scaleDraw;344 d_data->scaleDraw = scaleDraw;344 delete m_data->scaleDraw; 345 m_data->scaleDraw = scaleDraw; 345 346 346 347 layoutScale(); … … 350 351 \return scaleDraw of this scale 351 352 \sa setScaleDraw(), QwtScaleDraw::setScaleDraw() 352 */ 353 const QwtScaleDraw *QwtScaleWidget::scaleDraw() const354 { 355 return d_data->scaleDraw;353 */ 354 const QwtScaleDraw* QwtScaleWidget::scaleDraw() const 355 { 356 return m_data->scaleDraw; 356 357 } 357 358 … … 359 360 \return scaleDraw of this scale 360 361 \sa QwtScaleDraw::setScaleDraw() 361 */ 362 QwtScaleDraw *QwtScaleWidget::scaleDraw()363 { 364 return d_data->scaleDraw;362 */ 363 QwtScaleDraw* QwtScaleWidget::scaleDraw() 364 { 365 return m_data->scaleDraw; 365 366 } 366 367 … … 368 369 \return title 369 370 \sa setTitle() 370 */ 371 */ 371 372 QwtText QwtScaleWidget::title() const 372 373 { 373 return d_data->title;374 return m_data->title; 374 375 } 375 376 … … 377 378 \return start border distance 378 379 \sa setBorderDist() 379 */ 380 */ 380 381 int QwtScaleWidget::startBorderDist() const 381 382 { 382 return d_data->borderDist[0];383 return m_data->borderDist[0]; 383 384 } 384 385 … … 386 387 \return end border distance 387 388 \sa setBorderDist() 388 */ 389 */ 389 390 int QwtScaleWidget::endBorderDist() const 390 391 { 391 return d_data->borderDist[1];392 return m_data->borderDist[1]; 392 393 } 393 394 … … 395 396 \return margin 396 397 \sa setMargin() 397 */ 398 */ 398 399 int QwtScaleWidget::margin() const 399 400 { 400 return d_data->margin;401 return m_data->margin; 401 402 } 402 403 … … 404 405 \return distance between scale and title 405 406 \sa setMargin() 406 */ 407 */ 407 408 int QwtScaleWidget::spacing() const 408 409 { 409 return d_data->spacing;410 } 411 412 /*! 413 \brief paintEvent 414 */ 415 void QwtScaleWidget::paintEvent( QPaintEvent *event )410 return m_data->spacing; 411 } 412 413 /*! 414 \brief paintEvent 415 */ 416 void QwtScaleWidget::paintEvent( QPaintEvent* event ) 416 417 { 417 418 QPainter painter( this ); … … 419 420 420 421 QStyleOption opt; 421 opt.init(this); 422 opt.initFrom(this); 422 423 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); 423 424 … … 426 427 427 428 /*! 428 \brief draw the scale 429 */ 430 void QwtScaleWidget::draw( QPainter *painter ) const431 { 432 d_data->scaleDraw->draw( painter, palette() );433 434 if ( d_data->colorBar.isEnabled &&d_data->colorBar.width > 0 &&435 d_data->colorBar.interval.isValid() )429 \brief draw the scale 430 */ 431 void QwtScaleWidget::draw( QPainter* painter ) const 432 { 433 m_data->scaleDraw->draw( painter, palette() ); 434 435 if ( m_data->colorBar.isEnabled && m_data->colorBar.width > 0 && 436 m_data->colorBar.interval.isValid() ) 436 437 { 437 438 drawColorBar( painter, colorBarRect( contentsRect() ) ); … … 439 440 440 441 QRect r = contentsRect(); 441 if ( d_data->scaleDraw->orientation() == Qt::Horizontal )442 { 443 r.setLeft( r.left() + d_data->borderDist[0] );444 r.setWidth( r.width() - d_data->borderDist[1] );442 if ( m_data->scaleDraw->orientation() == Qt::Horizontal ) 443 { 444 r.setLeft( r.left() + m_data->borderDist[0] ); 445 r.setWidth( r.width() - m_data->borderDist[1] ); 445 446 } 446 447 else 447 448 { 448 r.setTop( r.top() + d_data->borderDist[0] );449 r.setHeight( r.height() - d_data->borderDist[1] );450 } 451 452 if ( ! d_data->title.isEmpty() )453 drawTitle( painter, d_data->scaleDraw->alignment(), r );454 } 455 456 /*! 457 Calculate the the rectangle for the color bar 458 459 \param rect Bounding rectangle for all components of the scale 460 \return Rectangle for the color bar 461 */ 449 r.setTop( r.top() + m_data->borderDist[0] ); 450 r.setHeight( r.height() - m_data->borderDist[1] ); 451 } 452 453 if ( !m_data->title.isEmpty() ) 454 drawTitle( painter, m_data->scaleDraw->alignment(), r ); 455 } 456 457 /*! 458 Calculate the the rectangle for the color bar 459 460 \param rect Bounding rectangle for all components of the scale 461 \return Rectangle for the color bar 462 */ 462 463 QRectF QwtScaleWidget::colorBarRect( const QRectF& rect ) const 463 464 { 464 465 QRectF cr = rect; 465 466 466 if ( d_data->scaleDraw->orientation() == Qt::Horizontal )467 { 468 cr.setLeft( cr.left() + d_data->borderDist[0] );469 cr.setWidth( cr.width() - d_data->borderDist[1] + 1 );467 if ( m_data->scaleDraw->orientation() == Qt::Horizontal ) 468 { 469 cr.setLeft( cr.left() + m_data->borderDist[0] ); 470 cr.setWidth( cr.width() - m_data->borderDist[1] + 1 ); 470 471 } 471 472 else 472 473 { 473 cr.setTop( cr.top() + d_data->borderDist[0] );474 cr.setHeight( cr.height() - d_data->borderDist[1] + 1 );475 } 476 477 switch ( d_data->scaleDraw->alignment() )474 cr.setTop( cr.top() + m_data->borderDist[0] ); 475 cr.setHeight( cr.height() - m_data->borderDist[1] + 1 ); 476 } 477 478 switch ( m_data->scaleDraw->alignment() ) 478 479 { 479 480 case QwtScaleDraw::LeftScale: 480 481 { 481 cr.setLeft( cr.right() - d_data->margin482 - d_data->colorBar.width );483 cr.setWidth( d_data->colorBar.width );482 cr.setLeft( cr.right() - m_data->margin 483 - m_data->colorBar.width ); 484 cr.setWidth( m_data->colorBar.width ); 484 485 break; 485 486 } … … 487 488 case QwtScaleDraw::RightScale: 488 489 { 489 cr.setLeft( cr.left() + d_data->margin );490 cr.setWidth( d_data->colorBar.width );490 cr.setLeft( cr.left() + m_data->margin ); 491 cr.setWidth( m_data->colorBar.width ); 491 492 break; 492 493 } … … 494 495 case QwtScaleDraw::BottomScale: 495 496 { 496 cr.setTop( cr.top() + d_data->margin );497 cr.setHeight( d_data->colorBar.width );497 cr.setTop( cr.top() + m_data->margin ); 498 cr.setHeight( m_data->colorBar.width ); 498 499 break; 499 500 } … … 501 502 case QwtScaleDraw::TopScale: 502 503 { 503 cr.setTop( cr.bottom() - d_data->margin504 - d_data->colorBar.width );505 cr.setHeight( d_data->colorBar.width );504 cr.setTop( cr.bottom() - m_data->margin 505 - m_data->colorBar.width ); 506 cr.setHeight( m_data->colorBar.width ); 506 507 break; 507 508 } … … 512 513 513 514 /*! 514 Event handler for resize events 515 \param event Resize event 516 */ 517 void QwtScaleWidget::resizeEvent( QResizeEvent *event ) 515 Change Event handler 516 \param event Change event 517 518 Invalidates internal caches if necessary 519 */ 520 void QwtScaleWidget::changeEvent( QEvent* event ) 521 { 522 if ( event->type() == QEvent::LocaleChange ) 523 { 524 m_data->scaleDraw->invalidateCache(); 525 } 526 527 QWidget::changeEvent( event ); 528 } 529 530 /*! 531 Event handler for resize events 532 \param event Resize event 533 */ 534 void QwtScaleWidget::resizeEvent( QResizeEvent* event ) 518 535 { 519 536 Q_UNUSED( event ); … … 522 539 523 540 /*! 524 Recalculate the scale's geometry and layout based on 525 the current geometry and fonts. 526 527 \param update_geometry Notify the layout system and call update 541 Recalculate the scale's geometry and layout based on 542 the current geometry and fonts. 543 544 \param update_geometry Notify the layout system and call update 528 545 to redraw the scale 529 */ 546 */ 530 547 531 548 void QwtScaleWidget::layoutScale( bool update_geometry ) … … 533 550 int bd0, bd1; 534 551 getBorderDistHint( bd0, bd1 ); 535 if ( d_data->borderDist[0] > bd0 )536 bd0 = d_data->borderDist[0];537 if ( d_data->borderDist[1] > bd1 )538 bd1 = d_data->borderDist[1];552 if ( m_data->borderDist[0] > bd0 ) 553 bd0 = m_data->borderDist[0]; 554 if ( m_data->borderDist[1] > bd1 ) 555 bd1 = m_data->borderDist[1]; 539 556 540 557 int colorBarWidth = 0; 541 if ( d_data->colorBar.isEnabled &&d_data->colorBar.interval.isValid() )542 colorBarWidth = d_data->colorBar.width +d_data->spacing;558 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() ) 559 colorBarWidth = m_data->colorBar.width + m_data->spacing; 543 560 544 561 const QRectF r = contentsRect(); 545 562 double x, y, length; 546 563 547 if ( d_data->scaleDraw->orientation() == Qt::Vertical )564 if ( m_data->scaleDraw->orientation() == Qt::Vertical ) 548 565 { 549 566 y = r.top() + bd0; 550 567 length = r.height() - ( bd0 + bd1 ); 551 568 552 if ( d_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale )553 x = r.right() - 1.0 - d_data->margin - colorBarWidth;569 if ( m_data->scaleDraw->alignment() == QwtScaleDraw::LeftScale ) 570 x = r.right() - 1.0 - m_data->margin - colorBarWidth; 554 571 else 555 x = r.left() + d_data->margin + colorBarWidth;572 x = r.left() + m_data->margin + colorBarWidth; 556 573 } 557 574 else … … 560 577 length = r.width() - ( bd0 + bd1 ); 561 578 562 if ( d_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale )563 y = r.top() + d_data->margin + colorBarWidth;579 if ( m_data->scaleDraw->alignment() == QwtScaleDraw::BottomScale ) 580 y = r.top() + m_data->margin + colorBarWidth; 564 581 else 565 y = r.bottom() - 1.0 - d_data->margin - colorBarWidth;566 } 567 568 d_data->scaleDraw->move( x, y );569 d_data->scaleDraw->setLength( length );570 571 const int extent = q Ceil( d_data->scaleDraw->extent( font() ) );572 573 d_data->titleOffset =574 d_data->margin +d_data->spacing + colorBarWidth + extent;582 y = r.bottom() - 1.0 - m_data->margin - colorBarWidth; 583 } 584 585 m_data->scaleDraw->move( x, y ); 586 m_data->scaleDraw->setLength( length ); 587 588 const int extent = qwtCeil( m_data->scaleDraw->extent( font() ) ); 589 590 m_data->titleOffset = 591 m_data->margin + m_data->spacing + colorBarWidth + extent; 575 592 576 593 if ( update_geometry ) … … 599 616 600 617 /*! 601 Draw the color bar of the scale widget 602 603 \param painter Painter 604 \param rect Bounding rectangle for the color bar 605 606 \sa setColorBarEnabled() 607 */ 608 void QwtScaleWidget::drawColorBar( QPainter *painter, const QRectF& rect ) const609 { 610 if ( ! d_data->colorBar.interval.isValid() )618 Draw the color bar of the scale widget 619 620 \param painter Painter 621 \param rect Bounding rectangle for the color bar 622 623 \sa setColorBarEnabled() 624 */ 625 void QwtScaleWidget::drawColorBar( QPainter* painter, const QRectF& rect ) const 626 { 627 if ( !m_data->colorBar.interval.isValid() ) 611 628 return; 612 629 613 const QwtScaleDraw* sd = d_data->scaleDraw;614 615 QwtPainter::drawColorBar( painter, * d_data->colorBar.colorMap,616 d_data->colorBar.interval.normalized(), sd->scaleMap(),630 const QwtScaleDraw* sd = m_data->scaleDraw; 631 632 QwtPainter::drawColorBar( painter, *m_data->colorBar.colorMap, 633 m_data->colorBar.interval.normalized(), sd->scaleMap(), 617 634 sd->orientation(), rect ); 618 635 } 619 636 620 637 /*! 621 Rotate and paint a title according to its position into a given rectangle. 622 623 \param painter Painter 624 \param align Alignment 625 \param rect Bounding rectangle 626 */ 627 628 void QwtScaleWidget::drawTitle( QPainter *painter,629 QwtScaleDraw::Alignment align, const QRectF &rect ) const638 Rotate and paint a title according to its position into a given rectangle. 639 640 \param painter Painter 641 \param align Alignment 642 \param rect Bounding rectangle 643 */ 644 645 void QwtScaleWidget::drawTitle( QPainter* painter, 646 QwtScaleDraw::Alignment align, const QRectF& rect ) const 630 647 { 631 648 QRectF r = rect; 632 649 double angle; 633 int flags = d_data->title.renderFlags() &650 int flags = m_data->title.renderFlags() & 634 651 ~( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter ); 635 652 … … 640 657 flags |= Qt::AlignTop; 641 658 r.setRect( r.left(), r.bottom(), 642 r.height(), r.width() - d_data->titleOffset );659 r.height(), r.width() - m_data->titleOffset ); 643 660 break; 644 661 … … 646 663 angle = -90.0; 647 664 flags |= Qt::AlignTop; 648 r.setRect( r.left() + d_data->titleOffset, r.bottom(),649 r.height(), r.width() - d_data->titleOffset );665 r.setRect( r.left() + m_data->titleOffset, r.bottom(), 666 r.height(), r.width() - m_data->titleOffset ); 650 667 break; 651 668 … … 653 670 angle = 0.0; 654 671 flags |= Qt::AlignBottom; 655 r.setTop( r.top() + d_data->titleOffset );672 r.setTop( r.top() + m_data->titleOffset ); 656 673 break; 657 674 … … 660 677 angle = 0.0; 661 678 flags |= Qt::AlignTop; 662 r.setBottom( r.bottom() - d_data->titleOffset );679 r.setBottom( r.bottom() - m_data->titleOffset ); 663 680 break; 664 681 } 665 682 666 if ( d_data->layoutFlags & TitleInverted )683 if ( m_data->layoutFlags & TitleInverted ) 667 684 { 668 685 if ( align == QwtScaleDraw::LeftScale … … 683 700 painter->rotate( angle ); 684 701 685 QwtText title = d_data->title;702 QwtText title = m_data->title; 686 703 title.setRenderFlags( flags ); 687 704 title.draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) ); … … 691 708 692 709 /*! 693 \brief Notify a change of the scale 694 695 This virtual function can be overloaded by derived 696 classes. The default implementation updates the geometry 697 and repaints the widget. 698 */ 710 \brief Notify a change of the scale 711 712 This virtual function can be overloaded by derived 713 classes. The default implementation updates the geometry 714 and repaints the widget. 715 */ 699 716 700 717 void QwtScaleWidget::scaleChange() … … 704 721 705 722 /*! 706 \return a size hint 707 */ 723 \return a size hint 724 */ 708 725 QSize QwtScaleWidget::sizeHint() const 709 726 { … … 712 729 713 730 /*! 714 \return a minimum size hint 715 */ 731 \return a minimum size hint 732 */ 716 733 QSize QwtScaleWidget::minimumSizeHint() const 717 734 { 718 const Qt::Orientation o = d_data->scaleDraw->orientation();735 const Qt::Orientation o = m_data->scaleDraw->orientation(); 719 736 720 737 // Border Distance cannot be less than the scale borderDistHint … … 723 740 int mbd1, mbd2; 724 741 getBorderDistHint( mbd1, mbd2 ); 725 length += qMax( 0, d_data->borderDist[0] - mbd1 );726 length += qMax( 0, d_data->borderDist[1] - mbd2 );727 length += d_data->scaleDraw->minLength( font() );742 length += qMax( 0, m_data->borderDist[0] - mbd1 ); 743 length += qMax( 0, m_data->borderDist[1] - mbd2 ); 744 length += m_data->scaleDraw->minLength( font() ); 728 745 729 746 int dim = dimForLength( length, font() ); … … 739 756 size.transpose(); 740 757 741 int left, right, top, bottom; 742 getContentsMargins( &left, &top, &right, &bottom ); 743 return size + QSize( left + right, top + bottom ); 744 } 745 746 /*! 747 \brief Find the height of the title for a given width. 748 \param width Width 749 \return height Height 758 const QMargins m = contentsMargins(); 759 return size + QSize( m.left() + m.right(), m.top() + m.bottom() ); 760 } 761 762 /*! 763 \brief Find the height of the title for a given width. 764 \param width Width 765 \return height Height 750 766 */ 751 767 752 768 int QwtScaleWidget::titleHeightForWidth( int width ) const 753 769 { 754 return q Ceil( d_data->title.heightForWidth( width, font() ) );755 } 756 757 /*! 758 \brief Find the minimum dimension for a given length. 770 return qwtCeil( m_data->title.heightForWidth( width, font() ) ); 771 } 772 773 /*! 774 \brief Find the minimum dimension for a given length. 759 775 dim is the height, length the width seen in 760 776 direction of the title. 761 \param length width for horizontal, height for vertical scales 762 \param scaleFont Font of the scale 763 \return height for horizontal, width for vertical scales 764 */ 765 766 int QwtScaleWidget::dimForLength( int length, const QFont &scaleFont ) const767 { 768 const int extent = q Ceil( d_data->scaleDraw->extent( scaleFont ) );769 770 int dim = d_data->margin + extent + 1;771 772 if ( ! d_data->title.isEmpty() )773 dim += titleHeightForWidth( length ) + d_data->spacing;774 775 if ( d_data->colorBar.isEnabled &&d_data->colorBar.interval.isValid() )776 dim += d_data->colorBar.width +d_data->spacing;777 \param length width for horizontal, height for vertical scales 778 \param scaleFont Font of the scale 779 \return height for horizontal, width for vertical scales 780 */ 781 782 int QwtScaleWidget::dimForLength( int length, const QFont& scaleFont ) const 783 { 784 const int extent = qwtCeil( m_data->scaleDraw->extent( scaleFont ) ); 785 786 int dim = m_data->margin + extent + 1; 787 788 if ( !m_data->title.isEmpty() ) 789 dim += titleHeightForWidth( length ) + m_data->spacing; 790 791 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.isValid() ) 792 dim += m_data->colorBar.width + m_data->spacing; 777 793 778 794 return dim; … … 780 796 781 797 /*! 782 \brief Calculate a hint for the border distances. 783 784 This member function calculates the distance 785 of the scale's endpoints from the widget borders which 786 is required for the mark labels to fit into the widget. 787 The maximum of this distance an the minimum border distance 788 is returned. 789 790 \param start Return parameter for the border width at 798 \brief Calculate a hint for the border distances. 799 800 This member function calculates the distance 801 of the scale's endpoints from the widget borders which 802 is required for the mark labels to fit into the widget. 803 The maximum of this distance an the minimum border distance 804 is returned. 805 806 \param start Return parameter for the border width at 791 807 the beginning of the scale 792 \param end Return parameter for the border width at the 808 \param end Return parameter for the border width at the 793 809 end of the scale 794 810 795 \warning 796 <ul> <li>The minimum border distance depends on the font.</ul> 797 \sa setMinBorderDist(), getMinBorderDist(), setBorderDist() 798 */ 799 void QwtScaleWidget::getBorderDistHint( int &start, int&end ) const800 { 801 d_data->scaleDraw->getBorderDistHint( font(), start, end );802 803 if ( start < d_data->minBorderDist[0] )804 start = d_data->minBorderDist[0];805 806 if ( end < d_data->minBorderDist[1] )807 end = d_data->minBorderDist[1];808 } 809 810 /*! 811 Set a minimum value for the distances of the scale's endpoints from 812 the widget borders. This is useful to avoid that the scales 813 are "jumping", when the tick labels or their positions change 814 often. 815 816 \param start Minimum for the start border 817 \param end Minimum for the end border 818 \sa getMinBorderDist(), getBorderDistHint() 819 */ 811 \warning 812 <ul> <li>The minimum border distance depends on the font.</ul> 813 \sa setMinBorderDist(), getMinBorderDist(), setBorderDist() 814 */ 815 void QwtScaleWidget::getBorderDistHint( int& start, int& end ) const 816 { 817 m_data->scaleDraw->getBorderDistHint( font(), start, end ); 818 819 if ( start < m_data->minBorderDist[0] ) 820 start = m_data->minBorderDist[0]; 821 822 if ( end < m_data->minBorderDist[1] ) 823 end = m_data->minBorderDist[1]; 824 } 825 826 /*! 827 Set a minimum value for the distances of the scale's endpoints from 828 the widget borders. This is useful to avoid that the scales 829 are "jumping", when the tick labels or their positions change 830 often. 831 832 \param start Minimum for the start border 833 \param end Minimum for the end border 834 \sa getMinBorderDist(), getBorderDistHint() 835 */ 820 836 void QwtScaleWidget::setMinBorderDist( int start, int end ) 821 837 { 822 d_data->minBorderDist[0] = start;823 d_data->minBorderDist[1] = end;824 } 825 826 /*! 827 Get the minimum value for the distances of the scale's endpoints from 828 the widget borders. 829 830 \param start Return parameter for the border width at 838 m_data->minBorderDist[0] = start; 839 m_data->minBorderDist[1] = end; 840 } 841 842 /*! 843 Get the minimum value for the distances of the scale's endpoints from 844 the widget borders. 845 846 \param start Return parameter for the border width at 831 847 the beginning of the scale 832 \param end Return parameter for the border width at the 848 \param end Return parameter for the border width at the 833 849 end of the scale 834 850 835 \sa setMinBorderDist(), getBorderDistHint() 836 */ 837 void QwtScaleWidget::getMinBorderDist( int &start, int&end ) const838 { 839 start = d_data->minBorderDist[0];840 end = d_data->minBorderDist[1];841 } 842 843 /*! 844 \brief Assign a scale division 845 846 The scale division determines where to set the tick marks. 847 848 \param scaleDiv Scale Division 849 \sa For more information about scale divisions, see QwtScaleDiv. 850 */ 851 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv &scaleDiv )852 { 853 QwtScaleDraw *sd = d_data->scaleDraw;851 \sa setMinBorderDist(), getBorderDistHint() 852 */ 853 void QwtScaleWidget::getMinBorderDist( int& start, int& end ) const 854 { 855 start = m_data->minBorderDist[0]; 856 end = m_data->minBorderDist[1]; 857 } 858 859 /*! 860 \brief Assign a scale division 861 862 The scale division determines where to set the tick marks. 863 864 \param scaleDiv Scale Division 865 \sa For more information about scale divisions, see QwtScaleDiv. 866 */ 867 void QwtScaleWidget::setScaleDiv( const QwtScaleDiv& scaleDiv ) 868 { 869 QwtScaleDraw* sd = m_data->scaleDraw; 854 870 if ( sd->scaleDiv() != scaleDiv ) 855 871 { … … 862 878 863 879 /*! 864 Set the transformation 865 866 \param transformation Transformation 867 \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap 868 */ 869 void QwtScaleWidget::setTransformation( QwtTransform *transformation )870 { 871 d_data->scaleDraw->setTransformation( transformation );880 Set the transformation 881 882 \param transformation Transformation 883 \sa QwtAbstractScaleDraw::scaleDraw(), QwtScaleMap 884 */ 885 void QwtScaleWidget::setTransformation( QwtTransform* transformation ) 886 { 887 m_data->scaleDraw->setTransformation( transformation ); 872 888 layoutScale(); 873 889 } 874 890 875 891 /*! 876 En/disable a color bar associated to the scale 877 \sa isColorBarEnabled(), setColorBarWidth() 878 */ 892 En/disable a color bar associated to the scale 893 \sa isColorBarEnabled(), setColorBarWidth() 894 */ 879 895 void QwtScaleWidget::setColorBarEnabled( bool on ) 880 896 { 881 if ( on != d_data->colorBar.isEnabled )882 { 883 d_data->colorBar.isEnabled = on;897 if ( on != m_data->colorBar.isEnabled ) 898 { 899 m_data->colorBar.isEnabled = on; 884 900 layoutScale(); 885 901 } … … 887 903 888 904 /*! 889 \return true, when the color bar is enabled 890 \sa setColorBarEnabled(), setColorBarWidth() 891 */ 905 \return true, when the color bar is enabled 906 \sa setColorBarEnabled(), setColorBarWidth() 907 */ 892 908 bool QwtScaleWidget::isColorBarEnabled() const 893 909 { 894 return d_data->colorBar.isEnabled;895 } 896 897 /*! 898 Set the width of the color bar 899 900 \param width Width 901 \sa colorBarWidth(), setColorBarEnabled() 902 */ 910 return m_data->colorBar.isEnabled; 911 } 912 913 /*! 914 Set the width of the color bar 915 916 \param width Width 917 \sa colorBarWidth(), setColorBarEnabled() 918 */ 903 919 void QwtScaleWidget::setColorBarWidth( int width ) 904 920 { 905 if ( width != d_data->colorBar.width )906 { 907 d_data->colorBar.width = width;921 if ( width != m_data->colorBar.width ) 922 { 923 m_data->colorBar.width = width; 908 924 if ( isColorBarEnabled() ) 909 925 layoutScale(); … … 912 928 913 929 /*! 914 \return Width of the color bar 915 \sa setColorBarEnabled(), setColorBarEnabled() 916 */ 930 \return Width of the color bar 931 \sa setColorBarEnabled(), setColorBarEnabled() 932 */ 917 933 int QwtScaleWidget::colorBarWidth() const 918 934 { 919 return d_data->colorBar.width;920 } 921 922 /*! 923 \return Value interval for the color bar 924 \sa setColorMap(), colorMap() 925 */ 935 return m_data->colorBar.width; 936 } 937 938 /*! 939 \return Value interval for the color bar 940 \sa setColorMap(), colorMap() 941 */ 926 942 QwtInterval QwtScaleWidget::colorBarInterval() const 927 943 { 928 return d_data->colorBar.interval;929 } 930 931 /*! 932 Set the color map and value interval, that are used for displaying 933 the color bar. 934 935 \param interval Value interval 936 \param colorMap Color map 937 938 \sa colorMap(), colorBarInterval() 939 */ 944 return m_data->colorBar.interval; 945 } 946 947 /*! 948 Set the color map and value interval, that are used for displaying 949 the color bar. 950 951 \param interval Value interval 952 \param colorMap Color map 953 954 \sa colorMap(), colorBarInterval() 955 */ 940 956 void QwtScaleWidget::setColorMap( 941 const QwtInterval &interval, QwtColorMap*colorMap )942 { 943 d_data->colorBar.interval = interval;944 945 if ( colorMap != d_data->colorBar.colorMap )946 { 947 delete d_data->colorBar.colorMap;948 d_data->colorBar.colorMap = colorMap;957 const QwtInterval& interval, QwtColorMap* colorMap ) 958 { 959 m_data->colorBar.interval = interval; 960 961 if ( colorMap != m_data->colorBar.colorMap ) 962 { 963 delete m_data->colorBar.colorMap; 964 m_data->colorBar.colorMap = colorMap; 949 965 } 950 966 … … 954 970 955 971 /*! 956 \return Color map 957 \sa setColorMap(), colorBarInterval() 958 */ 959 const QwtColorMap *QwtScaleWidget::colorMap() const 960 { 961 return d_data->colorBar.colorMap; 962 } 972 \return Color map 973 \sa setColorMap(), colorBarInterval() 974 */ 975 const QwtColorMap* QwtScaleWidget::colorMap() const 976 { 977 return m_data->colorBar.colorMap; 978 } 979 980 #include "moc_qwt_scale_widget.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
