source: ntrip/trunk/BNC/qwt/qwt_plot_glcanvas.cpp@ 11158

Last change on this file since 11158 was 11158, checked in by stuerze, 4 weeks ago

deprecated functions exchanged libs updated

File size: 5.3 KB
RevLine 
[11158]1/******************************************************************************
[8127]2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#include "qwt_plot_glcanvas.h"
11#include "qwt_plot.h"
12#include "qwt_painter.h"
[11158]13
14#include <qcoreevent.h>
[8127]15#include <qpainter.h>
[11158]16#include <qpainterpath.h>
17#include <qglframebufferobject.h>
[8127]18
[11158]19namespace
[8127]20{
[11158]21 class QwtPlotGLCanvasFormat : public QGLFormat
[8127]22 {
[11158]23 public:
24 QwtPlotGLCanvasFormat()
25 : QGLFormat( QGLFormat::defaultFormat() )
[8127]26 {
[11158]27 setSampleBuffers( true );
[8127]28 }
[11158]29 };
[8127]30}
31
32class QwtPlotGLCanvas::PrivateData
33{
[11158]34 public:
35 PrivateData()
36 : fboDirty( true )
37 , fbo( NULL )
[8127]38 {
39 }
40
[11158]41 ~PrivateData()
[8127]42 {
[11158]43 delete fbo;
[8127]44 }
[11158]45
46 bool fboDirty;
47 QGLFramebufferObject* fbo;
[8127]48};
49
[9383]50/*!
[11158]51 \brief Constructor
[8127]52
[11158]53 \param plot Parent plot widget
54 \sa QwtPlot::setCanvas()
55 */
56QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot* plot )
57 : QGLWidget( QwtPlotGLCanvasFormat(), plot )
58 , QwtPlotAbstractGLCanvas( this )
[8127]59{
[11158]60 init();
61}
62/*!
63 \brief Constructor
[8127]64
[11158]65 \param format OpenGL rendering options
66 \param plot Parent plot widget
67 \sa QwtPlot::setCanvas()
68 */
69QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat& format, QwtPlot* plot )
70 : QGLWidget( format, plot )
71 , QwtPlotAbstractGLCanvas( this )
72{
73 init();
[8127]74}
75
76//! Destructor
77QwtPlotGLCanvas::~QwtPlotGLCanvas()
78{
[11158]79 delete m_data;
[8127]80}
81
[11158]82void QwtPlotGLCanvas::init()
[8127]83{
[11158]84 m_data = new PrivateData;
[8127]85
[11158]86#if 1
87 setAttribute( Qt::WA_OpaquePaintEvent, true );
88#endif
89 setLineWidth( 2 );
90 setFrameShadow( QFrame::Sunken );
91 setFrameShape( QFrame::Panel );
[8127]92}
93
94/*!
[11158]95 Paint event
[8127]96
[11158]97 \param event Paint event
98 \sa QwtPlot::drawCanvas()
[8127]99 */
[11158]100void QwtPlotGLCanvas::paintEvent( QPaintEvent* event )
[8127]101{
[11158]102 QGLWidget::paintEvent( event );
[8127]103}
104
105/*!
[11158]106 Qt event handler for QEvent::PolishRequest and QEvent::StyleChange
107 \param event Qt Event
108 \return See QGLWidget::event()
[8127]109 */
[11158]110bool QwtPlotGLCanvas::event( QEvent* event )
[8127]111{
[11158]112 const bool ok = QGLWidget::event( event );
[8127]113
[11158]114 if ( event->type() == QEvent::PolishRequest ||
115 event->type() == QEvent::StyleChange )
116 {
117 // assuming, that we always have a styled background
118 // when we have a style sheet
[8127]119
[11158]120 setAttribute( Qt::WA_StyledBackground,
121 testAttribute( Qt::WA_StyleSheet ) );
122 }
123
124 return ok;
[8127]125}
126
127/*!
[11158]128 Invalidate the paint cache and repaint the canvas
129 \sa invalidatePaintCache()
[8127]130 */
[11158]131void QwtPlotGLCanvas::replot()
[8127]132{
[11158]133 QwtPlotAbstractGLCanvas::replot();
[8127]134}
135
[11158]136//! Invalidate the internal backing store
137void QwtPlotGLCanvas::invalidateBackingStore()
[8127]138{
[11158]139 m_data->fboDirty = true;
[8127]140}
141
[11158]142void QwtPlotGLCanvas::clearBackingStore()
[8127]143{
[11158]144 delete m_data->fbo;
145 m_data->fbo = NULL;
[8127]146}
147
148/*!
[11158]149 Calculate the painter path for a styled or rounded border
[8127]150
[11158]151 When the canvas has no styled background or rounded borders
152 the painter path is empty.
[8127]153
[11158]154 \param rect Bounding rectangle of the canvas
155 \return Painter path, that can be used for clipping
[9383]156 */
[11158]157QPainterPath QwtPlotGLCanvas::borderPath( const QRect& rect ) const
[8127]158{
[11158]159 return canvasBorderPath( rect );
[8127]160}
161
[11158]162//! No operation - reserved for some potential use in the future
163void QwtPlotGLCanvas::initializeGL()
[8127]164{
165}
166
[11158]167//! Paint the plot
168void QwtPlotGLCanvas::paintGL()
[8127]169{
[11158]170 const bool hasFocusIndicator =
171 hasFocus() && focusIndicator() == CanvasFocusIndicator;
[8127]172
[11158]173 QPainter painter;
[8127]174
[11158]175 if ( testPaintAttribute( QwtPlotGLCanvas::BackingStore ) )
[8127]176 {
[11158]177 const qreal pixelRatio = QwtPainter::devicePixelRatio( this );
178 const QRect rect( 0, 0, width() * pixelRatio, height() * pixelRatio );
[8127]179
[11158]180 if ( hasFocusIndicator )
181 painter.begin( this );
[8127]182
[11158]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 }
[8127]191
[11158]192 if ( m_data->fbo == NULL )
193 {
194 QGLFramebufferObjectFormat format;
195 format.setSamples( 4 );
196 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
[8127]197
[11158]198 m_data->fbo = new QGLFramebufferObject( rect.size(), format );
199 m_data->fboDirty = true;
200 }
[8127]201
[11158]202 if ( m_data->fboDirty )
203 {
204 QPainter fboPainter( m_data->fbo );
205 fboPainter.scale( pixelRatio, pixelRatio );
206 draw( &fboPainter );
207 fboPainter.end();
[8127]208
[11158]209 m_data->fboDirty = false;
210 }
[8127]211
[11158]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 */
[8127]218
[11158]219 QGLFramebufferObject::blitFramebuffer( NULL,
220 rect.translated( 0, height() - rect.height() ), m_data->fbo, rect );
[8127]221 }
[9383]222 else
[8127]223 {
[11158]224 painter.begin( this );
225 draw( &painter );
[8127]226 }
227
[11158]228 if ( hasFocusIndicator )
229 drawFocusIndicator( &painter );
[8127]230}
231
[11158]232//! No operation - reserved for some potential use in the future
233void QwtPlotGLCanvas::resizeGL( int, int )
[8127]234{
[11158]235 // nothing to do
[8127]236}
237
[11158]238#include "moc_qwt_plot_glcanvas.cpp"
Note: See TracBrowser for help on using the repository browser.