Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
qt
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
42
QwtPaintBuffer::QwtPaintBuffer
():
43
d_device(0),
44
d_painter(0),
45
d_devicePainter(0)
46
{
47
}
48
59
QwtPaintBuffer::QwtPaintBuffer
(
QPaintDevice
*device,
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
72
QwtPaintBuffer::~QwtPaintBuffer
()
73
{
74
close
();
75
}
76
83
QPainter
*
QwtPaintBuffer::painter
()
84
{
85
return
d_painter
;
86
}
87
91
const
QPaintDevice
*
QwtPaintBuffer::device
()
92
{
93
return
d_device
;
94
}
95
101
void
QwtPaintBuffer::setEnabled
(
bool
enable)
102
{
103
d_enabled
= enable;
104
}
105
109
bool
QwtPaintBuffer::isEnabled
()
110
{
111
return
d_enabled
;
112
}
113
122
void
QwtPaintBuffer::open
(
QPaintDevice
*device,
123
const
QRect
&rect,
QPainter
*painter)
124
{
125
close
();
126
127
if
( device == 0 || !rect.
isValid
() )
128
return
;
129
130
d_device
=
device
;
131
d_devicePainter
=
painter
;
132
d_rect
= rect;
133
134
if
(
isEnabled
() )
135
{
136
d_pixBuffer
.
resize
(
d_rect
.
size
());
137
138
d_painter
=
new
QPainter
();
139
if
(
d_device
->devType() == QInternal::Widget )
140
{
141
QWidget
*w = (
QWidget
*)
d_device
;
142
d_pixBuffer
.
fill
(w,
d_rect
.
topLeft
());
143
d_painter
->
begin
(&
d_pixBuffer
, w);
144
d_painter
->
translate
(-
d_rect
.
x
(), -
d_rect
.
y
());
145
}
146
else
147
{
148
d_painter
->
begin
(&
d_pixBuffer
);
149
}
150
}
151
else
152
{
153
if
(
d_devicePainter
)
154
d_painter
=
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
167
d_painter
->
eraseRect
(
d_rect
);
168
}
169
}
170
}
171
}
172
176
void
QwtPaintBuffer::flush
()
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
197
d_devicePainter
->
drawPixmap
(
d_rect
.
topLeft
(),
d_pixBuffer
);
198
else
199
bitBlt(device,
d_rect
.
topLeft
(), &
d_pixBuffer
);
200
201
if
(
d_devicePainter
== 0 )
202
delete
p;
203
}
204
}
205
209
void
QwtPaintBuffer::close
()
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