com.trolltech.qt.gui
Class QPicture

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.gui.QPicture
All Implemented Interfaces:
QPaintDeviceInterface, QtJambiInterface

public class QPicture
extends QtJambiObject
implements QPaintDeviceInterface

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:

            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

Note that the list of painter commands is reset on each call to the QPainter::begin() function.

Example of how to replay a picture:

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

Pictures can also be drawn using play. Some basic data about a picture is available, for example, size, isNull and boundingRect.

See Also:
QMovie

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QPicture()
          Equivalent to QPicture(-1).
QPicture(int formatVersion)
          Constructs an empty picture.
QPicture(QPicture arg__1)
          Constructs a copy of arg__1.
 
Method Summary
 QRect boundingRect()
          Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data.
 byte[] data()
          Returns the picture data.
 int depth()
          Returns the bit depth (number of bit planes) of the paint device.
 int devType()
          This function is reimplemented for internal reasons.
static QPicture fromNativePointer(QNativePointer nativePointer)
          This function returns the QPicture instance pointed to by nativePointer
 int height()
          Returns the height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).
 int heightMM()
          Returns the height of the paint device in millimeters.
 boolean isNull()
          Returns true if the picture contains no data; otherwise returns false.
 boolean load(QIODevice dev)
          This is an overloaded member function, provided for convenience.
 boolean load(java.lang.String fileName)
          Loads a picture from the file specified by fileName and returns true if successful; otherwise returns false.
 int logicalDpiX()
          Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes.
 int logicalDpiY()
          Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes.
 int metric(QPaintDevice.PaintDeviceMetric m)
          Internal implementation of the virtual QPaintDevice::metric() function.
static QNativePointer nativePointerArray(QPicture[] array)
          This function returns a QNativePointer that is pointing to the specified QPicture array.
 int numColors()
          Returns the number of different colors available for the paint device.
 QPaintEngine paintEngine()
          This function is reimplemented for internal reasons.
 boolean paintingActive()
          Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false.
 int physicalDpiX()
          Returns the horizontal resolution of the device in dots per inch.
 int physicalDpiY()
          Returns the horizontal resolution of the device in dots per inch.
 boolean play(QPainter p)
          Replays the picture using p, and returns true if successful; otherwise returns false.
 void readFrom(QDataStream arg__1)
          Reads a QPicture from arg__1.
 boolean save(QIODevice dev)
          This is an overloaded member function, provided for convenience.
 boolean save(java.lang.String fileName)
          Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false.
 void setBoundingRect(QRect r)
          Sets the picture's bounding rectangle to r.
 void setData(byte[] data)
          Equivalent to setData(data, ).
 int size()
          Returns the size of the picture data.
 int width()
          Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).
 int widthMM()
          Returns the width of the paint device in millimeters.
 void writeTo(QDataStream arg__1)
          Writes thisQPicture to arg__1.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QPicture

public QPicture()

Equivalent to QPicture(-1).


QPicture

public QPicture(int formatVersion)

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.


QPicture

public QPicture(QPicture arg__1)

Constructs a copy of arg__1.

This constructor is fast thanks to implicit sharing.

Method Detail

boundingRect

public final QRect boundingRect()

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

See Also:
setBoundingRect

depth

public final int depth()

Returns the bit depth (number of bit planes) of the paint device.

Specified by:
depth in interface QPaintDeviceInterface

height

public final int height()

Returns the height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).

Specified by:
height in interface QPaintDeviceInterface
See Also:
heightMM

heightMM

public final int heightMM()

Returns the height of the paint device in millimeters.

Specified by:
heightMM in interface QPaintDeviceInterface
See Also:
height

isNull

public final boolean isNull()

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


logicalDpiX

public final int logicalDpiX()

Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from widthMM, but it varies on Windows.

Note that if the logicalDpiX doesn't equal the physicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.

Specified by:
logicalDpiX in interface QPaintDeviceInterface
See Also:
logicalDpiY, physicalDpiX

logicalDpiY

public final int logicalDpiY()

Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from heightMM, but it varies on Windows.

Note that if the logicalDpiY doesn't equal the physicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.

Specified by:
logicalDpiY in interface QPaintDeviceInterface
See Also:
logicalDpiX, physicalDpiY

numColors

public final int numColors()

Returns the number of different colors available for the paint device. Since this value is an int, it will not be sufficient to represent the number of colors on 32 bit displays, in this case INT_MAX is returned instead.

Specified by:
numColors in interface QPaintDeviceInterface

writeTo

public final void writeTo(QDataStream arg__1)
Writes thisQPicture to arg__1.


readFrom

public final void readFrom(QDataStream arg__1)
Reads a QPicture from arg__1.


paintingActive

public final boolean paintingActive()

Returns true if the device is currently being painted on, i.e. someone has called QPainter::begin() but not yet called QPainter::end() for this device; otherwise returns false.

Specified by:
paintingActive in interface QPaintDeviceInterface
See Also:
QPainter::isActive

physicalDpiX

public final int physicalDpiX()

Returns the horizontal resolution of the device in dots per inch.

Note that if the physicalDpiX doesn't equal the logicalDpiX, the corresponding QPaintEngine must handle the resolution mapping.

Specified by:
physicalDpiX in interface QPaintDeviceInterface
See Also:
physicalDpiY, logicalDpiX

physicalDpiY

public final int physicalDpiY()

Returns the horizontal resolution of the device in dots per inch.

Note that if the physicalDpiY doesn't equal the logicalDpiY, the corresponding QPaintEngine must handle the resolution mapping.

Specified by:
physicalDpiY in interface QPaintDeviceInterface
See Also:
physicalDpiX, logicalDpiY

play

public final boolean play(QPainter p)

Replays the picture using p, and returns true if successful; otherwise returns false.

This function does exactly the same as QPainter::drawPicture() with (x, y) = (0, 0).


setBoundingRect

public final void setBoundingRect(QRect r)

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

See Also:
boundingRect

size

public final int size()

Returns the size of the picture data.

See Also:
data

width

public final int width()

Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget).

Specified by:
width in interface QPaintDeviceInterface
See Also:
widthMM

widthMM

public final int widthMM()

Returns the width of the paint device in millimeters.

Specified by:
widthMM in interface QPaintDeviceInterface
See Also:
width

devType

public int devType()

This function is reimplemented for internal reasons.

Specified by:
devType in interface QPaintDeviceInterface

metric

public int metric(QPaintDevice.PaintDeviceMetric m)

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.

Specified by:
metric in interface QPaintDeviceInterface
See Also:
PaintDeviceMetric

paintEngine

public QPaintEngine paintEngine()

This function is reimplemented for internal reasons.

Specified by:
paintEngine in interface QPaintDeviceInterface

setData

public void setData(byte[] data)

Equivalent to setData(data, ).


fromNativePointer

public static QPicture fromNativePointer(QNativePointer nativePointer)
This function returns the QPicture instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

nativePointerArray

public static QNativePointer nativePointerArray(QPicture[] array)
This function returns a QNativePointer that is pointing to the specified QPicture array.

Parameters:
array - the array that the returned pointer will point to.
Returns:
a QNativePointer that is pointing to the specified array.

load

public final boolean load(QIODevice dev)
This is an overloaded member function, provided for convenience. dev is the device used for loading.


load

public final boolean load(java.lang.String fileName)
Loads a picture from the file specified by fileName and returns true if successful; otherwise returns false.


save

public final boolean save(QIODevice dev)
This is an overloaded member function, provided for convenience.

dev is the device to use for saving.


save

public final boolean save(java.lang.String fileName)
Saves a picture to the file specified by fileName and returns true if successful; otherwise returns false.


data

public final byte[] data()
Returns the picture data.