QPicturePaintEngine Class Reference

#include <qpaintengine_pic_p.h>

Inheritance diagram for QPicturePaintEngine:

Inheritance graph
[legend]
Collaboration diagram for QPicturePaintEngine:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 46 of file qpaintengine_pic_p.h.

Public Member Functions

 QPicturePaintEngine ()
 ~QPicturePaintEngine ()
bool begin (QPaintDevice *pdev)
bool end ()
void updateState (const QPaintEngineState &state)
void updatePen (const QPen &pen)
void updateBrush (const QBrush &brush, const QPointF &origin)
void updateFont (const QFont &font)
void updateBackground (Qt::BGMode bgmode, const QBrush &bgBrush)
void updateMatrix (const QMatrix &matrix)
void updateClipRegion (const QRegion &region, Qt::ClipOperation op)
void updateClipPath (const QPainterPath &path, Qt::ClipOperation op)
void updateRenderHints (QPainter::RenderHints hints)
void drawPath (const QPainterPath &path)
void drawPolygon (const QPointF *points, int numPoints, PolygonDrawMode mode)
void drawPixmap (const QRectF &r, const QPixmap &pm, const QRectF &sr)
void drawTiledPixmap (const QRectF &r, const QPixmap &pixmap, const QPointF &s)
void drawTextItem (const QPointF &p, const QTextItem &ti)
Type type () const

Protected Member Functions

 QPicturePaintEngine (QPaintEnginePrivate &dptr)

Private Member Functions

void writeCmdLength (int pos, const QRectF &r, bool corr)


Constructor & Destructor Documentation

QPicturePaintEngine::QPicturePaintEngine (  ) 

Definition at line 52 of file qpaintengine_pic.cpp.

References d.

00053     : QPaintEngine(*(new QPicturePaintEnginePrivate), AllFeatures)
00054 {
00055     Q_D(QPicturePaintEngine);
00056     d->pt = 0;
00057 }

QPicturePaintEngine::~QPicturePaintEngine (  ) 

Definition at line 66 of file qpaintengine_pic.cpp.

00067 {
00068 }

QPicturePaintEngine::QPicturePaintEngine ( QPaintEnginePrivate dptr  )  [protected]

Definition at line 59 of file qpaintengine_pic.cpp.

References d.

00060     : QPaintEngine(dptr, AllFeatures)
00061 {
00062     Q_D(QPicturePaintEngine);
00063     d->pt = 0;
00064 }


Member Function Documentation

bool QPicturePaintEngine::begin ( QPaintDevice pdev  )  [virtual]

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. Return true if the initialization was successful; otherwise return false.

See also:
end() isActive()

Implements QPaintEngine.

Definition at line 70 of file qpaintengine_pic.cpp.

References QPicture::boundingRect(), d, QRect::height(), QRect::left(), QPicturePrivate::PdcBegin, qDebug(), qt_mfhdr_tag, QPaintEngine::setActive(), QRect::top(), QIODevice::Truncate, QRect::width(), and QIODevice::WriteOnly.

00071 {
00072     Q_D(QPicturePaintEngine);
00073 #ifdef QT_PICTURE_DEBUG
00074     qDebug() << "QPicturePaintEngine::begin()";
00075 #endif
00076     Q_ASSERT(pd);
00077     QPicture *pic = static_cast<QPicture *>(pd);
00078 
00079     d->pdev = pd;
00080     d->pic_d = pic->d_func();
00081     Q_ASSERT(d->pic_d);
00082 
00083     d->s.setDevice(&d->pic_d->pictb);
00084     d->s.setVersion(d->pic_d->formatMajor);
00085 
00086     d->pic_d->pictb.open(QIODevice::WriteOnly | QIODevice::Truncate);
00087     d->s.writeRawData(qt_mfhdr_tag, 4);
00088     d->s << (quint16) 0 << (quint16) d->pic_d->formatMajor << (quint16) d->pic_d->formatMinor;
00089     d->s << (quint8) QPicturePrivate::PdcBegin << (quint8) sizeof(qint32);
00090     d->pic_d->brect = QRect();
00091     if (d->pic_d->formatMajor >= 4) {
00092         QRect r = pic->boundingRect();
00093         d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width()
00094              << (qint32) r.height();
00095     }
00096     d->pic_d->trecs = 0;
00097     d->s << (quint32)d->pic_d->trecs; // total number of records
00098     d->pic_d->formatOk = false;
00099     setActive(true);
00100     return true;
00101 }

Here is the call graph for this function:

bool QPicturePaintEngine::end (  )  [virtual]

Reimplement this function to finish painting on the current paint device. Return true if painting was finished successfully; otherwise return false.

See also:
begin() isActive()

Implements QPaintEngine.

Definition at line 103 of file qpaintengine_pic.cpp.

References buf, d, QRect::height(), QRect::left(), QPicturePrivate::PdcEnd, qChecksum(), qDebug(), QPaintEngine::setActive(), QRect::top(), and QRect::width().

00104 {
00105     Q_D(QPicturePaintEngine);
00106 #ifdef QT_PICTURE_DEBUG
00107     qDebug() << "QPicturePaintEngine::end()";
00108 #endif
00109     d->pic_d->trecs++;
00110     d->s << (quint8) QPicturePrivate::PdcEnd << (quint8) 0;
00111     int cs_start = sizeof(quint32);                // pos of checksum word
00112     int data_start = cs_start + sizeof(quint16);
00113     int brect_start = data_start + 2*sizeof(qint16) + 2*sizeof(quint8);
00114     int pos = d->pic_d->pictb.pos();
00115     d->pic_d->pictb.seek(brect_start);
00116     if (d->pic_d->formatMajor >= 4) { // bounding rectangle
00117         QRect r = static_cast<QPicture *>(d->pdev)->boundingRect();
00118         d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width()
00119              << (qint32) r.height();
00120     }
00121     d->s << (quint32) d->pic_d->trecs;                        // write number of records
00122     d->pic_d->pictb.seek(cs_start);
00123     QByteArray buf = d->pic_d->pictb.buffer();
00124     quint16 cs = (quint16) qChecksum(buf.constData() + data_start, pos - data_start);
00125     d->s << cs;                                // write checksum
00126     d->pic_d->pictb.close();
00127     setActive(false);
00128     return true;
00129 }

Here is the call graph for this function:

void QPicturePaintEngine::updateState ( const QPaintEngineState state  )  [virtual]

Reimplement this function to update the state of a paint engine.

When implemented, this function is responsible for checking the paint engine's current state and update the properties that are changed. Use the QPaintEngineState::state() function to find out which properties that must be updated, then use the corresponding {GetFunction}{get function} to retrieve the current values for the given properties.

See also:
QPaintEngineState

Implements QPaintEngine.

Definition at line 380 of file qpaintengine_pic.cpp.

References QPaintEngineState::backgroundBrush(), QPaintEngineState::backgroundMode(), QPaintEngineState::brush(), QPaintEngineState::brushOrigin(), QPaintEngineState::clipOperation(), QPaintEngineState::clipPath(), QPaintEngineState::clipRegion(), QPaintEngine::DirtyBackground, QPaintEngine::DirtyBrush, QPaintEngine::DirtyClipPath, QPaintEngine::DirtyClipRegion, QPaintEngine::DirtyFont, QPaintEngine::DirtyHints, QPaintEngine::DirtyPen, QPaintEngine::DirtyTransform, flags, QPaintEngineState::font(), QPaintEngineState::matrix(), QPaintEngineState::pen(), QPaintEngineState::renderHints(), QPaintEngineState::state(), QPaintEngine::state, updateBackground(), updateBrush(), updateClipPath(), updateClipRegion(), updateFont(), updateMatrix(), updatePen(), and updateRenderHints().

00381 {
00382     QPaintEngine::DirtyFlags flags = state.state();
00383     if (flags & DirtyPen) updatePen(state.pen());
00384     if (flags & DirtyBrush) updateBrush(state.brush(), state.brushOrigin());
00385     if (flags & DirtyBackground) updateBackground(state.backgroundMode(), state.backgroundBrush());
00386     if (flags & DirtyFont) updateFont(state.font());
00387     if (flags & DirtyTransform) updateMatrix(state.matrix());
00388     if (flags & DirtyClipPath) updateClipPath(state.clipPath(), state.clipOperation());
00389     if (flags & DirtyClipRegion) updateClipRegion(state.clipRegion(), state.clipOperation());
00390     if (flags & DirtyHints) updateRenderHints(state.renderHints());
00391 }

Here is the call graph for this function:

void QPicturePaintEngine::updatePen ( const QPen pen  ) 

Definition at line 137 of file qpaintengine_pic.cpp.

References QPen::color(), d, QPicturePrivate::PdcSetPen, qDebug(), SERIALIZE_CMD, QPen::style(), QPen::width(), and writeCmdLength().

Referenced by updateState().

00138 {
00139     Q_D(QPicturePaintEngine);
00140 #ifdef QT_PICTURE_DEBUG
00141     qDebug() << " -> updatePen(): width:" << pen.width() << "style:"
00142              << pen.style() << "color:" << pen.color();
00143 #endif
00144     int pos;
00145     SERIALIZE_CMD(QPicturePrivate::PdcSetPen);
00146     d->s << pen;
00147     writeCmdLength(pos, QRect(), false);
00148 }

Here is the call graph for this function:

void QPicturePaintEngine::updateBrush ( const QBrush brush,
const QPointF origin 
)

Definition at line 150 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcSetBrush, qDebug(), SERIALIZE_CMD, QBrush::style(), and writeCmdLength().

Referenced by updateState().

00151 {
00152     Q_D(QPicturePaintEngine);
00153 #ifdef QT_PICTURE_DEBUG
00154     qDebug() << " -> updateBrush(): style:" << brush.style();
00155 #endif
00156     int pos;
00157     SERIALIZE_CMD(QPicturePrivate::PdcSetBrush);
00158     d->s << brush;
00159     writeCmdLength(pos, QRect(), false);
00160 }

Here is the call graph for this function:

void QPicturePaintEngine::updateFont ( const QFont font  ) 

Definition at line 162 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcSetFont, QFont::pointSize(), qDebug(), SERIALIZE_CMD, and writeCmdLength().

Referenced by updateState().

00163 {
00164     Q_D(QPicturePaintEngine);
00165 #ifdef QT_PICTURE_DEBUG
00166     qDebug() << " -> updateFont(): pt sz:" << font.pointSize();
00167 #endif
00168     int pos;
00169     SERIALIZE_CMD(QPicturePrivate::PdcSetFont);
00170     QFont fnt = font;
00171     d->s << fnt;
00172     writeCmdLength(pos, QRectF(), false);
00173 }

Here is the call graph for this function:

void QPicturePaintEngine::updateBackground ( Qt::BGMode  bgmode,
const QBrush bgBrush 
)

Definition at line 175 of file qpaintengine_pic.cpp.

References QBrush::color(), d, QPicturePrivate::PdcSetBkColor, QPicturePrivate::PdcSetBkMode, qDebug(), SERIALIZE_CMD, QBrush::style(), and writeCmdLength().

Referenced by updateState().

00176 {
00177     Q_D(QPicturePaintEngine);
00178 #ifdef QT_PICTURE_DEBUG
00179     qDebug() << " -> updateBackground(): mode:" << bgMode << "style:" << bgBrush.style();
00180 #endif
00181     int pos;
00182     SERIALIZE_CMD(QPicturePrivate::PdcSetBkColor);
00183     d->s << bgBrush.color();
00184     writeCmdLength(pos, QRect(), false);
00185 
00186     SERIALIZE_CMD(QPicturePrivate::PdcSetBkMode);
00187     d->s << (qint8) bgMode;
00188     writeCmdLength(pos, QRectF(), false);
00189 }

Here is the call graph for this function:

void QPicturePaintEngine::updateMatrix ( const QMatrix matrix  ) 

Definition at line 191 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcSetWMatrix, qDebug(), SERIALIZE_CMD, and writeCmdLength().

Referenced by updateState().

00192 {
00193     Q_D(QPicturePaintEngine);
00194 #ifdef QT_PICTURE_DEBUG
00195     qDebug() << " -> updateMatrix():" << matrix;
00196 #endif
00197     int pos;
00198     SERIALIZE_CMD(QPicturePrivate::PdcSetWMatrix);
00199     d->s << matrix << (qint8) false;
00200     writeCmdLength(pos, QRectF(), false);
00201 }

Here is the call graph for this function:

void QPicturePaintEngine::updateClipRegion ( const QRegion region,
Qt::ClipOperation  op 
)

Definition at line 203 of file qpaintengine_pic.cpp.

References QRegion::boundingRect(), d, QRegion::isEmpty(), QPicturePrivate::PdcSetClip, QPicturePrivate::PdcSetClipRegion, qDebug(), SERIALIZE_CMD, and writeCmdLength().

Referenced by updateState().

00204 {
00205     Q_D(QPicturePaintEngine);
00206 #ifdef QT_PICTURE_DEBUG
00207     qDebug() << " -> updateClipRegion(): op:" << op
00208              << "bounding rect:" << region.boundingRect();
00209 #endif
00210     Q_UNUSED(op);
00211     int pos;
00212     SERIALIZE_CMD(QPicturePrivate::PdcSetClipRegion);
00213     d->s << region << qint8(0);
00214     writeCmdLength(pos, QRectF(), false);
00215 
00216     SERIALIZE_CMD(QPicturePrivate::PdcSetClip);
00217     d->s << (qint8) !region.isEmpty();
00218     writeCmdLength(pos, QRectF(), false);
00219 }

Here is the call graph for this function:

void QPicturePaintEngine::updateClipPath ( const QPainterPath path,
Qt::ClipOperation  op 
)

Definition at line 221 of file qpaintengine_pic.cpp.

References d, path, QPicturePrivate::PdcSetClipPath, qDebug(), SERIALIZE_CMD, and writeCmdLength().

Referenced by updateState().

00222 {
00223     Q_D(QPicturePaintEngine);
00224 #ifdef QT_PICTURE_DEBUG
00225     qDebug() << " -> updateClipPath(): op:" << op
00226              << "bounding rect:" << path.boundingRect();
00227 #endif
00228     Q_UNUSED(op);
00229     int pos;
00230 
00231     SERIALIZE_CMD(QPicturePrivate::PdcSetClipPath);
00232     d->s << path << (qint8) op;
00233     writeCmdLength(pos, QRectF(), false);
00234 }

Here is the call graph for this function:

void QPicturePaintEngine::updateRenderHints ( QPainter::RenderHints  hints  ) 

Definition at line 236 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcSetRenderHint, qDebug(), SERIALIZE_CMD, and writeCmdLength().

Referenced by updateState().

00237 {
00238     Q_D(QPicturePaintEngine);
00239 #ifdef QT_PICTURE_DEBUG
00240     qDebug() << " -> updateRenderHints(): " << hints;
00241 #endif
00242     int pos;
00243     SERIALIZE_CMD(QPicturePrivate::PdcSetRenderHint);
00244     d->s << (quint32) hints;
00245     writeCmdLength(pos, QRect(), false);
00246 }

Here is the call graph for this function:

void QPicturePaintEngine::drawPath ( const QPainterPath path  )  [virtual]

The default implementation ignores the path and does nothing.

Reimplemented from QPaintEngine.

Definition at line 300 of file qpaintengine_pic.cpp.

References d, path, QPicturePrivate::PdcDrawPath, qDebug(), SERIALIZE_CMD, and writeCmdLength().

00301 {
00302     Q_D(QPicturePaintEngine);
00303 #ifdef QT_PICTURE_DEBUG
00304     qDebug() << " -> drawPath():" << path.boundingRect();
00305 #endif
00306     int pos;
00307     SERIALIZE_CMD(QPicturePrivate::PdcDrawPath);
00308     d->s << path;
00309     writeCmdLength(pos, path.boundingRect(), true);
00310 }

Here is the call graph for this function:

void QPicturePaintEngine::drawPolygon ( const QPointF points,
int  numPoints,
PolygonDrawMode  mode 
) [virtual]

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

The default implementation of this function will try to use drawPath if the engine supports the feature QPaintEngine::PainterPaths or try the float based drawPolygon() implementation if not.

Reimplemented from QPaintEngine.

Definition at line 312 of file qpaintengine_pic.cpp.

References QPolygonF::boundingRect(), d, i, QPaintEngine::OddEvenMode, QPicturePrivate::PdcDrawPolygon, QPicturePrivate::PdcDrawPolyline, QPaintEngine::PolylineMode, qDebug(), SERIALIZE_CMD, and writeCmdLength().

00313 {
00314     Q_D(QPicturePaintEngine);
00315 #ifdef QT_PICTURE_DEBUG
00316     qDebug() << " -> drawPolygon(): size=" << numPoints;
00317 #endif
00318     int pos;
00319 
00320     QPolygonF polygon;
00321     for (int i=0; i<numPoints; ++i)
00322         polygon << points[i];
00323 
00324     if (mode == PolylineMode) {
00325         SERIALIZE_CMD(QPicturePrivate::PdcDrawPolyline);
00326         d->s << polygon;
00327     } else {
00328         SERIALIZE_CMD(QPicturePrivate::PdcDrawPolygon);
00329         d->s << polygon;
00330         d->s << (qint8)(mode == OddEvenMode ? 0 : 1);
00331     }
00332 
00333     writeCmdLength(pos, polygon.boundingRect(), true);
00334 }

Here is the call graph for this function:

void QPicturePaintEngine::drawPixmap ( const QRectF r,
const QPixmap pm,
const QRectF sr 
) [virtual]

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r.

Implements QPaintEngine.

Definition at line 336 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcDrawPixmap, qDebug(), SERIALIZE_CMD, and writeCmdLength().

00337 {
00338     Q_D(QPicturePaintEngine);
00339 #ifdef QT_PICTURE_DEBUG
00340     qDebug() << " -> drawPixmap():" << r;
00341 #endif
00342     int pos;
00343     SERIALIZE_CMD(QPicturePrivate::PdcDrawPixmap);
00344     d->s << r << pm << sr;
00345     writeCmdLength(pos, r, false);
00346 }

Here is the call graph for this function:

void QPicturePaintEngine::drawTiledPixmap ( const QRectF r,
const QPixmap pixmap,
const QPointF s 
) [virtual]

Reimplement this function to draw the pixmap in the given rect, starting at the given p. The pixmap will be drawn repeatedly until the rect is filled.

Reimplemented from QPaintEngine.

Definition at line 348 of file qpaintengine_pic.cpp.

References d, QPicturePrivate::PdcDrawTiledPixmap, qDebug(), s, SERIALIZE_CMD, and writeCmdLength().

00349 {
00350     Q_D(QPicturePaintEngine);
00351 #ifdef QT_PICTURE_DEBUG
00352     qDebug() << " -> drawTiledPixmap():" << r << s;
00353 #endif
00354     int pos;
00355     SERIALIZE_CMD(QPicturePrivate::PdcDrawTiledPixmap);
00356     d->s << r << pixmap << s;
00357     writeCmdLength(pos, r, false);
00358 }

Here is the call graph for this function:

void QPicturePaintEngine::drawTextItem ( const QPointF p,
const QTextItem ti 
) [virtual]

This function draws the text item textItem at position p. The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

Reimplemented from QPaintEngine.

Definition at line 360 of file qpaintengine_pic.cpp.

References QTextItem::ascent(), d, QTextItem::font(), p, QPicturePrivate::PdcDrawText2, QPicturePrivate::PdcDrawTextItem, qDebug(), QTextItem::renderFlags(), SERIALIZE_CMD, QTextItem::text(), and writeCmdLength().

00361 {
00362     Q_D(QPicturePaintEngine);
00363 #ifdef QT_PICTURE_DEBUG
00364     qDebug() << " -> drawTextItem():" << p << ti.text();
00365 #endif
00366     if (d->pic_d->formatMajor >= 8) {
00367         int pos;
00368         SERIALIZE_CMD(QPicturePrivate::PdcDrawTextItem);
00369         d->s << QPointF(p.x(), p.y() - ti.ascent()) << ti.text() << ti.font() << ti.renderFlags();
00370         writeCmdLength(pos, /*brect=*/QRectF(), /*corr=*/false);
00371     } else {
00372         // old (buggy) format
00373         int pos;
00374         SERIALIZE_CMD(QPicturePrivate::PdcDrawText2);
00375         d->s << p << ti.text();
00376         writeCmdLength(pos, QRectF(p, QSizeF(1,1)), true);
00377     }
00378 }

Here is the call graph for this function:

Type QPicturePaintEngine::type (  )  const [inline, virtual]

Reimplement this function to return the paint engine {Type}.

Implements QPaintEngine.

Definition at line 80 of file qpaintengine_pic_p.h.

References QPaintEngine::Picture.

00080 { return Picture; }

void QPicturePaintEngine::writeCmdLength ( int  pos,
const QRectF r,
bool  corr 
) [private]

Definition at line 248 of file qpaintengine_pic.cpp.

References QRectF::bottom(), QRegion::boundingRect(), ceil, QPainter::clipRegion(), d, QRectF::height(), int, QRectF::left(), length, QMatrix::mapRect(), QPainter::matrix(), p, QPaintEngine::painter(), QPainter::pen(), qMax(), qMin(), QRectF::right(), QRectF::setCoords(), QRectF::top(), QPen::width(), and QRectF::width().

Referenced by drawPath(), drawPixmap(), drawPolygon(), drawTextItem(), drawTiledPixmap(), updateBackground(), updateBrush(), updateClipPath(), updateClipRegion(), updateFont(), updateMatrix(), updatePen(), and updateRenderHints().

00249 {
00250     Q_D(QPicturePaintEngine);
00251     int newpos = d->pic_d->pictb.pos();            // new position
00252     int length = newpos - pos;
00253     QRectF br(r);
00254 
00255     if (length < 255) {                         // write 8-bit length
00256         d->pic_d->pictb.seek(pos - 1);             // position to right index
00257         d->s << (quint8)length;
00258     } else {                                    // write 32-bit length
00259         d->s << (quint32)0;                    // extend the buffer
00260         d->pic_d->pictb.seek(pos - 1);             // position to right index
00261         d->s << (quint8)255;                   // indicate 32-bit length
00262         char *p = d->pic_d->pictb.buffer().data();
00263         memmove(p+pos+4, p+pos, length);        // make room for 4 byte
00264         d->s << (quint32)length;
00265         newpos += 4;
00266     }
00267     d->pic_d->pictb.seek(newpos);                  // set to new position
00268 
00269     if (br.width() > 0.0 || br.height() > 0.0) {
00270         if (corr) {                             // widen bounding rect
00271             int w2 = painter()->pen().width() / 2;
00272             br.setCoords(br.left() - w2, br.top() - w2,
00273                         br.right() + w2, br.bottom() + w2);
00274         }
00275         br = painter()->matrix().mapRect(br);
00276         if (painter()->hasClipping()) {
00277             QRect cr = painter()->clipRegion().boundingRect();
00278             br &= cr;
00279         }
00280 
00281         if (br.width() > 0.0 || br.height() > 0.0) {
00282             int minx = int(floor(br.left()));
00283             int miny = int(floor(br.top()));
00284             int maxx = int(ceil(br.right()));
00285             int maxy = int(ceil(br.bottom()));
00286 
00287             if (d->pic_d->brect.width() > 0 || d->pic_d->brect.height() > 0) {
00288                 minx = qMin(minx, d->pic_d->brect.left());
00289                 miny = qMin(miny, d->pic_d->brect.top());
00290                 maxx = qMax(maxx, d->pic_d->brect.x() + d->pic_d->brect.width());
00291                 maxy = qMax(maxy, d->pic_d->brect.y() + d->pic_d->brect.height());
00292                 d->pic_d->brect = QRect(minx, miny, maxx - minx, maxy - miny);
00293             } else {
00294                 d->pic_d->brect = QRect(minx, miny, maxx - minx, maxy - miny);
00295             }
00296         }
00297     }
00298 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:39:42 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1