qwt_paint_buffer.cpp
Go to the documentation of this file.
1 /*-*- c++ -*-******************************************************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *****************************************************************************/
19 
20 #include <qwidget.h>
21 
22 #if QT_VERSION < 0x040000
23 #else
24 //Added by the Qt porting tool:
25 #include <QtGui/QPaintEngine>
26 #include <QtGui/QPixmap>
27 #endif
28 
29 #include <qpainter.h>
30 
31 #include "qwt_paint_buffer.h"
32 
33 namespace hippodraw {
34 
35 #if QT_VERSION < 0x040000
36 bool QwtPaintBuffer::d_enabled = TRUE;
37 #else
38 bool QwtPaintBuffer::d_enabled = true;
39 #endif
40 
43  d_device(0),
44  d_painter(0),
45  d_devicePainter(0)
46 {
47 }
48 
60  const QRect &rect, QPainter *painter):
61  d_device(0),
62  d_painter(0),
63  d_devicePainter(0)
64 {
65  open(device, rect, painter);
66 }
67 
73 {
74  close();
75 }
76 
84 {
85  return d_painter;
86 }
87 
92 {
93  return d_device;
94 }
95 
101 void QwtPaintBuffer::setEnabled(bool enable)
102 {
103  d_enabled = enable;
104 }
105 
110 {
111  return d_enabled;
112 }
113 
123  const QRect &rect, QPainter *painter)
124 {
125  close();
126 
127  if ( device == 0 || !rect.isValid() )
128  return;
129 
130  d_device = device;
132  d_rect = rect;
133 
134  if ( isEnabled() )
135  {
137 
138  d_painter = new QPainter();
139  if ( d_device->devType() == QInternal::Widget )
140  {
141  QWidget *w = (QWidget *)d_device;
144  d_painter->translate(-d_rect.x(), -d_rect.y());
145  }
146  else
147  {
149  }
150  }
151  else
152  {
153  if ( d_devicePainter )
155  else
156  {
157  d_painter = new QPainter(d_device);
158 
159  if ( d_device->devType() == QInternal::Widget )
160  {
161 #if QT_VERSION < 0x040000
162  QWidget *w = (QWidget *)d_device;
163  if ( w->testWFlags( Qt::WRepaintNoErase | Qt::WResizeNoErase) )
164 // #else
165 // if ( w->testWFlags( Qt::WNoAutoErase | Qt::WResizeNoErase) )
166 #endif
168  }
169  }
170  }
171 }
172 
177 {
178  if ( d_enabled && d_device != 0 && d_rect.isValid())
179  {
180  // We need a painter to find out if
181  // there is a painter redirection for d_device.
182 
183  QPainter *p;
184  if ( d_devicePainter == 0 )
185  p = new QPainter(d_device);
186  else
187  p = d_devicePainter;
188 
189  QPaintDevice *device = p->device();
190 #if QT_VERSION < 0x040000
191  if ( device->isExtDev() )
192 #else
193  QPaintEngine * pe = device -> paintEngine ();
194  QPaintEngine::Type type = pe-> type ();
195  if ( type != QPaintEngine::PostScript )
196 #endif
198  else
199  bitBlt(device, d_rect.topLeft(), &d_pixBuffer );
200 
201  if ( d_devicePainter == 0 )
202  delete p;
203  }
204 }
205 
210 {
211  flush();
212 
213  if ( d_painter )
214  {
215  if ( d_painter->isActive() )
216  d_painter->end();
217 
218  if ( d_painter != d_devicePainter )
219  delete d_painter;
220  }
221 
222  if ( !d_pixBuffer.isNull() )
223  d_pixBuffer = QPixmap();
224 
225  d_device = 0;
226  d_painter = 0;
227  d_devicePainter = 0;
228 }
229 
230 } // namespace hippodraw
231 

Generated for HippoDraw Class Library by doxygen