📄 qcanvas.3qt
字号:
'\" t.TH QCanvas 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQCanvas \- 2D area that can contain QCanvasItem objects.SH SYNOPSIS\fC#include <qcanvas.h>\fR.PPInherits QObject..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQCanvas\fR ( QObject * parent = 0, const char * name = 0 )".br.ti -1c.BI "\fBQCanvas\fR ( int w, int h )".br.ti -1c.BI "\fBQCanvas\fR ( QPixmap p, int h, int v, int tilewidth, int tileheight )".br.ti -1c.BI "virtual \fB~QCanvas\fR ()".br.ti -1c.BI "virtual void \fBsetTiles\fR ( QPixmap p, int h, int v, int tilewidth, int tileheight )".br.ti -1c.BI "virtual void \fBsetBackgroundPixmap\fR ( const QPixmap & p )".br.ti -1c.BI "QPixmap \fBbackgroundPixmap\fR () const".br.ti -1c.BI "virtual void \fBsetBackgroundColor\fR ( const QColor & c )".br.ti -1c.BI "QColor \fBbackgroundColor\fR () const".br.ti -1c.BI "virtual void \fBsetTile\fR ( int x, int y, int tilenum )".br.ti -1c.BI "int \fBtile\fR ( int x, int y ) const".br.ti -1c.BI "int \fBtilesHorizontally\fR () const".br.ti -1c.BI "int \fBtilesVertically\fR () const".br.ti -1c.BI "int \fBtileWidth\fR () const".br.ti -1c.BI "int \fBtileHeight\fR () const".br.ti -1c.BI "virtual void \fBresize\fR ( int w, int h )".br.ti -1c.BI "int \fBwidth\fR () const".br.ti -1c.BI "int \fBheight\fR () const".br.ti -1c.BI "QSize \fBsize\fR () const".br.ti -1c.BI "QRect \fBrect\fR () const".br.ti -1c.BI "bool \fBonCanvas\fR ( int x, int y ) const".br.ti -1c.BI "bool \fBonCanvas\fR ( const QPoint & p ) const".br.ti -1c.BI "bool \fBvalidChunk\fR ( int x, int y ) const".br.ti -1c.BI "bool \fBvalidChunk\fR ( const QPoint & p ) const".br.ti -1c.BI "int \fBchunkSize\fR () const".br.ti -1c.BI "virtual void \fBretune\fR ( int chunksze, int mxclusters = 100 )".br.ti -1c.BI "virtual void \fBsetAllChanged\fR ()".br.ti -1c.BI "virtual void \fBsetChanged\fR ( const QRect & area )".br.ti -1c.BI "virtual void \fBsetUnchanged\fR ( const QRect & area )".br.ti -1c.BI "QCanvasItemList \fBallItems\fR ()".br.ti -1c.BI "QCanvasItemList \fBcollisions\fR ( const QPoint & p ) const".br.ti -1c.BI "QCanvasItemList \fBcollisions\fR ( const QRect & r ) const".br.ti -1c.BI "QCanvasItemList \fBcollisions\fR ( const QPointArray & chunklist, const QCanvasItem * item, bool exact ) const".br.ti -1c.BI "void \fBdrawArea\fR ( const QRect & clip, QPainter * painter, bool dbuf = FALSE )".br.ti -1c.BI "virtual void \fBsetAdvancePeriod\fR ( int ms )".br.ti -1c.BI "virtual void \fBsetUpdatePeriod\fR ( int ms )".br.ti -1c.BI "virtual void \fBsetDoubleBuffering\fR ( bool y )".br.in -1c.SS "Public Slots".in +1c.ti -1c.BI "virtual void \fBadvance\fR ()".br.ti -1c.BI "virtual void \fBupdate\fR ()".br.in -1c.SS "Signals".in +1c.ti -1c.BI "void \fBresized\fR ()".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "virtual void \fBdrawBackground\fR ( QPainter & painter, const QRect & clip )".br.ti -1c.BI "virtual void \fBdrawForeground\fR ( QPainter & painter, const QRect & clip )".br.in -1c.SH DESCRIPTIONThe QCanvas class provides a 2D area that can contain QCanvasItem objects..PPThe QCanvas class manages its 2D graphic area and all the canvas items the area contains. The canvas is displayed on screen with a QCanvasView widget. Multiple QCanvasView widgets may be associated with a canvas to provide multiple views of the same canvas..PPThe canvas is optimized for large numbers of items. Qt provides a rich set of canvas item classes, e.g. QCanvasEllipse, QCanvasLine, QCanvasPolygon, QCanvasPolygonalItem, QCanvasRectangle, QCanvasSpline, QCanvasSprite and QCanvasText. You can subclass to create your own canvas items; QCanvasPolygonalItem is the most common base class used for this purpose..PPItems 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()..PPAlthough a canvas may appear to be similar to a widget with child widgets, there are several notable differences:.TPCanvas items are usually far faster to manipulate and redraw than child widgets, with the speed advantage becoming especially great when there are \fImany\fR canvas items and non-rectangular items. In most situations canvas items are also a lot more memory efficient than child widgets..IP.TPIt's easy to detect overlapping items (collision detection)..IP.TPThe canvas can be larger than a widget. A million-by-million canvas is perfectly possible. At such a size a widget might be very inefficient, and some window systems might not support it at all, whereas QCanvas scales well. Even with a billion pixels and a million items, finding a particular canvas item, detecting collisions, etc., is still fast (though the memory consumption may be prohibitive at such an extreme)..IP.TPTwo or more QCanvasView objects can view the same canvas..IP.TPAn arbitrary transformation matrix can be set on each QCanvasView which makes it easy to zoom, rotate or shear the viewed canvas..IP.TPWidgets provide a lot more functionality, such as input (QKeyEvent, QMouseEvent etc.) and layout management (QGridLayout etc.)..IP.PPA canvas consists of a background, a number of canvas items organized by x, y and z coordinates, and a foreground. A canvas item's z coordinate may be treated as a layer number -- canvas items with a higher z coordinate appear in front of canvas items with a lower z coordinate..PPThe background is white by default, but can be set to a different color using setBackgroundColor(), or to a repeated pixmap using setBackgroundPixmap() or to a mosaic of smaller pixmaps using setTiles(). Individual tiles can be set with setTile(). There are corresponding get functions, e.g. backgroundColor() and backgroundPixmap()..PPNote that QCanvas does not inherit from QWidget, even though it has some functions which provide the same functionality as those in QWidget. One of these is setBackgroundPixmap(); some others are resize(), size(), width() and height(). QCanvasView is the widget used to display a canvas on the screen..PPCanvas 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 QCanvasItem::setCanvas()..PPCanvas items are movable (and in the case of QCanvasSprites, animated) objects that inherit QCanvasItem. Each canvas item has a position on the canvas (x, y coordinates) and a height (z coordinate), all of which are held as floating-point numbers. Moving canvas items also have x and y velocities. It's possible for a canvas item to be outside the canvas (for example QCanvasItem::x() is greater than width()). When a canvas item is off the canvas, onCanvas() returns FALSE and the canvas disregards the item. (Canvas items off the canvas do not slow down any of the common operations on the canvas.).PPCanvas items can be moved with QCanvasItem::move(). The advance() function moves all QCanvasItem::animated() canvas items and setAdvancePeriod() makes QCanvas move them automatically on a periodic basis. In the context of the QCanvas classes, to `animate' a canvas item is to set it in motion, i.e. using QCanvasItem::setVelocity(). Animation of a canvas item itself, i.e. items which change over time, is enabled by calling QCanvasSprite::setFrameAnimation(), or more generally by subclassing and reimplementing QCanvasItem::advance(). To detect collisions use one of the QCanvasItem::collisions() functions..PPThe changed parts of the canvas are redrawn (if they are visible in a canvas view) whenever update() is called. You can either call update() manually after having changed the contents of the canvas, or force periodic updates using setUpdatePeriod(). If you have moving objects on the canvas, you need to call advance() every time the objects should move one step further. Periodic calls to advance() can be forced using setAdvancePeriod(). The advance() function will call QCanvasItem::advance() on every item that is animated and trigger an update of the affected areas afterwards. (A canvas item that is `animated' is simply a canvas item that is in motion.).PPQCanvas organizes its canvas items into \fIchunks\fR; these are areas on the canvas that are used to speed up most operations. Many operations start by eliminating most chunks (i.e. those which haven't changed) and then process only the canvas items that are in the few interesting (i.e. changed) chunks. A valid chunk, validChunk(), is one which is on the canvas..PPThe chunk size is a key factor to QCanvas's speed: if there are too many chunks, the speed benefit of grouping canvas items into chunks is reduced. If the chunks are too large, it takes too long to process each one. The QCanvas constructor picks a hopefully suitable size, but you can call retune() to change it at any time. The chunkSize() function returns the current chunk size..PPThe canvas items always make sure they're in the right chunks; all you need to make sure of is that the canvas uses the right chunk size. A good rule of thumb is that the size should be a bit smaller than the average canvas item size. If you have moving objects, the chunk size should be a bit smaller than the average size of the moving items..PPThe foreground is normally nothing, but if you reimplement drawForeground(), you can draw things in front of all canvas items..PPAreas can be set as changed with setChanged() and set unchanged with setUnchanged(). The entire canvas can be set as changed with setAllChanged(). A list of all the items on the canvas is returned by allItems()..PPAn area can be copied (painted) to a QPainter with drawArea()..PPIf the canvas is resized it emits the resized() signal..PPThe examples/canvas application and the 2D graphics page of the examples/demo application demonstrate many of QCanvas's facilities..PPSee also QCanvasView, QCanvasItem, Abstract Widget Classes, Graphics Classes, and Image Processing Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QCanvas::QCanvas ( QObject * parent = 0, const char * name = 0 )"Create a QCanvas with no size. \fIparent\fR and \fIname\fR are passed to the QObject superclass..PP\fBWarning:\fR You \fImust\fR call resize() at some time after creation to be able to use the canvas..SH "QCanvas::QCanvas ( int w, int h )"Constructs a QCanvas that is \fIw\fR pixels wide and \fIh\fR pixels high..SH "QCanvas::QCanvas ( QPixmap p, int h, int v, int tilewidth, int tileheight )"Constructs a QCanvas which will be composed of \fIh\fR tiles horizontally and \fIv\fR tiles vertically. Each tile will be an image \fItilewidth\fR by \fItileheight\fR pixels taken from pixmap \fIp\fR..PPThe pixmap \fIp\fR is a list of tiles, arranged left to right, (and in the case of pixmaps that have multiple rows of tiles, top to bottom), with tile 0 in the top-left corner, tile 1 next to the right, and so on, e.g..PP<center>.nf.TS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -