Qt 4.8
|
The QPicture class is a paint device that records and replays QPainter commands. More...
#include <qpicture.h>
Public Types | |
typedef QExplicitlySharedDataPointer< QPicturePrivate > | DataPtr |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric { PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM, PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY, PdmPhysicalDpiX, PdmPhysicalDpiY } |
Public Functions | |
QRect | boundingRect () const |
Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data. More... | |
const char * | data () const |
Returns a pointer to the picture data. More... | |
DataPtr & | data_ptr () |
void | detach () |
Detaches from shared picture data and makes sure that this picture is the only one referring to the data. More... | |
int | devType () const |
bool | isDetached () const |
bool | isNull () const |
Returns true if the picture contains no data; otherwise returns false. More... | |
bool | load (QIODevice *dev, const char *format=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for loading. More... | |
bool | load (const QString &fileName, const char *format=0) |
Loads a picture from the file specified by fileName and returns true if successful; otherwise returns false. More... | |
QPicture & | operator= (const QPicture &p) |
Assigns picture p to this picture and returns a reference to this picture. More... | |
QPaintEngine * | paintEngine () const |
bool | play (QPainter *p) |
Replays the picture using painter, and returns true if successful; otherwise returns false. More... | |
QPicture (int formatVersion=-1) | |
Constructs an empty picture. More... | |
QPicture (const QPicture &) | |
Constructs a copy of pic. More... | |
bool | save (QIODevice *dev, const char *format=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for saving. More... | |
bool | save (const QString &fileName, const char *format=0) |
Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false. More... | |
void | setBoundingRect (const QRect &r) |
Sets the picture's bounding rectangle to r. More... | |
virtual void | setData (const char *data, uint size) |
Sets the picture data directly from data and size. More... | |
uint | size () const |
Returns the size of the picture data. More... | |
void | swap (QPicture &other) |
Swaps picture other with this picture. More... | |
~QPicture () | |
Destroys the picture. More... | |
Public Functions inherited from QPaintDevice | |
int | colorCount () const |
int | depth () const |
virtual HDC | getDC () const |
int | height () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
QT_DEPRECATED int | numColors () const |
bool | paintingActive () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
virtual void | releaseDC (HDC hdc) const |
int | width () const |
int | widthMM () const |
virtual | ~QPaintDevice () |
Static Public Functions | |
static QStringList | inputFormatList () |
Returns a list of picture formats that are supported for picture input. More... | |
static QList< QByteArray > | inputFormats () |
Returns a list of picture formats that are supported for picture input. More... | |
static QStringList | outputFormatList () |
Returns a list of picture formats that are supported for picture output. More... | |
static QList< QByteArray > | outputFormats () |
Returns a list of picture formats that are supported for picture output. More... | |
static const char * | pictureFormat (const QString &fileName) |
Returns a string that specifies the picture format of the file fileName, or 0 if the file cannot be read or if the format is not recognized. More... | |
Static Public Functions inherited from QPaintDevice | |
static QWSDisplay * | qwsDisplay () |
Protected Functions | |
int | metric (PaintDeviceMetric m) const |
Internal implementation of the virtual QPaintDevice::metric() function. More... | |
QPicture (QPicturePrivate &data) | |
Protected Functions inherited from QPaintDevice | |
QPaintDevice () | |
Private Functions | |
void | detach_helper () |
bool | exec (QPainter *p, QDataStream &ds, int i) |
Iterates over the internal picture data and draws the picture using painter. More... | |
Properties | |
QExplicitlySharedDataPointer< QPicturePrivate > | d_ptr |
Friends | |
Q_GUI_EXPORT QDataStream & | operator<< (QDataStream &in, const QPicture &p) |
Writes picture r to the stream s and returns a reference to the stream. More... | |
Q_GUI_EXPORT QDataStream & | operator>> (QDataStream &in, QPicture &p) |
Reads a picture from the stream s into picture r and returns a reference to the stream. More... | |
class | Q3Picture |
class | QAlphaPaintEngine |
class | QPicturePaintEngine |
class | QPreviewPaintEngine |
Additional Inherited Members | |
Protected Variables inherited from QPaintDevice | |
ushort | painters |
Related Functions inherited from QPaintDevice | |
const Q_GUI_EXPORT QX11Info * | qt_x11Info (const QPaintDevice *pd) |
Returns the QX11Info structure for the pd paint device. More... | |
The QPicture class is a paint device that records and replays QPainter commands.
A picture serializes painter commands to an IO device in a platform-independent format. They are sometimes referred to as meta-files.
Qt pictures use a proprietary binary format. Unlike native picture (meta-file) formats on many window systems, Qt pictures have no limitations regarding their contents. Everything that can be painted on a widget or pixmap (e.g., fonts, pixmaps, regions, transformed graphics, etc.) can also be stored in a picture.
QPicture is resolution independent, i.e. a QPicture can be displayed on different devices (for example svg, pdf, ps, printer and screen) looking the same. This is, for instance, needed for WYSIWYG print preview. QPicture runs in the default system dpi, and scales the painter to match differences in resolution depending on the window system.
Example of how to record a picture:
Note that the list of painter commands is reset on each call to the QPainter::begin() function.
Example of how to replay a picture:
Pictures can also be drawn using play(). Some basic data about a picture is available, for example, size(), isNull() and boundingRect().
Definition at line 58 of file qpicture.h.
Definition at line 122 of file qpicture.h.
|
explicit |
Constructs an empty picture.
The formatVersion parameter may be used to create a QPicture that can be read by applications that are compiled with earlier versions of Qt.
Note that the default formatVersion is -1 which signifies the current release, i.e. for Qt 4.0 a formatVersion of 7 is the same as the default formatVersion of -1.
Reading pictures generated by earlier versions of Qt is not supported in Qt 4.0.
Definition at line 131 of file qpicture.cpp.
QPicture::QPicture | ( | const QPicture & | pic | ) |
Constructs a copy of pic.
This constructor is fast thanks to implicit sharing.
Definition at line 156 of file qpicture.cpp.
QPicture::~QPicture | ( | ) |
|
protected |
Definition at line 162 of file qpicture.cpp.
QRect QPicture::boundingRect | ( | ) | const |
Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.
Definition at line 385 of file qpicture.cpp.
Referenced by QPicturePaintEngine::begin(), metric(), and QLabelPrivate::sizeForWidth().
const char * QPicture::data | ( | ) | const |
Returns a pointer to the picture data.
The pointer is only valid until the next non-const function is called on this picture. The returned pointer is 0 if the picture contains no data.
Definition at line 225 of file qpicture.cpp.
|
inline |
Definition at line 123 of file qpicture.h.
void QPicture::detach | ( | ) |
Detaches from shared picture data and makes sure that this picture is the only one referring to the data.
If multiple pictures share common data, this picture makes a copy of the data and detaches itself from the sharing mechanism. Nothing is done if there is just a single reference.
Definition at line 230 of file qpicture.cpp.
Referenced by load(), setData(), and swap().
|
private |
Definition at line 1031 of file qpicture.cpp.
|
virtual |
Reimplemented from QPaintDevice.
Definition at line 178 of file qpicture.cpp.
|
private |
Iterates over the internal picture data and draws the picture using painter.
Definition at line 490 of file qpicture.cpp.
Referenced by play().
|
static |
Returns a list of picture formats that are supported for picture input.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
Definition at line 1314 of file qpicture.cpp.
|
static |
Returns a list of picture formats that are supported for picture input.
Definition at line 1286 of file qpicture.cpp.
bool QPicture::isDetached | ( | ) | const |
Definition at line 235 of file qpicture.cpp.
bool QPicture::isNull | ( | ) | const |
Returns true if the picture contains no data; otherwise returns false.
Definition at line 215 of file qpicture.cpp.
Referenced by QLabelPrivate::sizeForWidth().
bool QPicture::load | ( | QIODevice * | dev, |
const char * | format = 0 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for loading.
Definition at line 279 of file qpicture.cpp.
Referenced by load().
bool QPicture::load | ( | const QString & | fileName, |
const char * | format = 0 |
||
) |
Loads a picture from the file specified by fileName and returns true if successful; otherwise returns false.
Please note that the format parameter has been deprecated and will have no effect.
Definition at line 265 of file qpicture.cpp.
|
protectedvirtual |
Internal implementation of the virtual QPaintDevice::metric() function.
A picture has the following hard-coded values: numcolors=16777216 and depth=24.
m is the metric to get.
Reimplemented from QPaintDevice.
Definition at line 972 of file qpicture.cpp.
Assigns picture p to this picture and returns a reference to this picture.
Definition at line 1043 of file qpicture.cpp.
Referenced by load(), and save().
|
static |
Returns a list of picture formats that are supported for picture output.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
Definition at line 1335 of file qpicture.cpp.
|
static |
Returns a list of picture formats that are supported for picture output.
Definition at line 1351 of file qpicture.cpp.
|
virtual |
Implements QPaintDevice.
Definition at line 1183 of file qpicture.cpp.
Referenced by paintEngine().
|
static |
Returns a string that specifies the picture format of the file fileName, or 0 if the file cannot be read or if the format is not recognized.
Definition at line 1270 of file qpicture.cpp.
bool QPicture::play | ( | QPainter * | painter | ) |
Replays the picture using painter, and returns true if successful; otherwise returns false.
This function does exactly the same as QPainter::drawPicture() with (x, y) = (0, 0).
Definition at line 416 of file qpicture.cpp.
bool QPicture::save | ( | QIODevice * | dev, |
const char * | format = 0 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.dev is the device to use for saving.
Definition at line 352 of file qpicture.cpp.
Referenced by save().
bool QPicture::save | ( | const QString & | fileName, |
const char * | format = 0 |
||
) |
Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false.
Please note that the format parameter has been deprecated and will have no effect.
Definition at line 315 of file qpicture.cpp.
void QPicture::setBoundingRect | ( | const QRect & | r | ) |
Sets the picture's bounding rectangle to r.
The automatically calculated value is overridden.
Definition at line 403 of file qpicture.cpp.
|
virtual |
Sets the picture data directly from data and size.
This function copies the input data.
Definition at line 247 of file qpicture.cpp.
uint QPicture::size | ( | ) | const |
Returns the size of the picture data.
Definition at line 220 of file qpicture.cpp.
Referenced by exec().
|
inline |
Swaps picture other with this picture.
This operation is very fast and never fails.
Definition at line 88 of file qpicture.h.
|
friend |
Writes picture r to the stream s and returns a reference to the stream.
Definition at line 1205 of file qpicture.cpp.
|
friend |
Reads a picture from the stream s into picture r and returns a reference to the stream.
Definition at line 1227 of file qpicture.cpp.
|
friend |
Definition at line 117 of file qpicture.h.
|
friend |
Definition at line 118 of file qpicture.h.
|
friend |
Definition at line 116 of file qpicture.h.
|
friend |
Definition at line 119 of file qpicture.h.
|
private |
Definition at line 115 of file qpicture.h.
Referenced by boundingRect(), detach(), operator=(), and swap().