Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_painter.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_painter.cpp (modified) (59 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_painter.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 13 13 #include "qwt_color_map.h" 14 14 #include "qwt_scale_map.h" 15 #include <qwindowdefs.h> 15 16 16 #include <qwidget.h> 17 17 #include <qframe.h> … … 28 28 #include <qpaintengine.h> 29 29 #include <qapplication.h> 30 31 #if QT_VERSION >= 0x060000 32 #include <qscreen.h> 33 #else 30 34 #include <qdesktopwidget.h> 31 32 #if QT_VERSION >= 0x05000033 #include <qwindow.h>34 35 #endif 35 36 … … 42 43 #endif 43 44 44 bool QwtPainter::d_polylineSplitting = true; 45 bool QwtPainter::d_roundingAlignment = true; 45 #include <cstring> 46 47 bool QwtPainter::m_polylineSplitting = true; 48 bool QwtPainter::m_roundingAlignment = true; 49 50 static inline bool qwtIsRasterPaintEngineBuggy() 51 { 52 #if 0 53 static int isBuggy = -1; 54 if ( isBuggy < 0 ) 55 { 56 // auto detect bug of the raster paint engine, 57 // fixed with: https://codereview.qt-project.org/#/c/99456/ 58 59 QImage image( 2, 3, QImage::Format_ARGB32 ); 60 image.fill( 0u ); 61 62 QPolygonF p; 63 p += QPointF(0, 1); 64 p += QPointF(0, 0); 65 p += QPointF(1, 0 ); 66 p += QPointF(1, 2 ); 67 68 QPainter painter( &image ); 69 painter.drawPolyline( p ); 70 painter.end(); 71 72 isBuggy = ( image.pixel( 1, 1 ) == 0 ) ? 1 : 0; 73 } 74 75 return isBuggy == 1; 76 #endif 77 78 #if QT_VERSION < 0x050000 79 return true; 80 #elif QT_VERSION < 0x050100 81 return false; 82 #elif QT_VERSION < 0x050400 83 return true; 84 #else 85 return false; 86 #endif 87 } 46 88 47 89 static inline bool qwtIsClippingNeeded( 48 const QPainter *painter, QRectF&clipRect )90 const QPainter* painter, QRectF& clipRect ) 49 91 { 50 92 bool doClipping = false; 51 const QPaintEngine *pe = painter->paintEngine();93 const QPaintEngine* pe = painter->paintEngine(); 52 94 if ( pe && pe->type() == QPaintEngine::SVG ) 53 95 { … … 64 106 } 65 107 66 template <class T>67 static inline void qwtDrawPolyline( QPainter *painter,68 const T *points, int pointCount, bool polylineSplitting )108 template< class T > 109 static inline void qwtDrawPolyline( QPainter* painter, 110 const T* points, int pointCount, bool polylineSplitting ) 69 111 { 70 112 bool doSplit = false; 71 113 if ( polylineSplitting ) 72 114 { 73 const QPaintEngine *pe = painter->paintEngine();115 const QPaintEngine* pe = painter->paintEngine(); 74 116 if ( pe && pe->type() == QPaintEngine::Raster ) 75 117 { 76 118 /* 77 The raster paint engine seems to use some algo with O(n*n). 78 ( Qt 4.3 is better than Qt 4.2, but remains unacceptable) 79 To work around this problem, we have to split the polygon into 80 smaller pieces. 119 Raster paint engine is much faster when splitting 120 the polygon, but of course we might see some issues where 121 the pieces are joining 81 122 */ 82 123 doSplit = true; … … 86 127 if ( doSplit ) 87 128 { 129 QPen pen = painter->pen(); 130 88 131 const int splitSize = 6; 89 132 90 for ( int i = 0; i < pointCount; i += splitSize ) 91 { 92 const int n = qMin( splitSize + 1, pointCount - i ); 93 painter->drawPolyline( points + i, n ); 133 if ( pen.width() <= 1 && pen.isSolid() && qwtIsRasterPaintEngineBuggy() 134 && !( painter->renderHints() & QPainter::Antialiasing ) ) 135 { 136 int k = 0; 137 138 for ( int i = k + 1; i < pointCount; i++ ) 139 { 140 const QPointF& p1 = points[i - 1]; 141 const QPointF& p2 = points[i]; 142 143 const bool isBad = ( qAbs( p2.y() - p1.y() ) <= 1 ) 144 && qAbs( p2.x() - p1.x() ) <= 1; 145 146 if ( isBad || ( i - k >= splitSize ) ) 147 { 148 painter->drawPolyline( points + k, i - k + 1 ); 149 k = i; 150 } 151 } 152 153 painter->drawPolyline( points + k, pointCount - k ); 154 } 155 else 156 { 157 for ( int i = 0; i < pointCount; i += splitSize ) 158 { 159 const int n = qMin( splitSize + 1, pointCount - i ); 160 painter->drawPolyline( points + i, n ); 161 } 94 162 } 95 163 } … … 105 173 if ( !screenResolution.isValid() ) 106 174 { 107 QDesktopWidget *desktop = QApplication::desktop(); 175 /* 176 We might have screens with different resolutions. TODO ... 177 */ 178 #if QT_VERSION >= 0x060000 179 QScreen* screen = QGuiApplication::primaryScreen(); 180 if ( screen ) 181 { 182 screenResolution.setWidth( screen->logicalDotsPerInchX() ); 183 screenResolution.setHeight( screen->logicalDotsPerInchY() ); 184 } 185 #else 186 QDesktopWidget* desktop = QApplication::desktop(); 108 187 if ( desktop ) 109 188 { … … 111 190 screenResolution.setHeight( desktop->logicalDpiY() ); 112 191 } 192 #endif 113 193 } 114 194 … … 116 196 } 117 197 118 static inline void qwtUnscaleFont( QPainter *painter )198 static inline void qwtUnscaleFont( QPainter* painter ) 119 199 { 120 200 if ( painter->font().pixelSize() >= 0 ) … … 123 203 const QSize screenResolution = qwtScreenResolution(); 124 204 125 const QPaintDevice *pd = painter->device();205 const QPaintDevice* pd = painter->device(); 126 206 if ( pd->logicalDpiX() != screenResolution.width() || 127 207 pd->logicalDpiY() != screenResolution.height() ) 128 208 { 129 QFont pixelFont( painter->font (), QApplication::desktop() );209 QFont pixelFont = QwtPainter::scaledFont( painter->font() ); 130 210 pixelFont.setPixelSize( QFontInfo( pixelFont ).pixelSize() ); 131 211 … … 135 215 136 216 /*! 137 Check is the application is running with the X11 graphics system 138 that has some special capabilities that can be used for incremental 139 painting to a widget. 140 141 \return True, when the graphics system is X11 142 */ 217 Check is the application is running with the X11 graphics system 218 that has some special capabilities that can be used for incremental 219 painting to a widget. 220 221 \return True, when the graphics system is X11 222 */ 143 223 bool QwtPainter::isX11GraphicsSystem() 144 224 { … … 162 242 163 243 /*! 164 Check if the painter is using a paint engine, that aligns 165 coordinates to integers. Today these are all paint engines 166 beside QPaintEngine::Pdf and QPaintEngine::SVG. 167 168 If we have an integer based paint engine it is also 169 checked if the painter has a transformation matrix, 170 that rotates or scales. 171 172 \param painter Painter 173 \return true, when the painter is aligning 174 175 \sa setRoundingAlignment() 176 */ 177 bool QwtPainter::isAligning( QPainter *painter )244 Check if the painter is using a paint engine, that aligns 245 coordinates to integers. Today these are all paint engines 246 beside QPaintEngine::Pdf and QPaintEngine::SVG. 247 248 If we have an integer based paint engine it is also 249 checked if the painter has a transformation matrix, 250 that rotates or scales. 251 252 \param painter Painter 253 \return true, when the painter is aligning 254 255 \sa setRoundingAlignment() 256 */ 257 bool QwtPainter::isAligning( const QPainter* painter ) 178 258 { 179 259 if ( painter && painter->isActive() ) 180 260 { 181 switch ( painter->paintEngine()->type() ) 261 const QPaintEngine::Type type = 262 painter->paintEngine()->type(); 263 264 if ( type >= QPaintEngine::User ) 265 { 266 // we have no idea - better don't align 267 return false; 268 } 269 270 switch ( type ) 182 271 { 183 272 case QPaintEngine::Pdf: 184 273 case QPaintEngine::SVG: 274 #if 0 275 case QPaintEngine::MacPrinter: 276 #endif 185 277 return false; 186 278 187 default:; 188 } 189 190 const QTransform &tr = painter->transform(); 279 default: 280 break; 281 } 282 283 const QTransform& tr = painter->transform(); 191 284 if ( tr.isRotating() || tr.isScaling() ) 192 285 { … … 200 293 201 294 /*! 202 Enable whether coordinates should be rounded, before they are painted 203 to a paint engine that floors to integer values. For other paint engines 204 ( PDF, SVG ) this flag has no effect. 205 QwtPainter stores this flag only, the rounding itself is done in 206 the painting code ( f.e the plot items ). 207 208 The default setting is true. 209 210 \sa roundingAlignment(), isAligning() 211 */ 295 Enable whether coordinates should be rounded, before they are painted 296 to a paint engine that floors to integer values. For other paint engines 297 ( PDF, SVG ) this flag has no effect. 298 QwtPainter stores this flag only, the rounding itself is done in 299 the painting code ( f.e the plot items ). 300 301 The default setting is true. 302 303 \sa roundingAlignment(), isAligning() 304 */ 212 305 void QwtPainter::setRoundingAlignment( bool enable ) 213 306 { 214 d_roundingAlignment = enable;215 } 216 217 /*! 218 \brief En/Disable line splitting for the raster paint engine 219 220 In some Qt versions the raster paint engine paints polylines of many points 221 much faster when they are split in smaller chunks: f.e all supported Qt versions 222 >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2. 223 224 Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... ) 225 for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked 226 around in this mode. 227 228 The default setting is true. 229 230 \sa polylineSplitting() 231 */ 307 m_roundingAlignment = enable; 308 } 309 310 /*! 311 \brief En/Disable line splitting for the raster paint engine 312 313 In some Qt versions the raster paint engine paints polylines of many points 314 much faster when they are split in smaller chunks: f.e all supported Qt versions 315 >= Qt 5.0 when drawing an antialiased polyline with a pen width >=2. 316 317 Also the raster paint engine has a nasty bug in many versions ( Qt 4.8 - ... ) 318 for short lines ( https://codereview.qt-project.org/#/c/99456 ), that is worked 319 around in this mode. 320 321 The default setting is true. 322 323 \sa polylineSplitting() 324 */ 232 325 void QwtPainter::setPolylineSplitting( bool enable ) 233 326 { 234 d_polylineSplitting = enable;327 m_polylineSplitting = enable; 235 328 } 236 329 237 330 //! Wrapper for QPainter::drawPath() 238 void QwtPainter::drawPath( QPainter *painter, const QPainterPath&path )331 void QwtPainter::drawPath( QPainter* painter, const QPainterPath& path ) 239 332 { 240 333 painter->drawPath( path ); … … 242 335 243 336 //! Wrapper for QPainter::drawRect() 244 void QwtPainter::drawRect( QPainter *painter,double x, double y, double w, doubleh )337 void QwtPainter::drawRect( QPainter* painter, qreal x, qreal y, qreal w, qreal h ) 245 338 { 246 339 drawRect( painter, QRectF( x, y, w, h ) ); … … 248 341 249 342 //! Wrapper for QPainter::drawRect() 250 void QwtPainter::drawRect( QPainter *painter, const QRectF&rect )343 void QwtPainter::drawRect( QPainter* painter, const QRectF& rect ) 251 344 { 252 345 const QRectF r = rect; … … 277 370 278 371 //! Wrapper for QPainter::fillRect() 279 void QwtPainter::fillRect( QPainter *painter,280 const QRectF &rect, const QBrush&brush )372 void QwtPainter::fillRect( QPainter* painter, 373 const QRectF& rect, const QBrush& brush ) 281 374 { 282 375 if ( !rect.isValid() ) … … 287 380 288 381 /* 289 Performance of Qt4 is horrible for a non trivial brush. Without 290 clipping expect minutes or hours for repainting large rectangles 291 (might result from zooming) 292 */ 382 Performance of Qt4 is horrible for a non trivial brush. Without 383 clipping expect minutes or hours for repainting large rectangles 384 (might result from zooming) 385 */ 293 386 294 387 if ( deviceClipping ) … … 309 402 310 403 //! Wrapper for QPainter::drawPie() 311 void QwtPainter::drawPie( QPainter *painter, const QRectF&rect,404 void QwtPainter::drawPie( QPainter* painter, const QRectF& rect, 312 405 int a, int alen ) 313 406 { … … 321 414 322 415 //! Wrapper for QPainter::drawEllipse() 323 void QwtPainter::drawEllipse( QPainter *painter, const QRectF&rect )416 void QwtPainter::drawEllipse( QPainter* painter, const QRectF& rect ) 324 417 { 325 418 QRectF clipRect; … … 333 426 334 427 //! Wrapper for QPainter::drawText() 335 void QwtPainter::drawText( QPainter *painter, double x, double y,336 const QString&text )428 void QwtPainter::drawText( QPainter* painter, 429 qreal x, qreal y, const QString& text ) 337 430 { 338 431 drawText( painter, QPointF( x, y ), text ); … … 340 433 341 434 //! Wrapper for QPainter::drawText() 342 void QwtPainter::drawText( QPainter *painter, const QPointF&pos,343 const QString&text )435 void QwtPainter::drawText( QPainter* painter, const QPointF& pos, 436 const QString& text ) 344 437 { 345 438 QRectF clipRect; … … 357 450 358 451 //! Wrapper for QPainter::drawText() 359 void QwtPainter::drawText( QPainter *painter,360 double x, double y, double w, doubleh,361 int flags, const QString &text )452 void QwtPainter::drawText( QPainter* painter, 453 qreal x, qreal y, qreal w, qreal h, 454 int flags, const QString& text ) 362 455 { 363 456 drawText( painter, QRectF( x, y, w, h ), flags, text ); … … 365 458 366 459 //! Wrapper for QPainter::drawText() 367 void QwtPainter::drawText( QPainter *painter, const QRectF&rect,368 int flags, const QString&text )460 void QwtPainter::drawText( QPainter* painter, const QRectF& rect, 461 int flags, const QString& text ) 369 462 { 370 463 painter->save(); … … 377 470 378 471 /*! 379 Draw a text document into a rectangle 380 381 \param painter Painter 382 \param rect T raget rectangle383 \param flags Alignments/Text flags, see QPainter::drawText() 384 \param text Text document 385 */ 386 void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF&rect,387 int flags, const QTextDocument &text )388 { 389 QTextDocument *txt = text.clone();472 Draw a text document into a rectangle 473 474 \param painter Painter 475 \param rect Target rectangle 476 \param flags Alignments/Text flags, see QPainter::drawText() 477 \param text Text document 478 */ 479 void QwtPainter::drawSimpleRichText( QPainter* painter, const QRectF& rect, 480 int flags, const QTextDocument& text ) 481 { 482 QTextDocument* txt = text.clone(); 390 483 391 484 painter->save(); … … 397 490 const QSize res = qwtScreenResolution(); 398 491 399 const QPaintDevice *pd = painter->device();492 const QPaintDevice* pd = painter->device(); 400 493 if ( pd->logicalDpiX() != res.width() || 401 494 pd->logicalDpiY() != res.height() ) 402 495 { 403 496 QTransform transform; 404 transform.scale( res.width() / double( pd->logicalDpiX() ),405 res.height() / double( pd->logicalDpiY() ));497 transform.scale( res.width() / qreal( pd->logicalDpiX() ), 498 res.height() / qreal( pd->logicalDpiY() ) ); 406 499 407 500 painter->setWorldTransform( transform, true ); … … 415 508 QAbstractTextDocumentLayout* layout = txt->documentLayout(); 416 509 417 const doubleheight = layout->documentSize().height();418 doubley = unscaledRect.y();510 const qreal height = layout->documentSize().height(); 511 qreal y = unscaledRect.y(); 419 512 if ( flags & Qt::AlignBottom ) 420 513 y += ( unscaledRect.height() - height ); … … 436 529 437 530 //! Wrapper for QPainter::drawLine() 438 void QwtPainter::drawLine( QPainter *painter,439 const QPointF &p1, const QPointF&p2 )531 void QwtPainter::drawLine( QPainter* painter, 532 const QPointF& p1, const QPointF& p2 ) 440 533 { 441 534 QRectF clipRect; … … 456 549 457 550 //! Wrapper for QPainter::drawPolygon() 458 void QwtPainter::drawPolygon( QPainter *painter, const QPolygonF&polygon )551 void QwtPainter::drawPolygon( QPainter* painter, const QPolygonF& polygon ) 459 552 { 460 553 QRectF clipRect; 461 554 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 462 555 463 QPolygonF cpa = polygon;464 556 if ( deviceClipping ) 465 cpa = QwtClipper::clipPolygonF( clipRect, polygon, true ); 466 467 painter->drawPolygon( cpa ); 557 { 558 painter->drawPolygon( 559 QwtClipper::clippedPolygonF( clipRect, polygon, true ) ); 560 } 561 else 562 { 563 painter->drawPolygon( polygon ); 564 } 468 565 } 469 566 470 567 //! Wrapper for QPainter::drawPolyline() 471 void QwtPainter::drawPolyline( QPainter *painter, const QPolygonF&polygon )568 void QwtPainter::drawPolyline( QPainter* painter, const QPolygonF& polygon ) 472 569 { 473 570 QRectF clipRect; 474 571 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 475 572 476 QPolygonF cpa = polygon;477 573 if ( deviceClipping ) 478 cpa = QwtClipper::clipPolygonF( clipRect, cpa ); 479 480 qwtDrawPolyline<QPointF>( painter, 481 cpa.constData(), cpa.size(), d_polylineSplitting ); 574 { 575 const QPolygonF cpa = QwtClipper::clippedPolygonF( clipRect, polygon ); 576 577 qwtDrawPolyline< QPointF >( painter, 578 cpa.constData(), cpa.size(), m_polylineSplitting ); 579 } 580 else 581 { 582 qwtDrawPolyline< QPointF >( painter, 583 polygon.constData(), polygon.size(), m_polylineSplitting ); 584 } 482 585 } 483 586 484 587 //! Wrapper for QPainter::drawPolyline() 485 void QwtPainter::drawPolyline( QPainter *painter,486 const QPointF *points, int pointCount )588 void QwtPainter::drawPolyline( QPainter* painter, 589 const QPointF* points, int pointCount ) 487 590 { 488 591 QRectF clipRect; … … 492 595 { 493 596 QPolygonF polygon( pointCount ); 494 ::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) ); 495 496 polygon =QwtClipper::clipPolygonF( clipRect, polygon );497 qwtDrawPolyline< QPointF>( painter,498 polygon.constData(), polygon.size(), d_polylineSplitting );597 std::memcpy( polygon.data(), points, pointCount * sizeof( QPointF ) ); 598 599 QwtClipper::clipPolygonF( clipRect, polygon ); 600 qwtDrawPolyline< QPointF >( painter, 601 polygon.constData(), polygon.size(), m_polylineSplitting ); 499 602 } 500 603 else 501 604 { 502 qwtDrawPolyline< QPointF>( painter, points, pointCount,d_polylineSplitting );605 qwtDrawPolyline< QPointF >( painter, points, pointCount, m_polylineSplitting ); 503 606 } 504 607 } 505 608 506 609 //! Wrapper for QPainter::drawPolygon() 507 void QwtPainter::drawPolygon( QPainter *painter, const QPolygon&polygon )610 void QwtPainter::drawPolygon( QPainter* painter, const QPolygon& polygon ) 508 611 { 509 612 QRectF clipRect; 510 613 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 511 614 512 QPolygon cpa = polygon;513 615 if ( deviceClipping ) 514 cpa = QwtClipper::clipPolygon( clipRect, polygon, true ); 515 516 painter->drawPolygon( cpa ); 616 { 617 painter->drawPolygon( 618 QwtClipper::clippedPolygon( clipRect, polygon, true ) ); 619 } 620 else 621 { 622 painter->drawPolygon( polygon ); 623 } 517 624 } 518 625 519 626 //! Wrapper for QPainter::drawPolyline() 520 void QwtPainter::drawPolyline( QPainter *painter, const QPolygon&polygon )627 void QwtPainter::drawPolyline( QPainter* painter, const QPolygon& polygon ) 521 628 { 522 629 QRectF clipRect; 523 630 const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect ); 524 631 525 QPolygon cpa = polygon;526 632 if ( deviceClipping ) 527 cpa = QwtClipper::clipPolygon( clipRect, cpa ); 528 529 qwtDrawPolyline<QPoint>( painter, 530 cpa.constData(), cpa.size(), d_polylineSplitting ); 633 { 634 const QPolygon cpa = QwtClipper::clippedPolygon( clipRect, polygon ); 635 636 qwtDrawPolyline< QPoint >( painter, 637 cpa.constData(), cpa.size(), m_polylineSplitting ); 638 } 639 else 640 { 641 qwtDrawPolyline< QPoint >( painter, 642 polygon.constData(), polygon.size(), m_polylineSplitting ); 643 } 531 644 } 532 645 533 646 //! Wrapper for QPainter::drawPolyline() 534 void QwtPainter::drawPolyline( QPainter *painter,535 const QPoint *points, int pointCount )647 void QwtPainter::drawPolyline( QPainter* painter, 648 const QPoint* points, int pointCount ) 536 649 { 537 650 QRectF clipRect; … … 541 654 { 542 655 QPolygon polygon( pointCount ); 543 ::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); 544 545 polygon =QwtClipper::clipPolygon( clipRect, polygon );546 qwtDrawPolyline< QPoint>( painter,547 polygon.constData(), polygon.size(), d_polylineSplitting );656 std::memcpy( polygon.data(), points, pointCount * sizeof( QPoint ) ); 657 658 QwtClipper::clipPolygon( clipRect, polygon ); 659 qwtDrawPolyline< QPoint >( painter, 660 polygon.constData(), polygon.size(), m_polylineSplitting ); 548 661 } 549 662 else 550 663 { 551 qwtDrawPolyline< QPoint>( painter, points, pointCount,d_polylineSplitting );664 qwtDrawPolyline< QPoint >( painter, points, pointCount, m_polylineSplitting ); 552 665 } 553 666 } 554 667 555 668 //! Wrapper for QPainter::drawPoint() 556 void QwtPainter::drawPoint( QPainter *painter, const QPointF&pos )669 void QwtPainter::drawPoint( QPainter* painter, const QPointF& pos ) 557 670 { 558 671 QRectF clipRect; … … 566 679 567 680 //! Wrapper for QPainter::drawPoint() 568 void QwtPainter::drawPoint( QPainter *painter, const QPoint&pos )681 void QwtPainter::drawPoint( QPainter* painter, const QPoint& pos ) 569 682 { 570 683 QRectF clipRect; … … 573 686 if ( deviceClipping ) 574 687 { 575 const int minX = qCeil( clipRect.left() ); 576 const int maxX = qFloor( clipRect.right() ); 577 const int minY = qCeil( clipRect.top() ); 578 const int maxY = qFloor( clipRect.bottom() ); 688 const int minX = qwtCeil( clipRect.left() ); 689 const int maxX = qwtFloor( clipRect.right() ); 690 const int minY = qwtCeil( clipRect.top() ); 691 const int maxY = qwtFloor( clipRect.bottom() ); 579 692 580 693 if ( pos.x() < minX || pos.x() > maxX … … 589 702 590 703 //! Wrapper for QPainter::drawPoints() 591 void QwtPainter::drawPoints( QPainter *painter,592 const QPoint *points, int pointCount )704 void QwtPainter::drawPoints( QPainter* painter, 705 const QPoint* points, int pointCount ) 593 706 { 594 707 QRectF clipRect; … … 597 710 if ( deviceClipping ) 598 711 { 599 const int minX = qCeil( clipRect.left() ); 600 const int maxX = qFloor( clipRect.right() ); 601 const int minY = qCeil( clipRect.top() ); 602 const int maxY = qFloor( clipRect.bottom() ); 712 const int minX = qwtCeil( clipRect.left() ); 713 const int maxX = qwtFloor( clipRect.right() ); 714 const int minY = qwtCeil( clipRect.top() ); 715 const int maxY = qwtFloor( clipRect.bottom() ); 603 716 604 717 const QRect r( minX, minY, maxX - minX, maxY - minY ); 605 718 606 719 QPolygon clippedPolygon( pointCount ); 607 QPoint *clippedData = clippedPolygon.data();720 QPoint* clippedData = clippedPolygon.data(); 608 721 609 722 int numClippedPoints = 0; … … 622 735 623 736 //! Wrapper for QPainter::drawPoints() 624 void QwtPainter::drawPoints( QPainter *painter,625 const QPointF *points, int pointCount )737 void QwtPainter::drawPoints( QPainter* painter, 738 const QPointF* points, int pointCount ) 626 739 { 627 740 QRectF clipRect; … … 631 744 { 632 745 QPolygonF clippedPolygon( pointCount ); 633 QPointF *clippedData = clippedPolygon.data();746 QPointF* clippedData = clippedPolygon.data(); 634 747 635 748 int numClippedPoints = 0; … … 648 761 649 762 //! Wrapper for QPainter::drawImage() 650 void QwtPainter::drawImage( QPainter *painter,651 const QRectF &rect, const QImage&image )763 void QwtPainter::drawImage( QPainter* painter, 764 const QRectF& rect, const QImage& image ) 652 765 { 653 766 const QRect alignedRect = rect.toAlignedRect(); … … 669 782 670 783 //! Wrapper for QPainter::drawPixmap() 671 void QwtPainter::drawPixmap( QPainter *painter,672 const QRectF &rect, const QPixmap&pixmap )784 void QwtPainter::drawPixmap( QPainter* painter, 785 const QRectF& rect, const QPixmap& pixmap ) 673 786 { 674 787 const QRect alignedRect = rect.toAlignedRect(); … … 690 803 691 804 //! Draw a focus rectangle on a widget using its style. 692 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget*widget )805 void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget ) 693 806 { 694 807 drawFocusRect( painter, widget, widget->rect() ); … … 696 809 697 810 //! Draw a focus rectangle on a widget using its style. 698 void QwtPainter::drawFocusRect( QPainter *painter, const QWidget*widget,699 const QRect &rect )811 void QwtPainter::drawFocusRect( QPainter* painter, const QWidget* widget, 812 const QRect& rect ) 700 813 { 701 814 QStyleOptionFocusRect opt; 702 opt.init( widget ); 815 opt.initFrom( widget ); 703 816 opt.rect = rect; 704 817 opt.state |= QStyle::State_HasFocus; … … 710 823 711 824 /*! 712 Draw a round frame 713 714 \param painter Painter 715 \param rect Frame rectangle 716 \param palette QPalette::WindowText is used for plain borders 825 Draw a round frame 826 827 \param painter Painter 828 \param rect Frame rectangle 829 \param palette QPalette::WindowText is used for plain borders 717 830 QPalette::Dark and QPalette::Light for raised 718 831 or sunken borders 719 \param lineWidth Line width 720 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 721 */ 722 void QwtPainter::drawRoundFrame( QPainter *painter,723 const QRectF &rect, const QPalette&palette,832 \param lineWidth Line width 833 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 834 */ 835 void QwtPainter::drawRoundFrame( QPainter* painter, 836 const QRectF& rect, const QPalette& palette, 724 837 int lineWidth, int frameStyle ) 725 838 { … … 732 845 733 846 Style style = Plain; 734 if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )847 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken ) 735 848 style = Sunken; 736 else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )849 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised ) 737 850 style = Raised; 738 851 739 const doublelw2 = 0.5 * lineWidth;852 const qreal lw2 = 0.5 * lineWidth; 740 853 QRectF r = rect.adjusted( lw2, lw2, -lw2, -lw2 ); 741 854 … … 776 889 777 890 /*! 778 Draw a rectangular frame 779 780 \param painter Painter 781 \param rect Frame rectangle 782 \param palette Palette 783 \param foregroundRole Foreground role used for QFrame::Plain 784 \param frameWidth Frame width 785 \param midLineWidth Used for QFrame::Box 786 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 787 */ 788 void QwtPainter::drawFrame( QPainter *painter, const QRectF&rect,789 const QPalette &palette, QPalette::ColorRole foregroundRole,891 Draw a rectangular frame 892 893 \param painter Painter 894 \param rect Frame rectangle 895 \param palette Palette 896 \param foregroundRole Foreground role used for QFrame::Plain 897 \param frameWidth Frame width 898 \param midLineWidth Used for QFrame::Box 899 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 900 */ 901 void QwtPainter::drawFrame( QPainter* painter, const QRectF& rect, 902 const QPalette& palette, QPalette::ColorRole foregroundRole, 790 903 int frameWidth, int midLineWidth, int frameStyle ) 791 904 { … … 882 995 painter->drawPath( path5 ); 883 996 } 884 #if 0885 // qDrawWinPanel doesn't result in something nice886 // on a scalable document like PDF. Better draw a887 // Panel.888 889 else if ( shape == QFrame::WinPanel )890 {891 painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true );892 qDrawWinPanel ( painter, rect.toRect(), palette,893 frameStyle & QFrame::Sunken );894 }895 else if ( shape == QFrame::StyledPanel )896 {897 }898 #endif899 997 else 900 998 { … … 942 1040 943 1041 /*! 944 Draw a rectangular frame with rounded borders 945 946 \param painter Painter 947 \param rect Frame rectangle 948 \param xRadius x-radius of the ellipses defining the corners 949 \param yRadius y-radius of the ellipses defining the corners 950 \param palette QPalette::WindowText is used for plain borders 1042 Draw a rectangular frame with rounded borders 1043 1044 \param painter Painter 1045 \param rect Frame rectangle 1046 \param xRadius x-radius of the ellipses defining the corners 1047 \param yRadius y-radius of the ellipses defining the corners 1048 \param palette QPalette::WindowText is used for plain borders 951 1049 QPalette::Dark and QPalette::Light for raised 952 1050 or sunken borders 953 \param lineWidth Line width 954 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 955 */ 956 957 void QwtPainter::drawRoundedFrame( QPainter *painter,958 const QRectF &rect, doublexRadius,doubleyRadius,959 const QPalette &palette, int lineWidth, int frameStyle )1051 \param lineWidth Line width 1052 \param frameStyle bitwise OR´ed value of QFrame::Shape and QFrame::Shadow 1053 */ 1054 1055 void QwtPainter::drawRoundedFrame( QPainter* painter, 1056 const QRectF& rect, qreal xRadius, qreal yRadius, 1057 const QPalette& palette, int lineWidth, int frameStyle ) 960 1058 { 961 1059 painter->save(); … … 963 1061 painter->setBrush( Qt::NoBrush ); 964 1062 965 doublelw2 = lineWidth * 0.5;1063 qreal lw2 = lineWidth * 0.5; 966 1064 QRectF innerRect = rect.adjusted( lw2, lw2, -lw2, -lw2 ); 967 1065 … … 977 1075 978 1076 Style style = Plain; 979 if ( (frameStyle & QFrame::Sunken) == QFrame::Sunken )1077 if ( (frameStyle& QFrame::Sunken) == QFrame::Sunken ) 980 1078 style = Sunken; 981 else if ( (frameStyle & QFrame::Raised) == QFrame::Raised )1079 else if ( (frameStyle& QFrame::Raised) == QFrame::Raised ) 982 1080 style = Raised; 983 1081 … … 993 1091 pathList[ 2 * i ].moveTo( 994 1092 path.elementAt(j - 1).x, path.elementAt( j - 1 ).y 995 ); 1093 ); 996 1094 997 1095 pathList[ 2 * i ].cubicTo( … … 1002 1100 pathList[ 2 * i + 1 ].moveTo( 1003 1101 path.elementAt(j + 2).x, path.elementAt(j + 2).y 1004 ); 1102 ); 1005 1103 pathList[ 2 * i + 1 ].lineTo( 1006 1104 path.elementAt(j + 3).x, path.elementAt(j + 3).y 1007 ); 1105 ); 1008 1106 } 1009 1107 … … 1086 1184 1087 1185 /*! 1088 Draw a color bar into a rectangle 1089 1090 \param painter Painter 1091 \param colorMap Color map 1092 \param interval Value range 1093 \param scaleMap Scale map 1094 \param orientation Orientation 1095 \param rect T raget rectangle1096 */ 1097 void QwtPainter::drawColorBar( QPainter *painter,1098 const QwtColorMap&colorMap, const QwtInterval&interval,1099 const QwtScaleMap&scaleMap, Qt::Orientation orientation,1100 const QRectF&rect )1101 { 1102 QVector< QRgb> colorTable;1186 Draw a color bar into a rectangle 1187 1188 \param painter Painter 1189 \param colorMap Color map 1190 \param interval Value range 1191 \param scaleMap Scale map 1192 \param orientation Orientation 1193 \param rect Target rectangle 1194 */ 1195 void QwtPainter::drawColorBar( QPainter* painter, 1196 const QwtColorMap& colorMap, const QwtInterval& interval, 1197 const QwtScaleMap& scaleMap, Qt::Orientation orientation, 1198 const QRectF& rect ) 1199 { 1200 QVector< QRgb > colorTable; 1103 1201 if ( colorMap.format() == QwtColorMap::Indexed ) 1104 colorTable = colorMap.colorTable ( interval);1202 colorTable = colorMap.colorTable256(); 1105 1203 1106 1204 QColor c; … … 1109 1207 1110 1208 /* 1111 We paint to a pixmap first to have something scalable for printing 1112 ( f.e. in a Pdf document ) 1209 We paint to a pixmap first to have something scalable for printing 1210 ( f.e. in a Pdf document ) 1113 1211 */ 1114 1212 … … 1131 1229 c.setRgba( colorMap.rgb( interval, value ) ); 1132 1230 else 1133 c = colorTable[colorMap.colorIndex( interval, value )]; 1231 c = colorTable[colorMap.colorIndex( 256, interval, value )]; 1134 1232 1135 1233 pmPainter.setPen( c ); … … 1149 1247 c.setRgba( colorMap.rgb( interval, value ) ); 1150 1248 else 1151 c = colorTable[colorMap.colorIndex( interval, value )]; 1249 c = colorTable[colorMap.colorIndex( 256, interval, value )]; 1152 1250 1153 1251 pmPainter.setPen( c ); … … 1160 1258 } 1161 1259 1162 static inline void qwtFillRect( const QWidget *widget, QPainter*painter,1163 const QRect &rect, const QBrush&brush)1260 static inline void qwtFillRect( const QWidget* widget, QPainter* painter, 1261 const QRect& rect, const QBrush& brush) 1164 1262 { 1165 1263 if ( brush.style() == Qt::TexturePattern ) … … 1168 1266 1169 1267 painter->setClipRect( rect ); 1170 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); 1268 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft() ); 1171 1269 1172 1270 painter->restore(); … … 1189 1287 1190 1288 /*! 1191 Fill a pixmap with the content of a widget 1192 1193 In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy 1194 for backgrounds with gradients. Thus fillPixmap() offers 1195 an alternative implementation. 1196 1197 \param widget Widget 1198 \param pixmap Pixmap to be filled 1199 \param offset Offset 1200 1201 \sa QPixmap::fill() 1202 */ 1203 void QwtPainter::fillPixmap( const QWidget *widget,1204 QPixmap &pixmap, const QPoint&offset )1289 Fill a pixmap with the content of a widget 1290 1291 In Qt >= 5.0 QPixmap::fill() is a nop, in Qt 4.x it is buggy 1292 for backgrounds with gradients. Thus fillPixmap() offers 1293 an alternative implementation. 1294 1295 \param widget Widget 1296 \param pixmap Pixmap to be filled 1297 \param offset Offset 1298 1299 \sa QPixmap::fill() 1300 */ 1301 void QwtPainter::fillPixmap( const QWidget* widget, 1302 QPixmap& pixmap, const QPoint& offset ) 1205 1303 { 1206 1304 const QRect rect( offset, pixmap.size() ); … … 1233 1331 1234 1332 /*! 1235 Fill rect with the background of a widget 1236 1237 \param painter Painter 1238 \param rect Rectangle to be filled 1239 \param widget Widget 1240 1241 \sa QStyle::PE_Widget, QWidget::backgroundRole() 1242 */ 1243 void QwtPainter::drawBackgound( QPainter *painter,1244 const QRectF &rect, const QWidget*widget )1333 Fill rect with the background of a widget 1334 1335 \param painter Painter 1336 \param rect Rectangle to be filled 1337 \param widget Widget 1338 1339 \sa QStyle::PE_Widget, QWidget::backgroundRole() 1340 */ 1341 void QwtPainter::drawBackgound( QPainter* painter, 1342 const QRectF& rect, const QWidget* widget ) 1245 1343 { 1246 1344 if ( widget->testAttribute( Qt::WA_StyledBackground ) ) … … 1263 1361 1264 1362 /*! 1265 \return A pixmap that can be used as backing store 1266 1267 \param widget Widget, for which the backingstore is intended 1268 \param size Size of the pixmap 1269 */ 1270 QPixmap QwtPainter::backingStore( QWidget *widget, const QSize &size ) 1363 Distance appropriate for drawing a subsequent character after text. 1364 1365 \param fontMetrics Font metrics 1366 \param text Text 1367 \return horizontal advance in pixels 1368 */ 1369 int QwtPainter::horizontalAdvance( 1370 const QFontMetrics& fontMetrics, const QString& text ) 1371 { 1372 #if QT_VERSION >= 0x050b00 1373 return fontMetrics.horizontalAdvance( text ); 1374 #else 1375 return fontMetrics.width( text ); 1376 #endif 1377 1378 } 1379 1380 /*! 1381 Distance appropriate for drawing a subsequent character after text. 1382 1383 \param fontMetrics Font metrics 1384 \param text Text 1385 \return horizontal advance in pixels 1386 */ 1387 qreal QwtPainter::horizontalAdvance( 1388 const QFontMetricsF& fontMetrics, const QString& text ) 1389 { 1390 #if QT_VERSION >= 0x050b00 1391 return fontMetrics.horizontalAdvance( text ); 1392 #else 1393 return fontMetrics.width( text ); 1394 #endif 1395 } 1396 1397 /*! 1398 Distance appropriate for drawing a subsequent character after ch. 1399 1400 \param fontMetrics Font metrics 1401 \param ch Character 1402 \return horizontal advance in pixels 1403 */ 1404 int QwtPainter::horizontalAdvance( 1405 const QFontMetrics& fontMetrics, QChar ch ) 1406 { 1407 #if QT_VERSION >= 0x050b00 1408 return fontMetrics.horizontalAdvance( ch ); 1409 #else 1410 return fontMetrics.width( ch ); 1411 #endif 1412 } 1413 1414 /*! 1415 Distance appropriate for drawing a subsequent character after ch. 1416 1417 \param fontMetrics Font metrics 1418 \param ch Character 1419 \return horizontal advance in pixels 1420 */ 1421 qreal QwtPainter::horizontalAdvance( 1422 const QFontMetricsF& fontMetrics, QChar ch ) 1423 { 1424 #if QT_VERSION >= 0x050b00 1425 return fontMetrics.horizontalAdvance( ch ); 1426 #else 1427 return fontMetrics.width( ch ); 1428 #endif 1429 } 1430 1431 /*! 1432 Adjust the DPI value of font according to the DPI value of the paint device 1433 1434 \param font Unscaled font 1435 \param paintDevice Paint device providing a DPI value. If paintDevice == null 1436 the DPI value of the primary screen will be used 1437 1438 \return Font being adjusted to the DPI value of the paint device 1439 */ 1440 QFont QwtPainter::scaledFont( const QFont& font, const QPaintDevice* paintDevice ) 1441 { 1442 if ( paintDevice == NULL ) 1443 { 1444 #if QT_VERSION < 0x060000 1445 paintDevice = QApplication::desktop(); 1446 #else 1447 class PaintDevice : public QPaintDevice 1448 { 1449 virtual QPaintEngine* paintEngine() const QWT_OVERRIDE 1450 { 1451 return NULL; 1452 } 1453 1454 virtual int metric( PaintDeviceMetric metric ) const QWT_OVERRIDE 1455 { 1456 if ( metric == PdmDpiY ) 1457 { 1458 QScreen* screen = QGuiApplication::primaryScreen(); 1459 if ( screen ) 1460 { 1461 return screen->logicalDotsPerInchY(); 1462 } 1463 } 1464 1465 return QPaintDevice::metric( metric ); 1466 } 1467 }; 1468 1469 static PaintDevice dummyPaintDevice; 1470 paintDevice = &dummyPaintDevice; 1471 #endif 1472 } 1473 1474 return QFont( font, const_cast< QPaintDevice* >( paintDevice ) ); 1475 } 1476 1477 /*! 1478 \return Pixel ratio for a paint device 1479 \param paintDevice Paint device 1480 */ 1481 qreal QwtPainter::devicePixelRatio( const QPaintDevice* paintDevice ) 1482 { 1483 qreal pixelRatio = 0.0; 1484 1485 #if QT_VERSION >= 0x050100 1486 if ( paintDevice ) 1487 { 1488 #if QT_VERSION >= 0x050600 1489 pixelRatio = paintDevice->devicePixelRatioF(); 1490 #else 1491 pixelRatio = paintDevice->devicePixelRatio(); 1492 #endif 1493 } 1494 #else 1495 Q_UNUSED( paintDevice ) 1496 #endif 1497 1498 #if QT_VERSION >= 0x050000 1499 if ( pixelRatio == 0.0 && qApp ) 1500 pixelRatio = qApp->devicePixelRatio(); 1501 #endif 1502 1503 if ( pixelRatio == 0.0 ) 1504 pixelRatio = 1.0; 1505 1506 return pixelRatio; 1507 } 1508 1509 /*! 1510 \return A pixmap that can be used as backing store 1511 1512 \param widget Widget, for which the backingstore is intended 1513 \param size Size of the pixmap 1514 */ 1515 QPixmap QwtPainter::backingStore( QWidget* widget, const QSize& size ) 1271 1516 { 1272 1517 QPixmap pm; 1273 1518 1274 #define QWT_HIGH_DPI 1 1275 1276 #if QT_VERSION >= 0x050000 && QWT_HIGH_DPI 1277 qreal pixelRatio = 1.0; 1278 1279 if ( widget && widget->windowHandle() ) 1280 { 1281 #if QT_VERSION < 0x050100 1282 pixelRatio = widget->windowHandle()->devicePixelRatio(); 1283 #else 1284 pixelRatio = widget->devicePixelRatio(); 1285 #endif 1286 } 1287 else 1288 { 1289 if ( qApp ) 1290 pixelRatio = qApp->devicePixelRatio(); 1291 } 1519 #if QT_VERSION >= 0x050000 1520 const qreal pixelRatio = QwtPainter::devicePixelRatio( widget ); 1292 1521 1293 1522 pm = QPixmap( size * pixelRatio ); 1294 1523 pm.setDevicePixelRatio( pixelRatio ); 1295 1524 #else 1296 Q_UNUSED( widget )1297 1525 pm = QPixmap( size ); 1298 1526 #endif 1299 1527 1300 #if QT_VERSION < 0x0500001301 1528 #ifdef Q_WS_X11 1302 1529 if ( widget && isX11GraphicsSystem() ) … … 1305 1532 pm.x11SetScreen( widget->x11Info().screen() ); 1306 1533 } 1307 #endif 1534 #else 1535 Q_UNUSED( widget ) 1308 1536 #endif 1309 1537 1310 1538 return pm; 1311 1539 } 1312
Note:
See TracChangeset
for help on using the changeset viewer.
