Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_canvas.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_canvas.cpp
r4271 r8127 18 18 #include <qpaintengine.h> 19 19 #include <qevent.h> 20 #include <qbitmap.h>21 #ifdef Q_WS_X1122 #include <qx11info_x11.h>23 #endif24 20 25 21 class QwtStyleSheetRecorder: public QwtNullPaintDevice … … 27 23 public: 28 24 QwtStyleSheetRecorder( const QSize &size ): 29 QwtNullPaintDevice( QPaintEngine::AllFeatures ) 30 { 31 setSize( size ); 25 d_size( size ) 26 { 32 27 } 33 28 … … 56 51 virtual void drawPath( const QPainterPath &path ) 57 52 { 58 const QRectF rect( QPointF( 0.0, 0.0 ) , size());53 const QRectF rect( QPointF( 0.0, 0.0 ), d_size ); 59 54 if ( path.controlPointRect().contains( rect.center() ) ) 60 55 { … … 117 112 } 118 113 114 protected: 115 virtual QSize sizeMetrics() const 116 { 117 return d_size; 118 } 119 119 120 private: 120 121 void alignCornerRects( const QRectF &rect ) … … 154 155 155 156 private: 157 const QSize d_size; 158 156 159 QPen d_pen; 157 160 QBrush d_brush; … … 159 162 }; 160 163 161 static void qwtDrawBackground( QPainter *painter, QWidget *widget ) 162 { 164 static void qwtDrawBackground( QPainter *painter, QwtPlotCanvas *canvas ) 165 { 166 painter->save(); 167 168 const QPainterPath borderClip = canvas->borderPath( canvas->rect() ); 169 if ( !borderClip.isEmpty() ) 170 painter->setClipPath( borderClip, Qt::IntersectClip ); 171 163 172 const QBrush &brush = 164 widget->palette().brush( widget->backgroundRole() );173 canvas->palette().brush( canvas->backgroundRole() ); 165 174 166 175 if ( brush.style() == Qt::TexturePattern ) 167 176 { 168 QPixmap pm( widget->size() );169 pm.fill( widget, 0, 0);177 QPixmap pm( canvas->size() ); 178 QwtPainter::fillPixmap( canvas, pm ); 170 179 painter->drawPixmap( 0, 0, pm ); 171 180 } … … 176 185 if ( brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode ) 177 186 { 178 rects += widget->rect();187 rects += canvas->rect(); 179 188 } 180 189 else … … 215 224 } 216 225 217 QImage image( widget->size(), format );226 QImage image( canvas->size(), format ); 218 227 219 228 QPainter p( &image ); … … 229 238 else 230 239 { 231 painter->save();232 233 240 painter->setPen( Qt::NoPen ); 234 241 painter->setBrush( brush ); 235 242 236 243 painter->drawRects( rects ); 237 238 painter->restore();239 244 } 240 245 } 241 246 else 242 247 { 243 painter->save();244 245 248 painter->setPen( Qt::NoPen ); 246 249 painter->setBrush( brush ); … … 248 251 painter->drawRects( painter->clipRegion().rects() ); 249 252 250 painter->restore(); 251 } 253 } 254 255 painter->restore(); 252 256 } 253 257 … … 256 260 if ( path.elementCount() == 4 ) 257 261 { 258 QPainterPath::Element &el0 = 259 const_cast<QPainterPath::Element &>( path.elementAt(0) ); 260 QPainterPath::Element &el2 = 261 const_cast<QPainterPath::Element &>( path.elementAt(3) ); 262 263 qSwap( el0.x, el2.x ); 264 qSwap( el0.y, el2.y ); 262 QPainterPath::Element el0 = path.elementAt(0); 263 QPainterPath::Element el3 = path.elementAt(3); 264 265 path.setElementPositionAt( 0, el3.x, el3.y ); 266 path.setElementPositionAt( 3, el0.x, el0.y ); 265 267 } 266 268 } … … 439 441 { 440 442 QPixmap pm( rect.size() ); 441 pm.fill( bgWidget, widget->mapTo( bgWidget, rect.topLeft() ) );443 QwtPainter::fillPixmap( bgWidget, pm, widget->mapTo( bgWidget, rect.topLeft() ) ); 442 444 painter->drawPixmap( rect, pm ); 443 445 } … … 468 470 if ( radius > 0.0 ) 469 471 { 470 QSize sz( radius, radius );472 QSizeF sz( radius, radius ); 471 473 472 474 rects += QRectF( r.topLeft(), sz ); … … 519 521 }; 520 522 521 //! Sets a cross cursor, enables QwtPlotCanvas::BackingStore 522 523 /*! 524 \brief Constructor 525 526 \param plot Parent plot widget 527 \sa QwtPlot::setCanvas() 528 */ 523 529 QwtPlotCanvas::QwtPlotCanvas( QwtPlot *plot ): 524 530 QFrame( plot ) 525 531 { 532 setFrameStyle( QFrame::Panel | QFrame::Sunken ); 533 setLineWidth( 2 ); 534 526 535 d_data = new PrivateData; 527 536 … … 545 554 QwtPlot *QwtPlotCanvas::plot() 546 555 { 547 return qobject_cast<QwtPlot *>( parent Widget() );556 return qobject_cast<QwtPlot *>( parent() ); 548 557 } 549 558 … … 551 560 const QwtPlot *QwtPlotCanvas::plot() const 552 561 { 553 return qobject_cast<const QwtPlot *>( parent Widget() );562 return qobject_cast<const QwtPlot *>( parent() ); 554 563 } 555 564 … … 583 592 if ( isVisible() ) 584 593 { 594 #if QT_VERSION >= 0x050000 595 *d_data->backingStore = grab( rect() ); 596 #else 585 597 *d_data->backingStore = 586 598 QPixmap::grabWidget( this, rect() ); 599 #endif 587 600 } 588 601 } … … 610 623 611 624 /*! 612 Test w ether a paint attribute is enabled625 Test whether a paint attribute is enabled 613 626 614 627 \param attribute Paint attribute 615 \return true if theattribute is enabled628 \return true, when attribute is enabled 616 629 \sa setPaintAttribute() 617 630 */ … … 676 689 /*! 677 690 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 691 678 692 \param event Qt Event 693 \return See QFrame::event() 679 694 */ 680 695 bool QwtPlotCanvas::event( QEvent *event ) … … 716 731 if ( bs.size() != size() ) 717 732 { 718 bs = QPixmap( size() ); 719 720 #ifdef Q_WS_X11 721 if ( bs.x11Info().screen() != x11Info().screen() ) 722 bs.x11SetScreen( x11Info().screen() ); 723 #endif 733 bs = QwtPainter::backingStore( this, size() ); 724 734 725 735 if ( testAttribute(Qt::WA_StyledBackground) ) … … 734 744 if ( d_data->borderRadius <= 0.0 ) 735 745 { 736 bs.fill( this, 0, 0);746 QwtPainter::fillPixmap( this, bs ); 737 747 p.begin( &bs ); 738 748 drawCanvas( &p, false ); … … 771 781 { 772 782 if ( autoFillBackground() ) 783 { 784 qwtFillBackground( &painter, this ); 773 785 qwtDrawBackground( &painter, this ); 786 } 787 } 788 else 789 { 790 if ( borderRadius() > 0.0 ) 791 { 792 QPainterPath clipPath; 793 clipPath.addRect( rect() ); 794 clipPath = clipPath.subtracted( borderPath( rect() ) ); 795 796 painter.save(); 797 798 painter.setClipPath( clipPath, Qt::IntersectClip ); 799 qwtFillBackground( &painter, this ); 800 qwtDrawBackground( &painter, this ); 801 802 painter.restore(); 803 } 774 804 } 775 805 … … 838 868 painter->setBrush( palette().brush( backgroundRole() ) ); 839 869 840 if ( d_data->borderRadius > 0.0 )870 if ( d_data->borderRadius > 0.0 && ( rect() == frameRect() ) ) 841 871 { 842 872 if ( frameWidth() > 0 ) … … 853 883 else 854 884 { 855 painter->drawRect( contentsRect() );885 painter->drawRect( rect() ); 856 886 } 857 887 } … … 870 900 { 871 901 if ( d_data->borderRadius > 0.0 ) 872 painter->setClipPath( borderPath( rect() ), Qt::IntersectClip );902 painter->setClipPath( borderPath( frameRect() ), Qt::IntersectClip ); 873 903 else 874 904 painter->setClipRect( contentsRect(), Qt::IntersectClip ); … … 892 922 893 923 \param painter Painter 894 \sa setBorderRadius() , QFrame::drawFrame()924 \sa setBorderRadius() 895 925 */ 896 926 void QwtPlotCanvas::drawBorder( QPainter *painter ) … … 900 930 if ( frameWidth() > 0 ) 901 931 { 902 QwtPainter::drawRoundedFrame( painter, QRectF( rect() ),932 QwtPainter::drawRoundedFrame( painter, QRectF( frameRect() ), 903 933 d_data->borderRadius, d_data->borderRadius, 904 934 palette(), frameWidth(), frameStyle() ); … … 907 937 else 908 938 { 939 #if QT_VERSION >= 0x040500 940 #if QT_VERSION < 0x050000 941 QStyleOptionFrameV3 opt; 942 #else 943 QStyleOptionFrame opt; 944 #endif 945 opt.init(this); 946 947 int frameShape = frameStyle() & QFrame::Shape_Mask; 948 int frameShadow = frameStyle() & QFrame::Shadow_Mask; 949 950 opt.frameShape = QFrame::Shape( int( opt.frameShape ) | frameShape ); 951 #if 0 952 opt.rect = frameRect(); 953 #endif 954 955 switch (frameShape) 956 { 957 case QFrame::Box: 958 case QFrame::HLine: 959 case QFrame::VLine: 960 case QFrame::StyledPanel: 961 case QFrame::Panel: 962 { 963 opt.lineWidth = lineWidth(); 964 opt.midLineWidth = midLineWidth(); 965 break; 966 } 967 default: 968 { 969 opt.lineWidth = frameWidth(); 970 break; 971 } 972 } 973 974 if ( frameShadow == Sunken ) 975 opt.state |= QStyle::State_Sunken; 976 else if ( frameShadow == Raised ) 977 opt.state |= QStyle::State_Raised; 978 979 style()->drawControl(QStyle::CE_ShapedFrame, &opt, painter, this); 980 #else 909 981 drawFrame( painter ); 982 #endif 910 983 } 911 984 } … … 950 1023 } 951 1024 952 //! Update the cached information sabout the current style sheet1025 //! Update the cached information about the current style sheet 953 1026 void QwtPlotCanvas::updateStyleSheetInfo() 954 1027 { … … 1027 1100 return QPainterPath(); 1028 1101 } 1029 1030 /*!1031 Calculate a mask, that can be used to clip away the border frame1032 1033 \param size Size including the frame1034 */1035 QBitmap QwtPlotCanvas::borderMask( const QSize &size ) const1036 {1037 const QRect r( 0, 0, size.width(), size.height() );1038 1039 const QPainterPath path = borderPath( r );1040 if ( path.isEmpty() )1041 return QBitmap();1042 1043 QImage image( size, QImage::Format_ARGB32_Premultiplied );1044 image.fill( Qt::color0 );1045 1046 QPainter painter( &image );1047 painter.setClipPath( path );1048 painter.fillRect( r, Qt::color1 );1049 1050 // now erase the frame1051 1052 painter.setCompositionMode( QPainter::CompositionMode_DestinationOut );1053 1054 if ( testAttribute(Qt::WA_StyledBackground ) )1055 {1056 QStyleOptionFrame opt;1057 opt.initFrom(this);1058 opt.rect = r;1059 style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );1060 }1061 else1062 {1063 if ( d_data->borderRadius > 0 && frameWidth() > 0 )1064 {1065 painter.setPen( QPen( Qt::color1, frameWidth() ) );1066 painter.setBrush( Qt::NoBrush );1067 painter.setRenderHint( QPainter::Antialiasing, true );1068 1069 painter.drawPath( path );1070 }1071 }1072 1073 painter.end();1074 1075 const QImage mask = image.createMaskFromColor(1076 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor );1077 1078 return QBitmap::fromImage( mask );1079 }
Note:
See TracChangeset
for help on using the changeset viewer.