Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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 <QPixmap>
00026 #endif
00027 
00028 #include <qpainter.h>
00029 #include "qwt_paint_buffer.h"
00030 
00031 #if QT_VERSION < 0x040000
00032 bool QwtPaintBuffer::d_enabled = TRUE;
00033 #else
00034 bool QwtPaintBuffer::d_enabled = true;
00035 #endif
00036 
00038 QwtPaintBuffer::QwtPaintBuffer():
00039     d_device(0),
00040     d_painter(0),
00041     d_devicePainter(0)
00042 {
00043 }
00044 
00055 QwtPaintBuffer::QwtPaintBuffer(QPaintDevice *device, 
00056         const QRect &rect, QPainter *painter):
00057     d_device(0),
00058     d_painter(0),
00059     d_devicePainter(0)
00060 {
00061     open(device, rect, painter);
00062 }
00063 
00068 QwtPaintBuffer::~QwtPaintBuffer()
00069 {
00070     close();
00071 }
00072 
00079 QPainter *QwtPaintBuffer::painter() 
00080 { 
00081     return d_painter; 
00082 }
00083 
00087 const QPaintDevice *QwtPaintBuffer::device() 
00088 { 
00089     return d_device; 
00090 }
00091 
00097 void QwtPaintBuffer::setEnabled(bool enable) 
00098 { 
00099     d_enabled = enable; 
00100 }
00101 
00105 bool QwtPaintBuffer::isEnabled() 
00106 { 
00107     return d_enabled; 
00108 }
00109 
00118 void QwtPaintBuffer::open(QPaintDevice *device, 
00119         const QRect &rect, QPainter *painter)
00120 {
00121     close();
00122 
00123     if ( device == 0 || !rect.isValid() )
00124         return;
00125 
00126     d_device = device;
00127     d_devicePainter = painter;
00128     d_rect = rect;
00129 
00130     if ( isEnabled() )
00131     {
00132         d_pixBuffer.resize(d_rect.size());
00133 
00134         d_painter = new QPainter();
00135         if ( d_device->devType() == QInternal::Widget )
00136         {
00137             QWidget *w = (QWidget *)d_device;
00138             d_pixBuffer.fill(w, d_rect.topLeft());
00139             d_painter->begin(&d_pixBuffer, w);
00140             d_painter->translate(-d_rect.x(), -d_rect.y());
00141         }
00142         else
00143         {
00144             d_painter->begin(&d_pixBuffer);
00145         }
00146     }
00147     else
00148     {
00149         if ( d_devicePainter )
00150             d_painter = d_devicePainter;
00151         else
00152         {
00153             d_painter = new QPainter(d_device);
00154 
00155             if ( d_device->devType() == QInternal::Widget )
00156             {
00157                 QWidget *w = (QWidget *)d_device;
00158 #if QT_VERSION < 0x040000
00159                 if ( w->testWFlags( Qt::WRepaintNoErase | Qt::WResizeNoErase) )
00160 #else
00161                 if ( w->testWFlags( Qt::WNoAutoErase | Qt::WResizeNoErase) )
00162 #endif
00163                     d_painter->eraseRect(d_rect);
00164             }
00165         }
00166     }
00167 }
00168 
00172 void QwtPaintBuffer::flush()
00173 {
00174     if ( d_enabled && d_device != 0 && d_rect.isValid())
00175     {
00176                 // We need a painter to find out if
00177                 // there is a painter redirection for d_device.
00178 
00179                 QPainter *p;
00180                 if ( d_devicePainter == 0 )
00181                         p = new QPainter(d_device);
00182                 else 
00183                         p = d_devicePainter;
00184 
00185                 QPaintDevice *device = p->device();
00186                 if ( device->isExtDev() )
00187             d_devicePainter->drawPixmap(d_rect.topLeft(), d_pixBuffer);
00188                 else
00189             bitBlt(device, d_rect.topLeft(), &d_pixBuffer );
00190 
00191                 if ( d_devicePainter == 0 )
00192                         delete p;
00193     }
00194 }
00195 
00199 void QwtPaintBuffer::close()
00200 {
00201     flush();
00202 
00203     if ( d_painter )
00204     {
00205         if ( d_painter->isActive() )
00206             d_painter->end();
00207 
00208         if ( d_painter != d_devicePainter )
00209             delete d_painter;
00210     }
00211 
00212     if ( !d_pixBuffer.isNull() )
00213         d_pixBuffer = QPixmap();
00214 
00215     d_device = 0;
00216     d_painter = 0;
00217     d_devicePainter = 0;
00218 } 

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3