Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "qwt_plot_glcanvas.h"
00011 #include "qwt_plot.h"
00012 #include <qevent.h>
00013 #include <qglframebufferobject.h>
00014
00015 class QwtPlotGLCanvas::PrivateData
00016 {
00017 public:
00018 PrivateData():
00019 fboDirty( true ),
00020 fbo( NULL )
00021 {
00022 }
00023
00024 ~PrivateData()
00025 {
00026 delete fbo;
00027 }
00028
00029 bool fboDirty;
00030 QGLFramebufferObject* fbo;
00031 };
00032
00033 class QwtPlotGLCanvasFormat: public QGLFormat
00034 {
00035 public:
00036 QwtPlotGLCanvasFormat():
00037 QGLFormat( QGLFormat::defaultFormat() )
00038 {
00039 setSampleBuffers( true );
00040 }
00041 };
00042
00049 QwtPlotGLCanvas::QwtPlotGLCanvas( QwtPlot *plot ):
00050 QGLWidget( QwtPlotGLCanvasFormat(), plot ),
00051 QwtPlotAbstractGLCanvas( this )
00052 {
00053 d_data = new PrivateData;
00054 #if 1
00055 setAttribute( Qt::WA_OpaquePaintEvent, true );
00056 #endif
00057 }
00058
00059 QwtPlotGLCanvas::QwtPlotGLCanvas( const QGLFormat &format, QwtPlot *plot ):
00060 QGLWidget( format, plot ),
00061 QwtPlotAbstractGLCanvas( this )
00062 {
00063 d_data = new PrivateData;
00064 #if 1
00065 setAttribute( Qt::WA_OpaquePaintEvent, true );
00066 #endif
00067 }
00068
00070 QwtPlotGLCanvas::~QwtPlotGLCanvas()
00071 {
00072 delete d_data;
00073 }
00074
00081 void QwtPlotGLCanvas::paintEvent( QPaintEvent *event )
00082 {
00083 QGLWidget::paintEvent( event );
00084 }
00085
00091 bool QwtPlotGLCanvas::event( QEvent *event )
00092 {
00093 const bool ok = QGLWidget::event( event );
00094
00095 if ( event->type() == QEvent::PolishRequest ||
00096 event->type() == QEvent::StyleChange )
00097 {
00098
00099
00100
00101 setAttribute( Qt::WA_StyledBackground,
00102 testAttribute( Qt::WA_StyleSheet ) );
00103 }
00104
00105 return ok;
00106 }
00107
00108 void QwtPlotGLCanvas::replot()
00109 {
00110 QwtPlotAbstractGLCanvas::replot();
00111 }
00112
00113 void QwtPlotGLCanvas::invalidateBackingStore()
00114 {
00115 d_data->fboDirty = true;
00116 }
00117
00118 void QwtPlotGLCanvas::clearBackingStore()
00119 {
00120 delete d_data->fbo;
00121 d_data->fbo = NULL;
00122 }
00123
00124 QPainterPath QwtPlotGLCanvas::borderPath( const QRect &rect ) const
00125 {
00126 return borderPath2( rect );
00127 }
00128
00129 void QwtPlotGLCanvas::initializeGL()
00130 {
00131 }
00132
00133 void QwtPlotGLCanvas::paintGL()
00134 {
00135 const bool hasFocusIndicator =
00136 hasFocus() && focusIndicator() == CanvasFocusIndicator;
00137
00138 QPainter painter;
00139
00140 #if QT_VERSION < 0x040600
00141 painter.begin( this );
00142 draw( &painter );
00143 #else
00144 if ( testPaintAttribute( QwtPlotGLCanvas::BackingStore ) )
00145 {
00146 if ( hasFocusIndicator )
00147 painter.begin( this );
00148
00149 const QRect rect(0, 0, width(), height());
00150
00151 if ( d_data->fbo && d_data->fbo->size() != size() )
00152 {
00153 delete d_data->fbo;
00154 d_data->fbo = NULL;
00155 }
00156
00157 if ( d_data->fbo == NULL || d_data->fbo->size() != size() )
00158 {
00159 QGLFramebufferObjectFormat format;
00160 format.setSamples( 4 );
00161 format.setAttachment(QGLFramebufferObject::CombinedDepthStencil);
00162
00163 d_data->fbo = new QGLFramebufferObject( size(), format );
00164 d_data->fboDirty = true;
00165 }
00166
00167 if ( d_data->fboDirty )
00168 {
00169 QPainter fboPainter( d_data->fbo );
00170 draw( &fboPainter);
00171 fboPainter.end();
00172
00173 d_data->fboDirty = false;
00174 }
00175
00176 QGLFramebufferObject::blitFramebuffer( NULL, rect, d_data->fbo, rect );
00177 }
00178 else
00179 {
00180 painter.begin( this );
00181 draw( &painter );
00182 }
00183 #endif
00184
00185 if ( hasFocusIndicator )
00186 drawFocusIndicator( &painter );
00187 }
00188
00189 void QwtPlotGLCanvas::resizeGL( int, int )
00190 {
00191
00192 }