CopperSpice API  1.9.1
QPicture Class Reference

The QPicture class is a paint device that records and replays QPainter commands. More...

Inheritance diagram for QPicture:
QPaintDevice

Public Methods

 QPicture (const QPicture &other)
 
 QPicture (int formatVersion=-1)
 
 ~QPicture ()
 
QRect boundingRect () const
 
const char * data () const
 
bool isNull () const
 
bool load (const QString &fileName, const QString &format=QString ())
 
bool load (QIODevice *dev, const QString &format=QString ())
 
QPicture & operator= (const QPicture &other)
 
QPicture & operator= (QPicture &&other)
 
QPaintEnginepaintEngine () const override
 
bool play (QPainter *painter)
 
bool save (const QString &fileName, const QString &format=QString ())
 
bool save (QIODevice *dev, const QString &format=QString ())
 
void setBoundingRect (const QRect &rect)
 
virtual void setData (const char *data, uint size)
 
uint size () const
 
void swap (QPicture &other)
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Static Public Methods

static QStringList inputFormatList ()
 
static QStringList inputFormats ()
 
static QStringList outputFormatList ()
 
static QStringList outputFormats ()
 
static QString pictureFormat (const QString &fileName)
 

Protected Methods

int metric (PaintDeviceMetric m) const override
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Friends

QDataStreamoperator<< (QDataStream &stream, const QPicture &picture)
 
QDataStreamoperator>> (QDataStream &stream, QPicture &picture)
 

Additional Inherited Members

- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Detailed Description

The QPicture class is a paint device which 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.

CopperSpice pictures use a proprietary binary format. Unlike native picture (meta file) formats on many window systems. 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, which means a QPicture can be displayed on different devices (for example svg, pdf, ps, printer and screen) looking the same. QPicture runs in the default system dpi, and scales the painter to match differences in resolution depending on the window system.

Examples

The following is an example of how to record a picture. The list of painter commands is reset on each call to the QPainter::begin().

QPicture picture;
QPainter painter;
painter.begin(&picture); // paint in picture
painter.drawEllipse(10,20, 80,70); // draw an ellipse
painter.end(); // painting done
picture.save("drawing.pic"); // save picture

The following is an 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().

QPicture picture;
picture.load("drawing.pic"); // load picture
QPainter painter;
painter.begin(&myImage); // paint in myImage
painter.drawPicture(0, 0, picture); // draw the picture at (0,0)
painter.end(); // painting done
See also
QMovie

Constructor & Destructor Documentation

QPicture::QPicture ( int  formatVersion = -1)
explicit

Constructs an empty QPicture.

The formatVersion parameter may be used to create a QPicture which can be read by applications compiled with earlier versions of CopperSpice. The default value is -1 which signifies the current release.

QPicture::QPicture ( const QPicture &  other)

Copy constructs a new :QPicture from other.

QPicture::~QPicture ( )

Destroys the QPicture.

Method Documentation

QRect QPicture::boundingRect ( ) const

Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.

See also
setBoundingRect()
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 QPicture. The returned pointer is a nullptr if the picture contains no data.

See also
setData(), size(), isNull()
QStringList QPicture::inputFormatList ( )
deprecatedstatic
Deprecated:
Returns a list of picture formats that are supported for picture input.

If you want to iterate over the list you should iterate over a copy.

for (const QString &string : list) {
myProcessing(string);
}
See also
outputFormatList(), inputFormats(), QPictureIO
QStringList QPicture::inputFormats ( )
deprecatedstatic
Deprecated:
Returns a list of picture formats that are supported for picture input.
See also
outputFormats(), inputFormatList(), QPictureIO
bool QPicture::isNull ( ) const

Returns true if the picture contains no data, otherwise returns false.

bool QPicture::load ( const QString fileName,
const QString format = QString() 
)

Loads a picture from the file specified by fileName and returns true if successful, otherwise returns false. The format parameter has been deprecated and will have no effect.

See also
save()
bool QPicture::load ( QIODevice dev,
const QString format = QString() 
)

The value for dev is the device to use for loading.

int QPicture::metric ( PaintDeviceMetric  metric) const
overrideprotectedvirtual

Returns the metric information for the given paint device metric.

See also
PaintDeviceMetric

Reimplemented from QPaintDevice::metric()

QPicture & QPicture::operator= ( const QPicture &  other)

Copy assigns from other and returns a reference to this object.

QPicture & QPicture::operator= ( QPicture &&  other)
inline

Move assigns from other and returns a reference to this object.

QStringList QPicture::outputFormatList ( )
deprecatedstatic
Deprecated:
Returns a list of picture formats that are supported for picture output.

If you want to iterate over the list, you should iterate over a copy.

for (const QString &string : list) {
myProcessing(string);
}
See also
inputFormatList(), outputFormats(), QPictureIO
QStringList QPicture::outputFormats ( )
deprecatedstatic
Deprecated:
Returns a list of picture formats that are supported for picture output.
See also
inputFormats(), outputFormatList(), QPictureIO
QPaintEngine* QPicture::paintEngine ( ) const
overridevirtual

Returns a pointer to the paint engine used for drawing on the device.

Implements QPaintDevice::paintEngine()

QString QPicture::pictureFormat ( const QString fileName)
deprecatedstatic
Deprecated:
Returns a string which specifies the picture format of the file fileName or an empty string if the file can not be read or if the format is not recognized.
See also
load(), save()
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).

bool QPicture::save ( const QString fileName,
const QString format = QString() 
)

Saves a picture to the file specified by fileName and returns true if successful, otherwise returns false. The format parameter has been deprecated and will have no effect.

See also
load()
bool QPicture::save ( QIODevice dev,
const QString format = QString() 
)

The value for dev is the device to use for saving.

void QPicture::setBoundingRect ( const QRect rect)

Sets the picture's bounding rectangle to rect. The automatically calculated value is overridden.

See also
boundingRect()
void QPicture::setData ( const char *  data,
uint  size 
)
virtual

Sets the picture data directly from data and size. This method copies the input data.

See also
data(), size()
uint QPicture::size ( ) const

Returns the size of the picture data.

See also
data()
void QPicture::swap ( QPicture &  other)
inline

Swaps other with this object. This operation is very fast and never fails.

Friends And Related Function Documentation

QDataStream & operator<< ( QDataStream stream,
const QPicture &  picture 
)
friend

Writes the given picture to the stream. Returns a reference to the stream.

QDataStream & operator>> ( QDataStream stream,
QPicture &  picture 
)
friend

Reads from the stream into the given picture. Returns a reference to the stream.