You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/man/man3/tqcanvasitem.3qt

427 lines
18 KiB

'\" t
.TH TQCanvasItem 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQCanvasItem \- Abstract graphic object on a TQCanvas
.SH SYNOPSIS
\fC#include <tqcanvas.h>\fR
.PP
Inherits Qt.
.PP
Inherited by TQCanvasSprite, TQCanvasPolygonalItem, and TQCanvasText.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQCanvasItem\fR ( TQCanvas * canvas )"
.br
.ti -1c
.BI "virtual \fB~TQCanvasItem\fR ()"
.br
.ti -1c
.BI "double \fBx\fR () const"
.br
.ti -1c
.BI "double \fBy\fR () const"
.br
.ti -1c
.BI "double \fBz\fR () const"
.br
.ti -1c
.BI "virtual void \fBmoveBy\fR ( double dx, double dy )"
.br
.ti -1c
.BI "void \fBmove\fR ( double x, double y )"
.br
.ti -1c
.BI "void \fBsetX\fR ( double x )"
.br
.ti -1c
.BI "void \fBsetY\fR ( double y )"
.br
.ti -1c
.BI "void \fBsetZ\fR ( double z )"
.br
.ti -1c
.BI "bool \fBanimated\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetAnimated\fR ( bool y )"
.br
.ti -1c
.BI "virtual void \fBsetVelocity\fR ( double vx, double vy )"
.br
.ti -1c
.BI "void \fBsetXVelocity\fR ( double vx )"
.br
.ti -1c
.BI "void \fBsetYVelocity\fR ( double vy )"
.br
.ti -1c
.BI "double \fBxVelocity\fR () const"
.br
.ti -1c
.BI "double \fByVelocity\fR () const"
.br
.ti -1c
.BI "virtual void \fBadvance\fR ( int phase )"
.br
.ti -1c
.BI "virtual bool \fBcollidesWith\fR ( const TQCanvasItem * other ) const = 0"
.br
.ti -1c
.BI "TQCanvasItemList \fBcollisions\fR ( bool exact ) const"
.br
.ti -1c
.BI "virtual void \fBsetCanvas\fR ( TQCanvas * c )"
.br
.ti -1c
.BI "virtual void \fBdraw\fR ( TQPainter & painter ) = 0"
.br
.ti -1c
.BI "void \fBshow\fR ()"
.br
.ti -1c
.BI "void \fBhide\fR ()"
.br
.ti -1c
.BI "virtual void \fBsetVisible\fR ( bool yes )"
.br
.ti -1c
.BI "bool \fBisVisible\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetSelected\fR ( bool yes )"
.br
.ti -1c
.BI "bool \fBisSelected\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetEnabled\fR ( bool yes )"
.br
.ti -1c
.BI "bool \fBisEnabled\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetActive\fR ( bool yes )"
.br
.ti -1c
.BI "bool \fBisActive\fR () const"
.br
.ti -1c
.BI "bool visible () const \fI(obsolete)\fR"
.br
.ti -1c
.BI "bool selected () const \fI(obsolete)\fR"
.br
.ti -1c
.BI "bool enabled () const \fI(obsolete)\fR"
.br
.ti -1c
.BI "bool active () const \fI(obsolete)\fR"
.br
.ti -1c
.BI "enum \fBRttiValues\fR { Rtti_Item = 0, Rtti_Sprite = 1, Rtti_PolygonalItem = 2, Rtti_Text = 3, Rtti_Polygon = 4, Rtti_Rectangle = 5, Rtti_Ellipse = 6, Rtti_Line = 7, Rtti_Spline = 8 }"
.br
.ti -1c
.BI "virtual int \fBrtti\fR () const"
.br
.ti -1c
.BI "virtual TQRect \fBboundingRect\fR () const = 0"
.br
.ti -1c
.BI "virtual TQRect \fBboundingRectAdvanced\fR () const"
.br
.ti -1c
.BI "TQCanvas * \fBcanvas\fR () const"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "void \fBupdate\fR ()"
.br
.in -1c
.SH DESCRIPTION
The TQCanvasItem class provides an abstract graphic object on a TQCanvas.
.PP
A variety of TQCanvasItem subclasses provide immediately usable behaviour. This class is a pure abstract superclass providing the behaviour that is shared among all the concrete canvas item classes. TQCanvasItem is not intended for direct subclassing. It is much easier to subclass one of its subclasses, e.g. TQCanvasPolygonalItem (the commonest base class), TQCanvasRectangle, TQCanvasSprite, TQCanvasEllipse or TQCanvasText.
.PP
Canvas items are added to a canvas by constructing them and passing the canvas to the canvas item's constructor. An item can be moved to a different canvas using setCanvas().
.PP
Items appear on the canvas after their show() function has been called (or setVisible(TRUE)), and \fIafter\fR update() has been called. The canvas only shows items that are visible, and then only if update() is called. If you created the canvas without passing a width and height to the constructor you'll also need to call resize(). Since the canvas background defaults to white and canvas items default to white, you may need to change colors to see your items.
.PP
A TQCanvasItem object can be moved in the x(), y() and z() dimensions using functions such as move(), moveBy(), setX(), setY() and setZ(). A canvas item can be set in motion, `animated', using setAnimated() and given a velocity in the x and y directions with setXVelocity() and setYVelocity() -- the same effect can be achieved by calling setVelocity(). Use the collidesWith() function to see if the canvas item will collide on the \fInext\fR advance(1) and use collisions() to see what collisions have occurred.
.PP
Use TQCanvasSprite or your own subclass of TQCanvasSprite to create canvas items which are animated, i.e. which change over time.
.PP
The size of a canvas item is given by boundingRect(). Use boundingRectAdvanced() to see what the size of the canvas item will be \fIafter\fR the next advance(1) call.
.PP
The rtti() function is used for identifying subclasses of TQCanvasItem. The canvas() function returns a pointer to the canvas which contains the canvas item.
.PP
TQCanvasItem provides the show() and isVisible() functions like those in TQWidget.
.PP
TQCanvasItem also provides the setEnabled(), setActive() and setSelected() functions; these functions set the relevant boolean and cause a repaint but the boolean values they set are not used in TQCanvasItem itself. You can make use of these booleans in your subclasses.
.PP
By default, canvas items have no velocity, no size, and are not in motion. The subclasses provided in TQt do not change these defaults except where noted.
.PP
See also Graphics Classes and Image Processing Classes.
.SS "Member Type Documentation"
.SH "TQCanvasItem::RttiValues"
This enum is used to name the different types of canvas item.
.TP
\fCTQCanvasItem::Rtti_Item\fR - Canvas item abstract base class
.TP
\fCTQCanvasItem::Rtti_Ellipse\fR
.TP
\fCTQCanvasItem::Rtti_Line\fR
.TP
\fCTQCanvasItem::Rtti_Polygon\fR
.TP
\fCTQCanvasItem::Rtti_PolygonalItem\fR
.TP
\fCTQCanvasItem::Rtti_Rectangle\fR
.TP
\fCTQCanvasItem::Rtti_Spline\fR
.TP
\fCTQCanvasItem::Rtti_Sprite\fR
.TP
\fCTQCanvasItem::Rtti_Text\fR
.PP
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQCanvasItem::TQCanvasItem ( TQCanvas * canvas )"
Constructs a TQCanvasItem on canvas \fIcanvas\fR.
.PP
See also setCanvas().
.SH "TQCanvasItem::~TQCanvasItem ()\fC [virtual]\fR"
Destroys the TQCanvasItem and removes it from its canvas.
.SH "bool TQCanvasItem::active () const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use isActive() instead.
.SH "void TQCanvasItem::advance ( int phase )\fC [virtual]\fR"
The default implementation moves the canvas item, if it is animated(), by the preset velocity if \fIphase\fR is 1, and does nothing if \fIphase\fR is 0.
.PP
Note that if you reimplement this function, the reimplementation must not change the canvas in any way, for example it must not add or remove items.
.PP
See also TQCanvas::advance() and setVelocity().
.PP
Example: canvas/canvas.cpp.
.PP
Reimplemented in TQCanvasSprite.
.SH "bool TQCanvasItem::animated () const"
Returns TRUE if the canvas item is in motion; otherwise returns FALSE.
.PP
See also setVelocity() and setAnimated().
.SH "TQRect TQCanvasItem::boundingRect () const\fC [pure virtual]\fR"
Returns the bounding rectangle in pixels that the canvas item covers.
.PP
See also boundingRectAdvanced().
.PP
Reimplemented in TQCanvasSprite, TQCanvasPolygonalItem, and TQCanvasText.
.SH "TQRect TQCanvasItem::boundingRectAdvanced () const\fC [virtual]\fR"
Returns the bounding rectangle of pixels that the canvas item \fIwill\fR cover after advance(1) is called.
.PP
See also boundingRect().
.SH "TQCanvas * TQCanvasItem::canvas () const"
Returns the canvas containing the canvas item.
.SH "bool TQCanvasItem::collidesWith ( const TQCanvasItem * other ) const\fC [pure virtual]\fR"
Returns TRUE if the canvas item will collide with the \fIother\fR item \fIafter\fR they have moved by their current velocities; otherwise returns FALSE.
.PP
See also collisions().
.PP
Example: canvas/canvas.cpp.
.SH "TQCanvasItemList TQCanvasItem::collisions ( bool exact ) const"
Returns the list of canvas items that this canvas item has collided with.
.PP
A collision is generally defined as occurring when the pixels of one item draw on the pixels of another item, but not all subclasses are so precise. Also, since pixel-wise collision detection can be slow, this function works in either exact or inexact mode, according to the \fIexact\fR parameter.
.PP
If \fIexact\fR is TRUE, the canvas items returned have been accurately tested for collision with the canvas item.
.PP
If \fIexact\fR is FALSE, the canvas items returned are \fInear\fR the canvas item. You can test the canvas items returned using collidesWith() if any are interesting collision candidates. By using this approach, you can ignore some canvas items for which collisions are not relevant.
.PP
The returned list is a list of TQCanvasItems, but often you will need to cast the items to their subclass types. The safe way to do this is to use rtti() before casting. This provides some of the functionality of the standard C++ dynamic cast operation even on compilers where dynamic casts are not available.
.PP
Note that a canvas item may be `on' a canvas, e.g. it was created with the canvas as parameter, even though its coordinates place it beyond the edge of the canvas's area. Collision detection only works for canvas items which are wholly or partly within the canvas's area.
.PP
Note that if items have a velocity (see setVelocity()), then collision testing is done based on where the item \fIwill\fR be when it moves, not its current location. For example, a "ball" item doesn't need to actually embed into a "wall" item before a collision is detected. For items without velocity, plain intersection is used.
.SH "void TQCanvasItem::draw ( TQPainter & painter )\fC [pure virtual]\fR"
This abstract virtual function draws the canvas item using \fIpainter\fR.
.PP
\fBWarning:\fR When you reimplement this function, make sure that you leave the painter in the same state as you found it. For example, if you start by calling TQPainter::translate(50, 50), end your code by calling TQPainter::translate(-50, -50). Be also aware that the painter might already have some transformations set (i.e., don't call TQPainter::resetXForm() when you're done).
.PP
Reimplemented in TQCanvasSprite, TQCanvasPolygonalItem, and TQCanvasText.
.SH "bool TQCanvasItem::enabled () const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use isEnabled() instead.
.SH "void TQCanvasItem::hide ()"
Shorthand for setVisible(FALSE).
.SH "bool TQCanvasItem::isActive () const"
Returns TRUE if the TQCanvasItem is active; otherwise returns FALSE.
.SH "bool TQCanvasItem::isEnabled () const"
Returns TRUE if the TQCanvasItem is enabled; otherwise returns FALSE.
.SH "bool TQCanvasItem::isSelected () const"
Returns TRUE if the canvas item is selected; otherwise returns FALSE.
.SH "bool TQCanvasItem::isVisible () const"
Returns TRUE if the canvas item is visible; otherwise returns FALSE.
.PP
Note that in this context TRUE does \fInot\fR mean that the canvas item is currently in a view, merely that if a view is showing the area where the canvas item is positioned, and the item is not obscured by items with higher z values, and the view is not obscured by overlaying windows, it would be visible.
.PP
See also setVisible() and z().
.SH "void TQCanvasItem::move ( double x, double y )"
Moves the canvas item to the absolute position (\fIx\fR, \fIy\fR).
.PP
Example: canvas/canvas.cpp.
.SH "void TQCanvasItem::moveBy ( double dx, double dy )\fC [virtual]\fR"
Moves the canvas item relative to its current position by (\fIdx\fR, \fIdy\fR).
.PP
Example: canvas/canvas.cpp.
.SH "int TQCanvasItem::rtti () const\fC [virtual]\fR"
Returns 0 (TQCanvasItem::Rtti_Item).
.PP
Make your derived classes return their own values for rtti(), so that you can distinguish between objects returned by TQCanvas::at(). You should use values greater than 1000 to allow for extensions to this class.
.PP
Overuse of this functionality can damage it's extensibility. For example, once you have identified a base class of a TQCanvasItem found by TQCanvas::at(), cast it to that type and call meaningful methods rather than acting upon the object based on its rtti value.
.PP
For example:
.PP
.nf
.br
TQCanvasItem* item;
.br
// Find an item, e.g. with TQCanvasItem::collisions().
.br
...
.br
if (item->rtti() == MySprite::RTTI ) {
.br
MySprite* s = (MySprite*)item;
.br
if (s->isDamagable()) s->loseHitPoints(1000);
.br
if (s->isHot()) myself->loseHitPoints(1000);
.br
...
.br
}
.br
.fi
.PP
Example: canvas/canvas.cpp.
.PP
Reimplemented in TQCanvasSprite, TQCanvasPolygonalItem, and TQCanvasText.
.SH "bool TQCanvasItem::selected () const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use isSelected() instead.
.SH "void TQCanvasItem::setActive ( bool yes )\fC [virtual]\fR"
Sets the active flag of the item to \fIyes\fR. If this changes the item's active state the item will be redrawn when TQCanvas::update() is next called.
.PP
The TQCanvas, TQCanvasItem and the Qt-supplied TQCanvasItem subclasses do not make use of this value. The setActive() function is supplied because many applications need it, but it is up to you how you use the isActive() value.
.SH "void TQCanvasItem::setAnimated ( bool y )\fC [virtual]\fR"
Sets the canvas item to be in motion if \fIy\fR is TRUE, or not if \fIy\fR is FALSE. The speed and direction of the motion is set with setVelocity(), or with setXVelocity() and setYVelocity().
.PP
See also advance() and TQCanvas::advance().
.SH "void TQCanvasItem::setCanvas ( TQCanvas * c )\fC [virtual]\fR"
Sets the TQCanvas upon which the canvas item is to be drawn to \fIc\fR.
.PP
See also canvas().
.SH "void TQCanvasItem::setEnabled ( bool yes )\fC [virtual]\fR"
Sets the enabled flag of the item to \fIyes\fR. If this changes the item's enabled state the item will be redrawn when TQCanvas::update() is next called.
.PP
The TQCanvas, TQCanvasItem and the Qt-supplied TQCanvasItem subclasses do not make use of this value. The setEnabled() function is supplied because many applications need it, but it is up to you how you use the isEnabled() value.
.SH "void TQCanvasItem::setSelected ( bool yes )\fC [virtual]\fR"
Sets the selected flag of the item to \fIyes\fR. If this changes the item's selected state the item will be redrawn when TQCanvas::update() is next called.
.PP
The TQCanvas, TQCanvasItem and the Qt-supplied TQCanvasItem subclasses do not make use of this value. The setSelected() function is supplied because many applications need it, but it is up to you how you use the isSelected() value.
.SH "void TQCanvasItem::setVelocity ( double vx, double vy )\fC [virtual]\fR"
Sets the canvas item to be in motion, moving by \fIvx\fR and \fIvy\fR pixels in the horizontal and vertical directions respectively.
.PP
See also advance(), setXVelocity(), and setYVelocity().
.SH "void TQCanvasItem::setVisible ( bool yes )\fC [virtual]\fR"
Makes the canvas item visible if \fIyes\fR is TRUE, or invisible if \fIyes\fR is FALSE. The change takes effect when TQCanvas::update() is next called.
.SH "void TQCanvasItem::setX ( double x )"
Moves the canvas item so that its x-position is \fIx\fR.
.PP
See also x() and move().
.PP
Example: chart/chartform_canvas.cpp.
.SH "void TQCanvasItem::setXVelocity ( double vx )"
Sets the horizontal component of the canvas item's velocity to \fIvx\fR.
.PP
See also setYVelocity() and setVelocity().
.SH "void TQCanvasItem::setY ( double y )"
Moves the canvas item so that its y-position is \fIy\fR.
.PP
See also y() and move().
.PP
Example: chart/chartform_canvas.cpp.
.SH "void TQCanvasItem::setYVelocity ( double vy )"
Sets the vertical component of the canvas item's velocity to \fIvy\fR.
.PP
See also setXVelocity() and setVelocity().
.SH "void TQCanvasItem::setZ ( double z )"
Sets the z index of the canvas item to \fIz\fR. Higher-z items obscure (are in front of) lower-z items.
.PP
See also z() and move().
.PP
Examples:
.)l canvas/canvas.cpp and chart/chartform_canvas.cpp.
.SH "void TQCanvasItem::show ()"
Shorthand for setVisible(TRUE).
.PP
Examples:
.)l canvas/canvas.cpp and chart/chartform_canvas.cpp.
.SH "void TQCanvasItem::update ()\fC [protected]\fR"
Call this function to repaint the canvas's changed chunks.
.SH "bool TQCanvasItem::visible () const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Use isVisible() instead.
.SH "double TQCanvasItem::x () const"
Returns the horizontal position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
.PP
Example: canvas/canvas.cpp.
.SH "double TQCanvasItem::xVelocity () const"
Returns the horizontal velocity component of the canvas item.
.SH "double TQCanvasItem::y () const"
Returns the vertical position of the canvas item. Note that subclasses often have an origin other than the top-left corner.
.PP
Example: canvas/canvas.cpp.
.SH "double TQCanvasItem::yVelocity () const"
Returns the vertical velocity component of the canvas item.
.SH "double TQCanvasItem::z () const"
Returns the z index of the canvas item, which is used for visual
order: higher-z items obscure (are in front of) lower-z items.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqcanvasitem.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqcanvasitem.3qt) and the Qt
version (3.3.8).