Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_plot_glcanvas.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_plot_glcanvas.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_glcanvas.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 11 11 #include "qwt_plot.h" 12 12 #include "qwt_painter.h" 13 #include <qevent.h> 13 14 #include <qcoreevent.h> 14 15 #include <qpainter.h> 15 #include <qdrawutil.h> 16 #include <qstyle.h> 17 #include <qstyleoption.h> 18 19 #define FIX_GL_TRANSLATION 0 20 21 static QWidget *qwtBGWidget( QWidget *widget ) 22 { 23 QWidget *w = widget; 24 25 for ( ; w->parentWidget() != NULL; w = w->parentWidget() ) 26 { 27 if ( w->autoFillBackground() || 28 w->testAttribute( Qt::WA_StyledBackground ) ) 29 { 30 return w; 31 } 32 } 33 34 return w; 35 } 36 37 static void qwtUpdateContentsRect( QwtPlotGLCanvas *canvas ) 38 { 39 const int fw = canvas->frameWidth(); 40 canvas->setContentsMargins( fw, fw, fw, fw ); 16 #include <qpainterpath.h> 17 #include <qglframebufferobject.h> 18 19 namespace 20 { 21 class QwtPlotGLCanvasFormat : public QGLFormat 22 { 23 public: 24 QwtPlotGLCanvasFormat() 25 : QGLFormat( QGLFormat::defaultFormat() ) 26 { 27 setSampleBuffers( true ); 28 } 29 }; 41 30 } 42 31 43 32 class QwtPlotGLCanvas::PrivateData 44 33 { 45 public: 46 PrivateData(): 47 frameStyle( QFrame::Panel | QFrame::Sunken), 48 lineWidth( 2 ), 49 midLineWidth( 0 ) 50 { 51 } 52 53 int frameStyle; 54 int lineWidth; 55 int midLineWidth; 34 public: 35 PrivateData() 36 : fboDirty( true ) 37 , fbo( NULL ) 38 { 39 } 40 41 ~PrivateData() 42 { 43 delete fbo; 44 } 45 46 bool fboDirty; 47 QGLFramebufferObject* fbo; 56 48 }; 57 49 58 class QwtPlotGLCanvasFormat: public QGLFormat 59 { 60 public: 61 QwtPlotGLCanvasFormat(): 62 QGLFormat( QGLFormat::defaultFormat() ) 63 { 64 setSampleBuffers( true ); 65 } 66 }; 67 68 /*! 69 \brief Constructor 70 71 \param plot Parent plot widget 72 \sa QwtPlot::setCanvas() 73 */ 74 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot *plot ): 75 QGLWidget( QwtPlotGLCanvasFormat(), plot ) 76 { 77 d_data = new PrivateData; 78 79 #ifndef QT_NO_CURSOR 80 setCursor( Qt::CrossCursor ); 81 #endif 82 83 setAutoFillBackground( true ); 84 qwtUpdateContentsRect( this ); 50 /*! 51 \brief Constructor 52 53 \param plot Parent plot widget 54 \sa QwtPlot::setCanvas() 55 */ 56 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot* plot ) 57 : QGLWidget( QwtPlotGLCanvasFormat(), plot ) 58 , QwtPlotAbstractGLCanvas( this ) 59 { 60 init(); 61 } 62 /*! 63 \brief Constructor 64 65 \param format OpenGL rendering options 66 \param plot Parent plot widget 67 \sa QwtPlot::setCanvas() 68 */ 69 QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat& format, QwtPlot* plot ) 70 : QGLWidget( format, plot ) 71 , QwtPlotAbstractGLCanvas( this ) 72 { 73 init(); 85 74 } 86 75 … … 88 77 QwtPlotGLCanvas::~QwtPlotGLCanvas() 89 78 { 90 delete d_data; 91 } 92 93 /*! 94 Set the frame style 95 96 \param style The bitwise OR between a shape and a shadow. 97 98 \sa frameStyle(), QFrame::setFrameStyle(), 99 setFrameShadow(), setFrameShape() 100 */ 101 void QwtPlotGLCanvas::setFrameStyle( int style ) 102 { 103 if ( style != d_data->frameStyle ) 104 { 105 d_data->frameStyle = style; 106 qwtUpdateContentsRect( this ); 107 108 update(); 109 } 110 } 111 112 /*! 113 \return The bitwise OR between a frameShape() and a frameShadow() 114 \sa setFrameStyle(), QFrame::frameStyle() 115 */ 116 int QwtPlotGLCanvas::frameStyle() const 117 { 118 return d_data->frameStyle; 119 } 120 121 /*! 122 Set the frame shadow 123 124 \param shadow Frame shadow 125 \sa frameShadow(), setFrameShape(), QFrame::setFrameShadow() 126 */ 127 void QwtPlotGLCanvas::setFrameShadow( Shadow shadow ) 128 { 129 setFrameStyle(( d_data->frameStyle & QFrame::Shape_Mask ) | shadow ); 130 } 131 132 /*! 133 \return Frame shadow 134 \sa setFrameShadow(), QFrame::setFrameShadow() 135 */ 136 QwtPlotGLCanvas::Shadow QwtPlotGLCanvas::frameShadow() const 137 { 138 return (Shadow) ( d_data->frameStyle & QFrame::Shadow_Mask ); 139 } 140 141 /*! 142 Set the frame shape 143 144 \param shape Frame shape 145 \sa frameShape(), setFrameShadow(), QFrame::frameShape() 146 */ 147 void QwtPlotGLCanvas::setFrameShape( Shape shape ) 148 { 149 setFrameStyle( ( d_data->frameStyle & QFrame::Shadow_Mask ) | shape ); 150 } 151 152 /*! 153 \return Frame shape 154 \sa setFrameShape(), QFrame::frameShape() 155 */ 156 QwtPlotGLCanvas::Shape QwtPlotGLCanvas::frameShape() const 157 { 158 return (Shape) ( d_data->frameStyle & QFrame::Shape_Mask ); 159 } 160 161 /*! 162 Set the frame line width 163 164 The default line width is 2 pixels. 165 166 \param width Line width of the frame 167 \sa lineWidth(), setMidLineWidth() 168 */ 169 void QwtPlotGLCanvas::setLineWidth( int width ) 170 { 171 width = qMax( width, 0 ); 172 if ( width != d_data->lineWidth ) 173 { 174 d_data->lineWidth = qMax( width, 0 ); 175 qwtUpdateContentsRect( this ); 176 update(); 177 } 178 } 179 180 /*! 181 \return Line width of the frame 182 \sa setLineWidth(), midLineWidth() 183 */ 184 int QwtPlotGLCanvas::lineWidth() const 185 { 186 return d_data->lineWidth; 187 } 188 189 /*! 190 Set the frame mid line width 191 192 The default midline width is 0 pixels. 193 194 \param width Midline width of the frame 195 \sa midLineWidth(), setLineWidth() 196 */ 197 void QwtPlotGLCanvas::setMidLineWidth( int width ) 198 { 199 width = qMax( width, 0 ); 200 if ( width != d_data->midLineWidth ) 201 { 202 d_data->midLineWidth = width; 203 qwtUpdateContentsRect( this ); 204 update(); 205 } 206 } 207 208 /*! 209 \return Midline width of the frame 210 \sa setMidLineWidth(), lineWidth() 211 */ 212 int QwtPlotGLCanvas::midLineWidth() const 213 { 214 return d_data->midLineWidth; 215 } 216 217 /*! 218 \return Frame width depending on the style, line width and midline width. 219 */ 220 int QwtPlotGLCanvas::frameWidth() const 221 { 222 return ( frameStyle() != NoFrame ) ? d_data->lineWidth : 0; 223 } 224 225 /*! 226 Paint event 227 228 \param event Paint event 229 \sa QwtPlot::drawCanvas() 230 */ 231 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event ) 232 { 233 Q_UNUSED( event ); 234 235 QPainter painter( this ); 236 237 #if FIX_GL_TRANSLATION 238 if ( painter.paintEngine()->type() == QPaintEngine::OpenGL2 ) 239 { 240 // work around a translation bug of QPaintEngine::OpenGL2 241 painter.translate( 1, 1 ); 242 } 79 delete m_data; 80 } 81 82 void QwtPlotGLCanvas::init() 83 { 84 m_data = new PrivateData; 85 86 #if 1 87 setAttribute( Qt::WA_OpaquePaintEvent, true ); 243 88 #endif 244 245 drawBackground( &painter ); 246 drawItems( &painter ); 247 248 if ( !testAttribute( Qt::WA_StyledBackground ) ) 249 { 250 if ( frameWidth() > 0 ) 251 drawBorder( &painter ); 252 } 253 } 254 /*! 255 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 256 \param event Qt Event 257 \return See QGLWidget::event() 258 */ 259 bool QwtPlotGLCanvas::event( QEvent *event ) 89 setLineWidth( 2 ); 90 setFrameShadow( QFrame::Sunken ); 91 setFrameShape( QFrame::Panel ); 92 } 93 94 /*! 95 Paint event 96 97 \param event Paint event 98 \sa QwtPlot::drawCanvas() 99 */ 100 void QwtPlotGLCanvas::paintEvent( QPaintEvent* event ) 101 { 102 QGLWidget::paintEvent( event ); 103 } 104 105 /*! 106 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange 107 \param event Qt Event 108 \return See QGLWidget::event() 109 */ 110 bool QwtPlotGLCanvas::event( QEvent* event ) 260 111 { 261 112 const bool ok = QGLWidget::event( event ); … … 275 126 276 127 /*! 277 Draw the plot items 278 \param painter Painter 279 280 \sa QwtPlot::drawCanvas() 281 */ 282 void QwtPlotGLCanvas::drawItems( QPainter *painter ) 283 { 284 painter->save(); 285 286 painter->setClipRect( contentsRect(), Qt::IntersectClip ); 287 288 QwtPlot *plot = qobject_cast< QwtPlot *>( parent() ); 289 if ( plot ) 290 plot->drawCanvas( painter ); 291 292 painter->restore(); 293 } 294 295 /*! 296 Draw the background of the canvas 297 \param painter Painter 298 */ 299 void QwtPlotGLCanvas::drawBackground( QPainter *painter ) 300 { 301 painter->save(); 302 303 QWidget *w = qwtBGWidget( this ); 304 305 const QPoint off = mapTo( w, QPoint() ); 306 painter->translate( -off ); 307 308 const QRect fillRect = rect().translated( off ); 309 310 if ( w->testAttribute( Qt::WA_StyledBackground ) ) 311 { 312 painter->setClipRect( fillRect ); 313 314 QStyleOption opt; 315 opt.initFrom( w ); 316 w->style()->drawPrimitive( QStyle::PE_Widget, &opt, painter, w); 128 Invalidate the paint cache and repaint the canvas 129 \sa invalidatePaintCache() 130 */ 131 void QwtPlotGLCanvas::replot() 132 { 133 QwtPlotAbstractGLCanvas::replot(); 134 } 135 136 //! Invalidate the internal backing store 137 void QwtPlotGLCanvas::invalidateBackingStore() 138 { 139 m_data->fboDirty = true; 140 } 141 142 void QwtPlotGLCanvas::clearBackingStore() 143 { 144 delete m_data->fbo; 145 m_data->fbo = NULL; 146 } 147 148 /*! 149 Calculate the painter path for a styled or rounded border 150 151 When the canvas has no styled background or rounded borders 152 the painter path is empty. 153 154 \param rect Bounding rectangle of the canvas 155 \return Painter path, that can be used for clipping 156 */ 157 QPainterPath QwtPlotGLCanvas::borderPath( const QRect& rect ) const 158 { 159 return canvasBorderPath( rect ); 160 } 161 162 //! No operation - reserved for some potential use in the future 163 void QwtPlotGLCanvas::initializeGL() 164 { 165 } 166 167 //! Paint the plot 168 void QwtPlotGLCanvas::paintGL() 169 { 170 const bool hasFocusIndicator = 171 hasFocus() && focusIndicator() == CanvasFocusIndicator; 172 173 QPainter painter; 174 175 if ( testPaintAttribute( QwtPlotGLCanvas::BackingStore ) ) 176 { 177 const qreal pixelRatio = QwtPainter::devicePixelRatio( this ); 178 const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio ); 179 180 if ( hasFocusIndicator ) 181 painter.begin( this ); 182 183 if ( m_data->fbo ) 184 { 185 if ( m_data->fbo->size() != rect.size() ) 186 { 187 delete m_data->fbo; 188 m_data->fbo = NULL; 189 } 190 } 191 192 if ( m_data->fbo == NULL ) 193 { 194 QGLFramebufferObjectFormat format; 195 format.setSamples( 4 ); 196 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); 197 198 m_data->fbo = new QGLFramebufferObject( rect.size(), format ); 199 m_data->fboDirty = true; 200 } 201 202 if ( m_data->fboDirty ) 203 { 204 QPainter fboPainter( m_data->fbo ); 205 fboPainter.scale( pixelRatio, pixelRatio ); 206 draw( &fboPainter ); 207 fboPainter.end(); 208 209 m_data->fboDirty = false; 210 } 211 212 /* 213 Why do we have this strange translation - but, anyway 214 QwtPlotGLCanvas in combination with scaling factor 215 is not very likely to happen as using QwtPlotOpenGLCanvas 216 usually makes more sense then. 217 */ 218 219 QGLFramebufferObject::blitFramebuffer( NULL, 220 rect.translated( 0, height() - rect.height() ), m_data->fbo, rect ); 317 221 } 318 222 else 319 223 { 320 painter->fillRect( fillRect, 321 w->palette().brush( w->backgroundRole() ) ); 322 } 323 324 painter->restore(); 325 } 326 327 /*! 328 Draw the border of the canvas 329 \param painter Painter 330 */ 331 void QwtPlotGLCanvas::drawBorder( QPainter *painter ) 332 { 333 const int fw = frameWidth(); 334 if ( fw <= 0 ) 335 return; 336 337 if ( frameShadow() == QwtPlotGLCanvas::Plain ) 338 { 339 qDrawPlainRect( painter, frameRect(), 340 palette().shadow().color(), lineWidth() ); 341 } 342 else 343 { 344 if ( frameShape() == QwtPlotGLCanvas::Box ) 345 { 346 qDrawShadeRect( painter, frameRect(), palette(), 347 frameShadow() == Sunken, lineWidth(), midLineWidth() ); 348 } 349 else 350 { 351 qDrawShadePanel( painter, frameRect(), palette(), 352 frameShadow() == Sunken, lineWidth() ); 353 } 354 } 355 } 356 357 //! Calls repaint() 358 void QwtPlotGLCanvas::replot() 359 { 360 repaint(); 361 } 362 363 /*! 364 \return Empty path 365 */ 366 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const 367 { 368 Q_UNUSED( rect ); 369 return QPainterPath(); 370 } 371 372 //! \return The rectangle where the frame is drawn in. 373 QRect QwtPlotGLCanvas::frameRect() const 374 { 375 const int fw = frameWidth(); 376 return contentsRect().adjusted( -fw, -fw, fw, fw ); 377 } 224 painter.begin( this ); 225 draw( &painter ); 226 } 227 228 if ( hasFocusIndicator ) 229 drawFocusIndicator( &painter ); 230 } 231 232 //! No operation - reserved for some potential use in the future 233 void QwtPlotGLCanvas::resizeGL( int, int ) 234 { 235 // nothing to do 236 } 237 238 #include "moc_qwt_plot_glcanvas.cpp"
Note:
See TracChangeset
for help on using the changeset viewer.
