qwt_paint_buffer.cpp

Go to the documentation of this file.
00001 /*-*- c++ -*-******************************************************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *****************************************************************************/
00019 
00020 #include <qwidget.h>
00021 
00022 #if QT_VERSION < 0x040000
00023 #else
00024 //Added by the Qt porting tool:
00025 #include <QtGui/QPaintEngine>
00026 #include <QtGui/QPixmap>
00027 #endif
00028 
00029 #include <qpainter.h>
00030 
00031 #include "qwt_paint_buffer.h"
00032 
00033 namespace hippodraw {
00034 
00035 #if QT_VERSION < 0x040000
00036 bool QwtPaintBuffer::d_enabled = TRUE;
00037 #else
00038 bool QwtPaintBuffer::d_enabled = true;
00039 #endif
00040 
00042 QwtPaintBuffer::QwtPaintBuffer():
00043     d_device(0),
00044     d_painter(0),
00045     d_devicePainter(0)
00046 {
00047 }
00048 
00059 QwtPaintBuffer::QwtPaintBuffer(QPaintDevice *device, 
00060         const QRect &rect, QPainter *painter):
00061     d_device(0),
00062     d_painter(0),
00063     d_devicePainter(0)
00064 {
00065     open(device, rect, painter);
00066 }
00067 
00072 QwtPaintBuffer::~QwtPaintBuffer()
00073 {
00074     close();
00075 }
00076 
00083 QPainter *QwtPaintBuffer::painter() 
00084 { 
00085     return d_painter; 
00086 }
00087 
00091 const QPaintDevice *QwtPaintBuffer::device() 
00092 { 
00093     return d_device; 
00094 }
00095 
00101 void QwtPaintBuffer::setEnabled(bool enable) 
00102 { 
00103     d_enabled = enable; 
00104 }
00105 
00109 bool QwtPaintBuffer::isEnabled() 
00110 { 
00111     return d_enabled; 
00112 }
00113 
00122 void QwtPaintBuffer::open(QPaintDevice *device, 
00123         const QRect &rect, QPainter *painter)
00124 {
00125     close();
00126 
00127     if ( device == 0 || !rect.isValid() )
00128         return;
00129 
00130     d_device = device;
00131     d_devicePainter = painter;
00132     d_rect = rect;
00133 
00134     if ( isEnabled() )
00135     {
00136         d_pixBuffer.resize(d_rect.size());
00137 
00138         d_painter = new QPainter();
00139         if ( d_device->devType() == QInternal::Widget )
00140         {
00141             QWidget *w = (QWidget *)d_device;
00142             d_pixBuffer.fill(w, d_rect.topLeft());
00143             d_painter->begin(&d_pixBuffer, w);
00144             d_painter->translate(-d_rect.x(), -d_rect.y());
00145         }
00146         else
00147         {
00148             d_painter->begin(&d_pixBuffer);
00149         }
00150     }
00151     else
00152     {
00153         if ( d_devicePainter )
00154             d_painter = d_devicePainter;
00155         else
00156         {
00157             d_painter = new QPainter(d_device);
00158 
00159             if ( d_device->devType() == QInternal::Widget )
00160             {
00161 #if QT_VERSION < 0x040000
00162                 QWidget *w = (QWidget *)d_device;
00163                 if ( w->testWFlags( Qt::WRepaintNoErase | Qt::WResizeNoErase) )
00164 // #else
00165 //                 if ( w->testWFlags( Qt::WNoAutoErase | Qt::WResizeNoErase) )
00166 #endif
00167                     d_painter->eraseRect(d_rect);
00168             }
00169         }
00170     }
00171 }
00172 
00176 void QwtPaintBuffer::flush()
00177 {
00178     if ( d_enabled && d_device != 0 && d_rect.isValid())
00179     {
00180                 // We need a painter to find out if
00181                 // there is a painter redirection for d_device.
00182 
00183                 QPainter *p;
00184                 if ( d_devicePainter == 0 )
00185                         p = new QPainter(d_device);
00186                 else 
00187                         p = d_devicePainter;
00188 
00189                 QPaintDevice *device = p->device();
00190 #if QT_VERSION < 0x040000
00191                 if ( device->isExtDev() )
00192 #else
00193                 QPaintEngine * pe = device -> paintEngine ();
00194                 QPaintEngine::Type type = pe-> type ();
00195                 if ( type != QPaintEngine::PostScript )
00196 #endif
00197                   d_devicePainter->drawPixmap(d_rect.topLeft(), d_pixBuffer);
00198                 else
00199             bitBlt(device, d_rect.topLeft(), &d_pixBuffer );
00200 
00201                 if ( d_devicePainter == 0 )
00202                         delete p;
00203     }
00204 }
00205 
00209 void QwtPaintBuffer::close()
00210 {
00211     flush();
00212 
00213     if ( d_painter )
00214     {
00215         if ( d_painter->isActive() )
00216             d_painter->end();
00217 
00218         if ( d_painter != d_devicePainter )
00219             delete d_painter;
00220     }
00221 
00222     if ( !d_pixBuffer.isNull() )
00223         d_pixBuffer = QPixmap();
00224 
00225     d_device = 0;
00226     d_painter = 0;
00227     d_devicePainter = 0;
00228 } 
00229 
00230 } // namespace hippodraw
00231 

Generated for HippoDraw Class Library by doxygen