#include <q3canvas.h>
Inheritance diagram for Q3Canvas:


The Q3Canvas class manages its 2D graphic area and all the canvas items the area contains. The canvas has no visual appearance of its own. Instead, it is displayed on screen using a Q3CanvasView. Multiple Q3CanvasView widgets may be associated with a canvas to provide multiple views of the same canvas.
The canvas is optimized for large numbers of items, particularly where only a small percentage of the items change at any one time. If the entire display changes very frequently, you should consider using your own custom Q3ScrollView subclass.
Qt provides a rich set of canvas item classes, e.g. Q3CanvasEllipse, Q3CanvasLine, Q3CanvasPolygon, Q3CanvasPolygonalItem, Q3CanvasRectangle, Q3CanvasSpline, Q3CanvasSprite and Q3CanvasText. You can subclass to create your own canvas items; Q3CanvasPolygonalItem is the most common base class used for this purpose.
Items appear on the canvas after their show() function has been called (or setVisible(true)), and after update() has been called. The canvas only shows items that are visible, and then only if update() is called. (By default the canvas is white and so are canvas items, so if nothing appears try changing colors.)
If you created the canvas without passing a width and height to the constructor you must also call resize().
Although a canvas may appear to be similar to a widget with child widgets, there are several notable differences:
Canvas items are usually much faster to manipulate and redraw than child widgets, with the speed advantage becoming especially great when there are many canvas items and non-rectangular items. In most situations canvas items are also a lot more memory efficient than child widgets.
It's easy to detect overlapping items (collision detection).
The 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 Q3Canvas 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 extremes).
Two or more Q3CanvasView objects can view the same canvas.
An arbitrary transformation matrix can be set on each Q3CanvasView which makes it easy to zoom, rotate or shear the viewed canvas.
Widgets provide a lot more functionality, such as input (QKeyEvent, QMouseEvent etc.) and layout management (QGridLayout etc.).
A 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 can be treated as a layer number -- canvas items with a higher z coordinate appear in front of canvas items with a lower z coordinate.
The 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().
Note that Q3Canvas 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(). Q3CanvasView is the widget used to display a canvas on the screen.
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 Q3CanvasItem::setCanvas().
Canvas items are movable (and in the case of Q3CanvasSprites, animated) objects that inherit Q3CanvasItem. 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 Q3CanvasItem::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.)
Canvas items can be moved with Q3CanvasItem::move(). The advance() function moves all Q3CanvasItem::animated() canvas items and setAdvancePeriod() makes Q3Canvas move them automatically on a periodic basis. In the context of the Q3Canvas classes, to `animate' a canvas item is to set it in motion, i.e. using Q3CanvasItem::setVelocity(). Animation of a canvas item itself, i.e. items which change over time, is enabled by calling Q3CanvasSprite::setFrameAnimation(), or more generally by subclassing and reimplementing Q3CanvasItem::advance(). To detect collisions use one of the Q3CanvasItem::collisions() functions.
The 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 must 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 Q3CanvasItem::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.)
Q3Canvas organizes its canvas items into chunks; 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.
The chunk size is a key factor to Q3Canvas'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 Q3Canvas constructor tries to pick a suitable size, but you can call retune() to change it at any time. The chunkSize() function returns the current chunk size. The 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.
The foreground is normally nothing, but if you reimplement drawForeground(), you can draw things in front of all the canvas items.
Areas 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().
An area can be copied (painted) to a QPainter with drawArea().
If the canvas is resized it emits the resized() signal.
The examples/canvas application and the 2D graphics page of the examples/demo application demonstrate many of Q3Canvas's facilities.
Definition at line 184 of file q3canvas.h.
Public Slots | |
| virtual void | advance () |
| virtual void | update () |
Signals | |
| void | resized () |
Public Member Functions | |
| Q3Canvas (QObject *parent=0, const char *name=0) | |
| Q3Canvas (int w, int h) | |
| Q3Canvas (QPixmap p, int h, int v, int tilewidth, int tileheight) | |
| virtual | ~Q3Canvas () |
| virtual void | setTiles (QPixmap tiles, int h, int v, int tilewidth, int tileheight) |
| virtual void | setBackgroundPixmap (const QPixmap &p) |
| QPixmap | backgroundPixmap () const |
| virtual void | setBackgroundColor (const QColor &c) |
| QColor | backgroundColor () const |
| virtual void | setTile (int x, int y, int tilenum) |
| int | tile (int x, int y) const |
| int | tilesHorizontally () const |
| int | tilesVertically () const |
| int | tileWidth () const |
| int | tileHeight () const |
| virtual void | resize (int width, int height) |
| int | width () const |
| int | height () const |
| QSize | size () const |
| QRect | rect () const |
| bool | onCanvas (int x, int y) const |
| bool | onCanvas (const QPoint &p) const |
| bool | validChunk (int x, int y) const |
| bool | validChunk (const QPoint &p) const |
| int | chunkSize () const |
| virtual void | retune (int chunksize, int maxclusters=100) |
| bool | sameChunk (int x1, int y1, int x2, int y2) const |
| virtual void | setChangedChunk (int i, int j) |
| virtual void | setChangedChunkContaining (int x, int y) |
| virtual void | setAllChanged () |
| virtual void | setChanged (const QRect &area) |
| virtual void | setUnchanged (const QRect &area) |
| void | addItemToChunk (Q3CanvasItem *, int i, int j) |
| void | removeItemFromChunk (Q3CanvasItem *, int i, int j) |
| void | addItemToChunkContaining (Q3CanvasItem *, int x, int y) |
| void | removeItemFromChunkContaining (Q3CanvasItem *, int x, int y) |
| Q3CanvasItemList | allItems () |
| Q3CanvasItemList | collisions (const QPoint &) const |
| Q3CanvasItemList | collisions (const QRect &) const |
| Q3CanvasItemList | collisions (const Q3PointArray &pa, const Q3CanvasItem *item, bool exact) const |
| void | drawArea (const QRect &, QPainter *p, bool double_buffer=false) |
| virtual void | addView (Q3CanvasView *) |
| virtual void | removeView (Q3CanvasView *) |
| void | drawCanvasArea (const QRect &, QPainter *p=0, bool double_buffer=true) |
| void | drawViewArea (Q3CanvasView *view, QPainter *p, const QRect &r, bool dbuf) |
| virtual void | addItem (Q3CanvasItem *) |
| virtual void | addAnimation (Q3CanvasItem *) |
| virtual void | removeItem (Q3CanvasItem *) |
| virtual void | removeAnimation (Q3CanvasItem *) |
| virtual void | setAdvancePeriod (int ms) |
| virtual void | setUpdatePeriod (int ms) |
| virtual void | setDoubleBuffering (bool y) |
Protected Member Functions | |
| virtual void | drawBackground (QPainter &, const QRect &area) |
| virtual void | drawForeground (QPainter &, const QRect &area) |
Private Member Functions | |
| void | init (int w, int h, int chunksze=16, int maxclust=100) |
| Q3CanvasChunk & | chunk (int i, int j) const |
| Q3CanvasChunk & | chunkContaining (int x, int y) const |
| QRect | changeBounds (const QRect &inarea) |
| void | ensureOffScrSize (int osw, int osh) |
| void | initTiles (QPixmap p, int h, int v, int tilewidth, int tileheight) |
Private Attributes | |
| QPixmap | offscr |
| int | awidth |
| int | aheight |
| int | chunksize |
| int | maxclusters |
| int | chwidth |
| int | chheight |
| Q3CanvasChunk * | chunks |
| Q3CanvasData * | d |
| ushort * | grid |
| ushort | htiles |
| ushort | vtiles |
| ushort | tilew |
| ushort | tileh |
| bool | oneone |
| QPixmap | pm |
| QTimer * | update_timer |
| QColor | bgcolor |
| bool | debug_redraw_areas |
| bool | dblbuf |
Friends | |
| void | qt_unview (Q3Canvas *c) |
| Q3Canvas::Q3Canvas | ( | QObject * | parent = 0, |
|
| const char * | name = 0 | |||
| ) |
| Q3Canvas::Q3Canvas | ( | int | w, | |
| int | h | |||
| ) |
| Q3Canvas::Q3Canvas | ( | QPixmap | p, | |
| int | h, | |||
| int | v, | |||
| int | tilewidth, | |||
| int | tileheight | |||
| ) |
Constructs a Q3Canvas which will be composed of h tiles horizontally and v tiles vertically. Each tile will be an image tilewidth by tileheight pixels taken from pixmap p.
The pixmap p 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.
0 1 2 3 4 5 6 7
The Q3Canvas is initially sized to show exactly the given number of tiles horizontally and vertically. If it is resized to be larger, the entire matrix of tiles will be repeated as often as necessary to cover the area. If it is smaller, tiles to the right and bottom will not be visible.
Definition at line 651 of file q3canvas.cpp.
References init(), p, scm(), and setTiles().
00653 { 00654 init(h*tilewidth, v*tileheight, scm(tilewidth,tileheight)); 00655 setTiles(p, h, v, tilewidth, tileheight); 00656 }
Here is the call graph for this function:

| Q3Canvas::~Q3Canvas | ( | ) | [virtual] |
Destroys the canvas and all the canvas's canvas items.
Definition at line 668 of file q3canvas.cpp.
References allItems(), QLinkedList< T >::begin(), chunks, d, QLinkedList< T >::end(), grid, and qt_unview.
00669 { 00670 qt_unview(this); 00671 Q3CanvasItemList all = allItems(); 00672 for (Q3CanvasItemList::Iterator it=all.begin(); it!=all.end(); ++it) 00673 delete *it; 00674 delete [] chunks; 00675 delete [] grid; 00676 delete d; 00677 }
Here is the call graph for this function:

| void Q3Canvas::setTiles | ( | QPixmap | p, | |
| int | h, | |||
| int | v, | |||
| int | tilewidth, | |||
| int | tileheight | |||
| ) | [virtual] |
Sets the Q3Canvas to be composed of h tiles horizontally and v tiles vertically. Each tile will be an image tilewidth by tileheight pixels from pixmap p.
The pixmap p 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.
0 1 2 3 4 5 6 7
If the canvas is larger than the matrix of tiles, the entire matrix is repeated as necessary to cover the whole canvas. If it is smaller, tiles to the right and bottom are not visible.
The width and height of p must be a multiple of tilewidth and tileheight. If they are not the function will do nothing.
If you want to unset any tiling set, then just pass in a null pixmap and 0 for h, v, tilewidth, and tileheight.
Definition at line 1603 of file q3canvas.cpp.
References grid, htiles, p, pm, retune(), s, scm(), setAllChanged(), tileh, tilew, and vtiles.
Referenced by Q3Canvas(), and setBackgroundPixmap().
01605 { 01606 if (!p.isNull() && (!tilewidth || !tileheight || 01607 p.width() % tilewidth != 0 || p.height() % tileheight != 0)) 01608 return; 01609 01610 htiles = h; 01611 vtiles = v; 01612 delete[] grid; 01613 pm = p; 01614 if (h && v && !p.isNull()) { 01615 grid = new ushort[h*v]; 01616 memset(grid, 0, h*v*sizeof(ushort)); 01617 tilew = tilewidth; 01618 tileh = tileheight; 01619 } else { 01620 grid = 0; 01621 } 01622 if (h + v > 10) { 01623 int s = scm(tilewidth,tileheight); 01624 retune(s < 128 ? s : QMAX(tilewidth,tileheight)); 01625 } 01626 setAllChanged(); 01627 }
Here is the call graph for this function:

| void Q3Canvas::setBackgroundPixmap | ( | const QPixmap & | p | ) | [virtual] |
Sets the solid background to be the pixmap p repeated as necessary to cover the entire canvas.
Definition at line 1486 of file q3canvas.cpp.
References d, Q3PtrList< type >::first(), Q3PtrList< type >::next(), p, setTiles(), Q3ScrollView::updateContents(), and Q3CanvasData::viewList.
01487 { 01488 setTiles(p, 1, 1, p.width(), p.height()); 01489 Q3CanvasView* view = d->viewList.first(); 01490 while (view != 0) { 01491 view->updateContents(); 01492 view = d->viewList.next(); 01493 } 01494 }
Here is the call graph for this function:

| QPixmap Q3Canvas::backgroundPixmap | ( | ) | const |
Returns the pixmap set by setBackgroundPixmap(). By default, this is a null pixmap.
Definition at line 1475 of file q3canvas.cpp.
References pm.
01476 { 01477 return pm; 01478 }
| void Q3Canvas::setBackgroundColor | ( | const QColor & | c | ) | [virtual] |
Sets the solid background to be the color c.
Definition at line 1454 of file q3canvas.cpp.
References bgcolor, c, d, Q3PtrList< type >::first(), Q3PtrList< type >::next(), setAllChanged(), Q3CanvasData::viewList, and Q3ScrollView::viewport().
01455 { 01456 if (bgcolor != c) { 01457 bgcolor = c; 01458 Q3CanvasView* view=d->viewList.first(); 01459 while (view != 0) { 01460 /* XXX this doesn't look right. Shouldn't this 01461 be more like setBackgroundPixmap? : Ian */ 01462 view->viewport()->setEraseColor(bgcolor); 01463 view=d->viewList.next(); 01464 } 01465 setAllChanged(); 01466 } 01467 }
Here is the call graph for this function:

| QColor Q3Canvas::backgroundColor | ( | ) | const |
Returns the color set by setBackgroundColor(). By default, this is white.
This function is not a reimplementation of QWidget::backgroundColor() (Q3Canvas is not a subclass of QWidget), but all Q3CanvasViews that are viewing the canvas will set their backgrounds to this color.
Definition at line 1444 of file q3canvas.cpp.
References bgcolor.
Referenced by addView().
01445 { 01446 return bgcolor; 01447 }
| void Q3Canvas::setTile | ( | int | x, | |
| int | y, | |||
| int | tilenum | |||
| ) | [virtual] |
Sets the tile at (x, y) to use tile number tilenum, which is an index into the tile pixmaps. The canvas will update appropriately when update() is next called.
The images are taken from the pixmap set by setTiles() and are 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.
0 1 2 3 4 5 6 7
Definition at line 1684 of file q3canvas.cpp.
References chunksize, grid, htiles, setChanged(), setChangedChunk(), t, tileh, and tilew.
01685 { 01686 ushort& t = grid[x+y*htiles]; 01687 if (t != tilenum) { 01688 t = tilenum; 01689 if (tilew == tileh && tilew == chunksize) 01690 setChangedChunk(x, y); // common case 01691 else 01692 setChanged(QRect(x*tilew,y*tileh,tilew,tileh)); 01693 } 01694 }
Here is the call graph for this function:

| int Q3Canvas::tile | ( | int | x, | |
| int | y | |||
| ) | const [inline] |
Returns the tile at position (x, y). Initially, all tiles are 0.
The parameters must be within range, i.e. 0 < x < tilesHorizontally() and 0 < y < tilesVertically().
Definition at line 203 of file q3canvas.h.
Referenced by drawBackground().
| int Q3Canvas::tilesHorizontally | ( | ) | const [inline] |
Returns the number of tiles horizontally.
Definition at line 206 of file q3canvas.h.
Referenced by drawBackground().
00207 { return htiles; }
| int Q3Canvas::tilesVertically | ( | ) | const [inline] |
Returns the number of tiles vertically.
Definition at line 208 of file q3canvas.h.
Referenced by drawBackground().
00209 { return vtiles; }
| int Q3Canvas::tileWidth | ( | ) | const [inline] |
| int Q3Canvas::tileHeight | ( | ) | const [inline] |
| void Q3Canvas::resize | ( | int | w, | |
| int | h | |||
| ) | [virtual] |
Changes the size of the canvas to have a width of w and a height of h. This is a slow operation.
Definition at line 714 of file q3canvas.cpp.
References aheight, Q3PtrList< type >::append(), awidth, chheight, chunks, chunksize, chwidth, d, emit, Q3PtrList< type >::first(), Q3CanvasData::itemDict, Q3PtrList< type >::next(), resized(), setAllChanged(), and Q3CanvasItem::show().
00715 { 00716 if (awidth==w && aheight==h) 00717 return; 00718 00719 Q3CanvasItem* item; 00720 Q3PtrList<Q3CanvasItem> hidden; 00721 for (Q3PtrDictIterator<void> it=d->itemDict; it.currentKey(); ++it) { 00722 if (((Q3CanvasItem*)it.currentKey())->isVisible()) { 00723 ((Q3CanvasItem*)it.currentKey())->hide(); 00724 hidden.append(((Q3CanvasItem*)it.currentKey())); 00725 } 00726 } 00727 00728 int nchwidth=(w+chunksize-1)/chunksize; 00729 int nchheight=(h+chunksize-1)/chunksize; 00730 00731 Q3CanvasChunk* newchunks = new Q3CanvasChunk[nchwidth*nchheight]; 00732 00733 // Commit the new values. 00734 // 00735 awidth=w; 00736 aheight=h; 00737 chwidth=nchwidth; 00738 chheight=nchheight; 00739 delete [] chunks; 00740 chunks=newchunks; 00741 00742 for (item=hidden.first(); item != 0; item=hidden.next()) { 00743 item->show(); 00744 } 00745 00746 setAllChanged(); 00747 00748 emit resized(); 00749 }
Here is the call graph for this function:

| int Q3Canvas::width | ( | ) | const [inline] |
Returns the width of the canvas, in pixels.
Definition at line 217 of file q3canvas.h.
Referenced by addItemToChunkContaining(), changeBounds(), drawCanvasArea(), drawViewArea(), removeItemFromChunkContaining(), setAllChanged(), setChanged(), setChangedChunkContaining(), setUnchanged(), and Q3CanvasView::updateContentsSize().
00218 { return awidth; }
| int Q3Canvas::height | ( | ) | const [inline] |
Returns the height of the canvas, in pixels.
Definition at line 219 of file q3canvas.h.
Referenced by addItemToChunkContaining(), changeBounds(), drawCanvasArea(), drawViewArea(), removeItemFromChunkContaining(), setAllChanged(), setChanged(), setChangedChunkContaining(), setUnchanged(), and Q3CanvasView::updateContentsSize().
00220 { return aheight; }
| QSize Q3Canvas::size | ( | ) | const [inline] |
| QRect Q3Canvas::rect | ( | ) | const [inline] |
Returns a rectangle the size of the canvas.
Definition at line 223 of file q3canvas.h.
Referenced by QPolygonalProcessor::QPolygonalProcessor().
| bool Q3Canvas::onCanvas | ( | int | x, | |
| int | y | |||
| ) | const [inline] |
Returns true if the pixel position (x, y) is on the canvas; otherwise returns false.
Definition at line 225 of file q3canvas.h.
| bool Q3Canvas::onCanvas | ( | const QPoint & | p | ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the pixel position p is on the canvas; otherwise returns false.
Definition at line 227 of file q3canvas.h.
References p.
| bool Q3Canvas::validChunk | ( | int | x, | |
| int | y | |||
| ) | const [inline] |
Returns true if the chunk position (x, y) is on the canvas; otherwise returns false.
Definition at line 229 of file q3canvas.h.
Referenced by addItemToChunk(), collisions(), removeItemFromChunk(), and setChangedChunk().
| bool Q3Canvas::validChunk | ( | const QPoint & | p | ) | const [inline] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the chunk position p is on the canvas; otherwise returns false.
Definition at line 231 of file q3canvas.h.
References p.
00232 { return validChunk(p.x(),p.y()); }
| int Q3Canvas::chunkSize | ( | ) | const [inline] |
Returns the chunk size of the canvas.
Definition at line 234 of file q3canvas.h.
Referenced by QPolygonalProcessor::add(), Q3CanvasSprite::addToChunks(), Q3CanvasText::addToChunks(), Q3CanvasText::changeChunks(), Q3CanvasSprite::changeChunks(), Q3CanvasItem::chunks(), QPolygonalProcessor::doSpans(), QPolygonalProcessor::QPolygonalProcessor(), Q3CanvasText::removeFromChunks(), and Q3CanvasSprite::removeFromChunks().
00235 { return chunksize; }
| void Q3Canvas::retune | ( | int | chunksze, | |
| int | mxclusters = 100 | |||
| ) | [virtual] |
Change the efficiency tuning parameters to mxclusters clusters, each of size chunksze. This is a slow operation if there are many objects on the canvas.
The canvas is divided into chunks which are rectangular areas chunksze wide by chunksze high. Use a chunk size which is about the average size of the canvas items. If you choose a chunk size which is too small it will increase the amount of calculation required when drawing since each change will affect many chunks. If you choose a chunk size which is too large the amount of drawing required will increase because for each change, a lot of drawing will be required since there will be many (unchanged) canvas items which are in the same chunk as the changed canvas items.
Internally, a canvas uses a low-resolution "chunk matrix" to keep track of all the items in the canvas. A 64x64 chunk matrix is the default for a 1024x1024 pixel canvas, where each chunk collects canvas items in a 16x16 pixel square. This default is also affected by setTiles(). You can tune this default using this function. For example if you have a very large canvas and want to trade off speed for memory then you might set the chunk size to 32 or 64.
The mxclusters argument is the number of rectangular groups of chunks that will be separately drawn. If the canvas has a large number of small, dispersed items, this should be about that number. Our testing suggests that a large number of clusters is almost always best.
Definition at line 791 of file q3canvas.cpp.
References aheight, Q3PtrList< type >::append(), awidth, chheight, chunks, chunksize, chwidth, d, Q3PtrList< type >::first(), Q3CanvasData::itemDict, maxclusters, and Q3PtrList< type >::next().
Referenced by setTiles().
00792 { 00793 maxclusters=mxclusters; 00794 00795 if (chunksize!=chunksze) { 00796 Q3PtrList<Q3CanvasItem> hidden; 00797 for (Q3PtrDictIterator<void> it=d->itemDict; it.currentKey(); ++it) { 00798 if (((Q3CanvasItem*)it.currentKey())->isVisible()) { 00799 ((Q3CanvasItem*)it.currentKey())->hide(); 00800 hidden.append(((Q3CanvasItem*)it.currentKey())); 00801 } 00802 } 00803 00804 chunksize=chunksze; 00805 00806 int nchwidth=(awidth+chunksize-1)/chunksize; 00807 int nchheight=(aheight+chunksize-1)/chunksize; 00808 00809 Q3CanvasChunk* newchunks = new Q3CanvasChunk[nchwidth*nchheight]; 00810 00811 // Commit the new values. 00812 // 00813 chwidth=nchwidth; 00814 chheight=nchheight; 00815 delete [] chunks; 00816 chunks=newchunks; 00817 00818 for (Q3CanvasItem* item=hidden.first(); item != 0; item=hidden.next()) { 00819 item->show(); 00820 } 00821 } 00822 }
Here is the call graph for this function:

| bool Q3Canvas::sameChunk | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2 | |||
| ) | const [inline] |
| void Q3Canvas::setChangedChunk | ( | int | i, | |
| int | j | |||
| ) | [virtual] |
Definition at line 1350 of file q3canvas.cpp.
References Q3CanvasChunk::change(), chunk(), and validChunk().
Referenced by Q3CanvasItem::changeChunks(), Q3CanvasText::changeChunks(), Q3CanvasSprite::changeChunks(), and setTile().
01351 { 01352 if (validChunk(x,y)) { 01353 Q3CanvasChunk& ch=chunk(x,y); 01354 ch.change(); 01355 } 01356 }
Here is the call graph for this function:

| void Q3Canvas::setChangedChunkContaining | ( | int | x, | |
| int | y | |||
| ) | [virtual] |
Definition at line 1368 of file q3canvas.cpp.
References Q3CanvasChunk::change(), chunk(), chunkContaining(), height(), and width().
01369 { 01370 if (x>=0 && x<width() && y>=0 && y<height()) { 01371 Q3CanvasChunk& chunk=chunkContaining(x,y); 01372 chunk.change(); 01373 } 01374 }
Here is the call graph for this function:

| void Q3Canvas::setAllChanged | ( | ) | [virtual] |
Marks the whole canvas as changed. All views of the canvas will be entirely redrawn when update() is called next.
Definition at line 1161 of file q3canvas.cpp.
References height(), setChanged(), and width().
Referenced by resize(), setBackgroundColor(), and setTiles().
01162 { 01163 setChanged(QRect(0,0,width(),height())); 01164 }
Here is the call graph for this function:

| void Q3Canvas::setChanged | ( | const QRect & | area | ) | [virtual] |
Marks area as changed. This area will be redrawn in all views that are showing it when update() is called next.
Definition at line 1170 of file q3canvas.cpp.
References area(), Q3CanvasChunk::change(), chheight, chunk(), chunksize, chwidth, QRect::height(), height(), QRect::width(), width(), QRect::x(), x, QRect::y(), and y.
Referenced by setAllChanged(), and setTile().
01171 { 01172 QRect thearea = area.intersected(QRect(0, 0, width(), height())); 01173 01174 int mx = (thearea.x()+thearea.width()+chunksize)/chunksize; 01175 int my = (thearea.y()+thearea.height()+chunksize)/chunksize; 01176 if (mx>chwidth) 01177 mx=chwidth; 01178 if (my>chheight) 01179 my=chheight; 01180 01181 int x=thearea.x()/chunksize; 01182 while(x<mx) { 01183 int y = thearea.y()/chunksize; 01184 while(y<my) { 01185 chunk(x,y).change(); 01186 y++; 01187 } 01188 x++; 01189 } 01190 }
Here is the call graph for this function:

| void Q3Canvas::setUnchanged | ( | const QRect & | area | ) | [virtual] |
Marks area as unchanged. The area will not be redrawn in the views for the next update(), unless it is marked or changed again before the next call to update().
Definition at line 1197 of file q3canvas.cpp.
References area(), chheight, chunk(), chunksize, chwidth, QRect::height(), height(), Q3CanvasChunk::takeChange(), QRect::width(), width(), QRect::x(), x, QRect::y(), and y.
Referenced by update().
01198 { 01199 QRect thearea = area.intersected(QRect(0, 0, width(), height())); 01200 01201 int mx = (thearea.x()+thearea.width()+chunksize)/chunksize; 01202 int my = (thearea.y()+thearea.height()+chunksize)/chunksize; 01203 if (mx>chwidth) 01204 mx=chwidth; 01205 if (my>chheight) 01206 my=chheight; 01207 01208 int x=thearea.x()/chunksize; 01209 while(x<mx) { 01210 int y = thearea.y()/chunksize; 01211 while(y<my) { 01212 chunk(x,y).takeChange(); 01213 y++; 01214 } 01215 x++; 01216 } 01217 }
Here is the call graph for this function:

| void Q3Canvas::addItemToChunk | ( | Q3CanvasItem * | , | |
| int | i, | |||
| int | j | |||
| ) |
Definition at line 1383 of file q3canvas.cpp.
References Q3CanvasChunk::add(), chunk(), g, and validChunk().
Referenced by Q3CanvasItem::addToChunks(), Q3CanvasSprite::addToChunks(), and Q3CanvasText::addToChunks().
Here is the call graph for this function:

| void Q3Canvas::removeItemFromChunk | ( | Q3CanvasItem * | , | |
| int | i, | |||
| int | j | |||
| ) |
Definition at line 1397 of file q3canvas.cpp.
References chunk(), g, Q3CanvasChunk::remove(), and validChunk().
Referenced by Q3CanvasText::removeFromChunks(), Q3CanvasItem::removeFromChunks(), and Q3CanvasSprite::removeFromChunks().
Here is the call graph for this function:

| void Q3Canvas::addItemToChunkContaining | ( | Q3CanvasItem * | , | |
| int | x, | |||
| int | y | |||
| ) |
Definition at line 1412 of file q3canvas.cpp.
References Q3CanvasChunk::add(), chunkContaining(), g, height(), and width().
01413 { 01414 if (x>=0 && x<width() && y>=0 && y<height()) { 01415 chunkContaining(x,y).add(g); 01416 } 01417 }
Here is the call graph for this function:

| void Q3Canvas::removeItemFromChunkContaining | ( | Q3CanvasItem * | , | |
| int | x, | |||
| int | y | |||
| ) |
Definition at line 1426 of file q3canvas.cpp.
References chunkContaining(), g, height(), Q3CanvasChunk::remove(), and width().
01427 { 01428 if (x>=0 && x<width() && y>=0 && y<height()) { 01429 chunkContaining(x,y).remove(g); 01430 } 01431 }
Here is the call graph for this function:

| Q3CanvasItemList Q3Canvas::allItems | ( | ) |
Returns a list of all the items in the canvas.
Definition at line 700 of file q3canvas.cpp.
References d, Q3CanvasData::itemDict, and Q3ValueList< T >::prepend().
Referenced by ~Q3Canvas().
00701 { 00702 Q3CanvasItemList list; 00703 for (Q3PtrDictIterator<void> it=d->itemDict; it.currentKey(); ++it) { 00704 list.prepend((Q3CanvasItem*)it.currentKey()); 00705 } 00706 return list; 00707 }
Here is the call graph for this function:

| Q3CanvasItemList Q3Canvas::collisions | ( | const QPoint & | p | ) | const |
Returns a list of canvas items that collide with the point p. The list is ordered by z coordinates, from highest z coordinate (front-most item) to lowest z coordinate (rear-most item).
Definition at line 2521 of file q3canvas.cpp.
References p.
Referenced by Q3CanvasItem::collisions().
02522 { 02523 return collisions(QRect(p,QSize(1,1))); 02524 }
| Q3CanvasItemList Q3Canvas::collisions | ( | const QRect & | r | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a list of items which collide with the rectangle r. The list is ordered by z coordinates, from highest z coordinate (front-most item) to lowest z coordinate (rear-most item).
Definition at line 2533 of file q3canvas.cpp.
References i, l, and Qt::NoPen.
02534 { 02535 Q3CanvasRectangle i(r,(Q3Canvas*)this); 02536 i.setPen(NoPen); 02537 i.show(); // doesn't actually show, since we destroy it 02538 Q3CanvasItemList l = i.collisions(true); 02539 l.sort(); 02540 return l; 02541 }
| Q3CanvasItemList Q3Canvas::collisions | ( | const Q3PointArray & | chunklist, | |
| const Q3CanvasItem * | item, | |||
| bool | exact | |||
| ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a list of canvas items which intersect with the chunks listed in chunklist, excluding item. If exact is true, only those which actually collide with item are returned; otherwise canvas items are included just for being in the chunks.
This is a utility function mainly used to implement the simpler Q3CanvasItem::collisions() function.
Definition at line 2555 of file q3canvas.cpp.
References Q3ValueList< T >::append(), chunk(), Q3CanvasItem::collidesWith(), QVector< T >::count(), Q3PtrDict< type >::find(), g, i, int, l, Q3CanvasChunk::listPtr(), Q3PtrDict< type >::replace(), validChunk(), x, and y.
02557 { 02558 Q3PtrDict<void> seen; 02559 Q3CanvasItemList result; 02560 for (int i=0; i<(int)chunklist.count(); i++) { 02561 int x = chunklist[i].x(); 02562 int y = chunklist[i].y(); 02563 if (validChunk(x,y)) { 02564 const Q3CanvasItemList* l = chunk(x,y).listPtr(); 02565 for (Q3CanvasItemList::ConstIterator it=l->begin(); it!=l->end(); ++it) { 02566 Q3CanvasItem *g=*it; 02567 if (g != item) { 02568 if (!seen.find(g)) { 02569 seen.replace(g,(void*)1); 02570 if (!exact || item->collidesWith(g)) 02571 result.append(g); 02572 } 02573 } 02574 } 02575 } 02576 } 02577 return result; 02578 }
Here is the call graph for this function:

Paints all canvas items that are in the area clip to painter, using double-buffering if dbuf is true.
e.g. to print the canvas to a printer:
Definition at line 1283 of file q3canvas.cpp.
References drawCanvasArea().
01284 { 01285 if (painter) 01286 drawCanvasArea(clip, painter, dbuf); 01287 }
Here is the call graph for this function:

| void Q3Canvas::addView | ( | Q3CanvasView * | ) | [virtual] |
Definition at line 946 of file q3canvas.cpp.
References Q3PtrList< type >::append(), backgroundColor(), d, htiles, QPixmap::isNull(), pm, Q3CanvasData::viewList, Q3ScrollView::viewport(), and vtiles.
00947 { 00948 d->viewList.append(view); 00949 if (htiles>1 || vtiles>1 || pm.isNull()) 00950 view->viewport()->setBackgroundColor(backgroundColor()); 00951 }
Here is the call graph for this function:

| void Q3Canvas::removeView | ( | Q3CanvasView * | ) | [virtual] |
Definition at line 958 of file q3canvas.cpp.
References d, Q3PtrList< type >::removeRef(), and Q3CanvasData::viewList.
Here is the call graph for this function:

Definition at line 1293 of file q3canvas.cpp.
References area(), chheight, chunk(), chunksize, chwidth, drawBackground(), drawForeground(), Q3CanvasItemList::drawUnique(), height(), QRect::intersected(), Q3CanvasChunk::listPtr(), p, Q3CanvasItemList::sort(), width(), x, and y.
Referenced by drawArea(), and drawViewArea().
01294 { 01295 QRect area=inarea.intersected(QRect(0,0,width(),height())); 01296 01297 if (!p) return; // Nothing to do. 01298 01299 int lx=area.x()/chunksize; 01300 int ly=area.y()/chunksize; 01301 int mx=area.right()/chunksize; 01302 int my=area.bottom()/chunksize; 01303 if (mx>=chwidth) 01304 mx=chwidth-1; 01305 if (my>=chheight) 01306 my=chheight-1; 01307 01308 Q3CanvasItemList allvisible; 01309 01310 // Stores the region within area that need to be drawn. It is relative 01311 // to area.topLeft() (so as to keep within bounds of 16-bit XRegions) 01312 QRegion rgn; 01313 01314 for (int x=lx; x<=mx; x++) { 01315 for (int y=ly; y<=my; y++) { 01316 // Only reset change if all views updating, and 01317 // wholy within area. (conservative: ignore entire boundary) 01318 // 01319 // Disable this to help debugging. 01320 // 01321 if (!p) { 01322 if (chunk(x,y).takeChange()) { 01323 // ### should at least make bands 01324 rgn |= QRegion(x*chunksize-area.x(),y*chunksize-area.y(), 01325 chunksize,chunksize); 01326 allvisible += *chunk(x,y).listPtr(); 01327 } 01328 } else { 01329 allvisible += *chunk(x,y).listPtr(); 01330 } 01331 } 01332 } 01333 allvisible.sort(); 01334 01335 drawBackground(*p,area); 01336 allvisible.drawUnique(*p); 01337 drawForeground(*p,area); 01338 }
Here is the call graph for this function:

| void Q3Canvas::drawViewArea | ( | Q3CanvasView * | view, | |
| QPainter * | p, | |||
| const QRect & | r, | |||
| bool | dbuf | |||
| ) |
Definition at line 1053 of file q3canvas.cpp.
References a, QPalette::Active, QPalette::brush(), QRect::contains(), Q3ScrollView::contentsToViewport(), drawCanvasArea(), QRect::height(), height(), QMatrix::m11(), QMatrix::m12(), QMatrix::m21(), QMatrix::m22(), QMatrix::map(), p, QWidget::palette(), qt_setcliprect(), qt_setclipregion(), QMatrix::translate(), Q3ScrollView::viewport(), QRect::width(), width(), QPalette::Window, Q3CanvasView::worldMatrix(), QRect::x(), QPoint::x(), QRect::y(), and QPoint::y().
Referenced by Q3CanvasView::drawContents().
01054 { 01055 QPoint tl = view->contentsToViewport(QPoint(0,0)); 01056 01057 #ifndef QT_NO_TRANSFORMATIONS 01058 QMatrix wm = view->worldMatrix(); 01059 QMatrix iwm = wm.invert(); 01060 // ivr = covers all chunks in vr 01061 QRect ivr = iwm.map(vr); 01062 QMatrix twm; 01063 twm.translate(tl.x(),tl.y()); 01064 #else 01065 QRect ivr = vr; 01066 #endif 01067 01068 QRect all(0,0,width(),height()); 01069 01070 if (!all.contains(ivr)) { 01071 // Need to clip with edge of canvas. 01072 01073 #ifndef QT_NO_TRANSFORMATIONS 01074 // For translation-only transformation, it is safe to include the right 01075 // and bottom edges, but otherwise, these must be excluded since they 01076 // are not precisely defined (different bresenham paths). 01077 Q3PointArray a; 01078 if (wm.m12()==0.0 && wm.m21()==0.0 && wm.m11() == 1.0 && wm.m22() == 1.0) 01079 a = Q3PointArray(QRect(all.x(),all.y(),all.width()+1,all.height()+1)); 01080 else 01081 a = Q3PointArray(all); 01082 01083 a = (wm*twm).map(a); 01084 #else 01085 Q3PointArray a(QRect(all.x(),all.y(),all.width()+1,all.height()+1)); 01086 #endif 01087 if (view->viewport()->backgroundMode() == NoBackground) { 01088 QRect cvr = vr; cvr.moveBy(tl.x(),tl.y()); 01089 qt_setclipregion(p, QRegion(cvr)-QRegion(a)); 01090 p->fillRect(vr,view->viewport()->palette() 01091 .brush(QPalette::Active,QPalette::Window)); 01092 } 01093 qt_setclipregion(p, a); 01094 } 01095 01096 QRect r = vr; r.moveBy(tl.x(),tl.y()); // move to untransformed co-ords 01097 if (!all.contains(ivr)) { 01098 QRegion inside = p->clipRegion() & r; 01099 //QRegion outside = p->clipRegion() - r; 01100 //p->setClipRegion(outside); 01101 //p->fillRect(outside.boundingRect(),red); 01102 qt_setclipregion(p, inside); 01103 } else { 01104 qt_setcliprect(p, r); 01105 } 01106 #ifndef QT_NO_TRANSFORMATIONS 01107 p->setWorldMatrix(wm*twm); 01108 #else 01109 #endif 01110 drawCanvasArea(ivr,p,false); 01111 }
Here is the call graph for this function:

| void Q3Canvas::addItem | ( | Q3CanvasItem * | ) | [virtual] |
Definition at line 906 of file q3canvas.cpp.
References d, and Q3CanvasData::itemDict.
Referenced by Q3CanvasItem::Q3CanvasItem(), and Q3CanvasItem::setCanvas().
| void Q3Canvas::addAnimation | ( | Q3CanvasItem * | ) | [virtual] |
Definition at line 916 of file q3canvas.cpp.
References Q3CanvasData::animDict, and d.
Referenced by Q3CanvasItem::setAnimated(), and Q3CanvasItem::setCanvas().
| void Q3Canvas::removeItem | ( | Q3CanvasItem * | ) | [virtual] |
Definition at line 936 of file q3canvas.cpp.
References d, and Q3CanvasData::itemDict.
Referenced by Q3CanvasItem::setCanvas(), and Q3CanvasItem::~Q3CanvasItem().
| void Q3Canvas::removeAnimation | ( | Q3CanvasItem * | ) | [virtual] |
Definition at line 926 of file q3canvas.cpp.
References Q3CanvasData::animDict, and d.
Referenced by Q3CanvasItem::setAnimated(), Q3CanvasItem::setCanvas(), and Q3CanvasItem::~Q3CanvasItem().
| void Q3Canvas::setAdvancePeriod | ( | int | ms | ) | [virtual] |
Sets the canvas to call advance() every ms milliseconds. Any previous setting by setAdvancePeriod() or setUpdatePeriod() is overridden.
If ms is less than 0 advancing will be stopped.
Definition at line 970 of file q3canvas.cpp.
References advance(), QObject::connect(), SIGNAL, SLOT, QTimer::start(), QTimer::stop(), and update_timer.
00971 { 00972 if (ms<0) { 00973 if (update_timer) 00974 update_timer->stop(); 00975 } else { 00976 if (update_timer) 00977 delete update_timer; 00978 update_timer = new QTimer(this); 00979 connect(update_timer,SIGNAL(timeout()),this,SLOT(advance())); 00980 update_timer->start(ms); 00981 } 00982 }
Here is the call graph for this function:

| void Q3Canvas::setUpdatePeriod | ( | int | ms | ) | [virtual] |
Sets the canvas to call update() every ms milliseconds. Any previous setting by setAdvancePeriod() or setUpdatePeriod() is overridden.
If ms is less than 0 automatic updating will be stopped.
Definition at line 991 of file q3canvas.cpp.
References QObject::connect(), SIGNAL, SLOT, QTimer::start(), QTimer::stop(), update(), and update_timer.
00992 { 00993 if (ms<0) { 00994 if (update_timer) 00995 update_timer->stop(); 00996 } else { 00997 if (update_timer) 00998 delete update_timer; 00999 update_timer = new QTimer(this); 01000 connect(update_timer,SIGNAL(timeout()),this,SLOT(update())); 01001 update_timer->start(ms); 01002 } 01003 }
Here is the call graph for this function:

| void Q3Canvas::setDoubleBuffering | ( | bool | y | ) | [virtual] |
If y is true (the default) double-buffering is switched on; otherwise double-buffering is switched off.
Turning off double-buffering causes the redrawn areas to flicker a little and also gives a (usually small) performance improvement.
Definition at line 1571 of file q3canvas.cpp.
References dblbuf.
| void Q3Canvas::resized | ( | ) | [signal] |
This signal is emitted whenever the canvas is resized. Each Q3CanvasView connects to this signal to keep the scrollview's size correct.
Referenced by resize().
| void Q3Canvas::advance | ( | ) | [virtual, slot] |
Moves all Q3CanvasItem::animated() canvas items on the canvas and refreshes all changes to all views of the canvas. (An `animated' item is an item that is in motion; see setVelocity().)
The advance takes place in two phases. In phase 0, the Q3CanvasItem::advance() function of each Q3CanvasItem::animated() canvas item is called with paramater 0. Then all these canvas items are called again, with parameter 1. In phase 0, the canvas items should not change position, merely examine other items on the canvas for which special processing is required, such as collisions between items. In phase 1, all canvas items should change positions, ignoring any other items on the canvas. This two-phase approach allows for considerations of "fairness", although no Q3CanvasItem subclasses supplied with Qt do anything interesting in phase 0.
The canvas can be configured to call this function periodically with setAdvancePeriod().
Definition at line 1027 of file q3canvas.cpp.
References Q3CanvasData::animDict, Q3PtrDictIterator< type >::current(), Q3PtrDictIterator< type >::currentKey(), d, i, Q3PtrDictIterator< type >::toFirst(), and update().
Referenced by setAdvancePeriod().
01028 { 01029 Q3PtrDictIterator<void> it=d->animDict; 01030 while (it.current()) { 01031 Q3CanvasItem* i = (Q3CanvasItem*)(void*)it.currentKey(); 01032 ++it; 01033 if (i) 01034 i->advance(0); 01035 } 01036 // we expect the dict contains the exact same items as in the 01037 // first pass. 01038 it.toFirst(); 01039 while (it.current()) { 01040 Q3CanvasItem* i = (Q3CanvasItem*)(void*)it.currentKey(); 01041 ++it; 01042 if (i) 01043 i->advance(1); 01044 } 01045 update(); 01046 }
| void Q3Canvas::update | ( | ) | [virtual, slot] |
Repaints changed areas in all views of the canvas.
Definition at line 1118 of file q3canvas.cpp.
References Q3PtrList< type >::append(), area(), changeBounds(), Q3ScrollView::contentsX(), Q3ScrollView::contentsY(), Q3PtrListIterator< type >::current(), d, Q3PtrList< type >::first(), Q3CanvasView::inverseWorldMatrix(), QMatrix::map(), Q3PtrList< type >::next(), Q3PtrCollection::setAutoDelete(), setUnchanged(), QWidget::update(), Q3CanvasData::viewList, Q3ScrollView::viewport(), Q3ScrollView::visibleHeight(), Q3ScrollView::visibleWidth(), and Q3CanvasView::worldMatrix().
Referenced by advance(), and setUpdatePeriod().
01119 { 01120 // ##### fix QT_NO_TRANSFORMATIONS 01121 #ifndef QT_NO_TRANSFORMATIONS 01122 Q3PtrList<QRect> doneareas; 01123 doneareas.setAutoDelete(true); 01124 #endif 01125 01126 Q3PtrListIterator<Q3CanvasView> it(d->viewList); 01127 Q3CanvasView* view; 01128 while((view=it.current()) != 0) { 01129 ++it; 01130 #ifndef QT_NO_TRANSFORMATIONS 01131 QMatrix wm = view->worldMatrix(); 01132 #endif 01133 QRect area(view->contentsX(),view->contentsY(), 01134 view->visibleWidth(),view->visibleHeight()); 01135 if (area.width()>0 && area.height()>0) { 01136 #ifndef QT_NO_TRANSFORMATIONS 01137 // r = Visible area of the canvas where there are changes 01138 QRect r = changeBounds(view->inverseWorldMatrix().map(area)); 01139 if (!r.isEmpty()) { 01140 QRect tr = wm.map(r); 01141 tr.moveBy(-view->contentsX(), -view->contentsY()); 01142 view->viewport()->update(tr); 01143 doneareas.append(new QRect(r)); 01144 } 01145 #endif 01146 } 01147 } 01148 01149 #ifndef QT_NO_TRANSFORMATIONS 01150 for (QRect* r=doneareas.first(); r != 0; r=doneareas.next()) 01151 setUnchanged(*r); 01152 #endif 01153 }
This virtual function is called for all updates of the canvas. It renders any background graphics using the painter painter, in the area clip. If the canvas has a background pixmap or a tiled background, that graphic is used, otherwise the canvas is cleared using the background color.
If the graphics for an area change, you must explicitly call setChanged(const QRect&) for the result to be visible when update() is next called.
Definition at line 1509 of file q3canvas.cpp.
References bgcolor, QRect::bottom(), QPainter::drawPixmap(), QPainter::fillRect(), grid, QPixmap::height(), QRect::height(), i, QPixmap::isNull(), j, QRect::left(), pm, QRect::right(), t, tile(), tileh, tilesHorizontally(), tilesVertically(), tilew, QRect::top(), QRect::width(), QPixmap::width(), QRect::x(), x, QRect::y(), and y.
Referenced by drawCanvasArea().
01510 { 01511 if (pm.isNull()) { 01512 painter.fillRect(clip,bgcolor); 01513 } else if (!grid) { 01514 for (int x=clip.x()/pm.width(); 01515 x<(clip.x()+clip.width()+pm.width()-1)/pm.width(); x++) 01516 { 01517 for (int y=clip.y()/pm.height(); 01518 y<(clip.y()+clip.height()+pm.height()-1)/pm.height(); y++) 01519 { 01520 painter.drawPixmap(x*pm.width(), y*pm.height(),pm); 01521 } 01522 } 01523 } else { 01524 const int x1 = clip.left()/tilew; 01525 int x2 = clip.right()/tilew; 01526 const int y1 = clip.top()/tileh; 01527 int y2 = clip.bottom()/tileh; 01528 01529 const int roww = pm.width()/tilew; 01530 01531 for (int j=y1; j<=y2; j++) { 01532 int jj = j%tilesVertically(); 01533 for (int i=x1; i<=x2; i++) { 01534 int t = tile(i%tilesHorizontally(), jj); 01535 int tx = t % roww; 01536 int ty = t / roww; 01537 painter.drawPixmap(i*tilew, j*tileh, pm, 01538 tx*tilew, ty*tileh, tilew, tileh); 01539 } 01540 } 01541 } 01542 }
Here is the call graph for this function:

This virtual function is called for all updates of the canvas. It renders any foreground graphics using the painter painter, in the area clip.
If the graphics for an area change, you must explicitly call setChanged(const QRect&) for the result to be visible when update() is next called.
The default is to draw nothing.
Definition at line 1555 of file q3canvas.cpp.
References debug_redraw_areas, QPainter::drawRect(), Qt::NoBrush, red, QPainter::setBrush(), and QPainter::setPen().
Referenced by drawCanvasArea().
01556 { 01557 if (debug_redraw_areas) { 01558 painter.setPen(red); 01559 painter.setBrush(NoBrush); 01560 painter.drawRect(clip); 01561 } 01562 }
Here is the call graph for this function:

| void Q3Canvas::init | ( | int | w, | |
| int | h, | |||
| int | chunksze = 16, |
|||
| int | maxclust = 100 | |||
| ) | [private] |
Definition at line 588 of file q3canvas.cpp.
References aheight, awidth, bgcolor, chheight, chunks, chunksize, chwidth, d, dblbuf, debug_redraw_areas, grid, htiles, maxclusters, update_timer, vtiles, and Qt::white.
Referenced by Q3Canvas().
00589 { 00590 d = new Q3CanvasData; 00591 awidth=w; 00592 aheight=h; 00593 chunksize=chunksze; 00594 maxclusters=mxclusters; 00595 chwidth=(w+chunksize-1)/chunksize; 00596 chheight=(h+chunksize-1)/chunksize; 00597 chunks=new Q3CanvasChunk[chwidth*chheight]; 00598 update_timer = 0; 00599 bgcolor = white; 00600 grid = 0; 00601 htiles = 0; 00602 vtiles = 0; 00603 dblbuf = false; 00604 debug_redraw_areas = false; 00605 }
| Q3CanvasChunk & Q3Canvas::chunk | ( | int | i, | |
| int | j | |||
| ) | const [private] |
Definition at line 683 of file q3canvas.cpp.
References chunks, and chwidth.
Referenced by addItemToChunk(), changeBounds(), chunkContaining(), collisions(), drawCanvasArea(), removeItemFromChunk(), setChanged(), setChangedChunk(), setChangedChunkContaining(), and setUnchanged().
| Q3CanvasChunk & Q3Canvas::chunkContaining | ( | int | x, | |
| int | y | |||
| ) | const [private] |
Definition at line 692 of file q3canvas.cpp.
References chunk(), and chunksize.
Referenced by addItemToChunkContaining(), removeItemFromChunkContaining(), and setChangedChunkContaining().
Here is the call graph for this function:

Definition at line 1223 of file q3canvas.cpp.
References area(), chheight, chunk(), chunksize, chwidth, Q3CanvasChunk::hasChanged(), height(), QRect::intersected(), QRect::isEmpty(), width(), x, and y.
Referenced by update().
01224 { 01225 QRect area = inarea.intersected(QRect(0, 0, width(), height())); 01226 01227 int mx = (area.x()+area.width()+chunksize)/chunksize; 01228 int my = (area.y()+area.height()+chunksize)/chunksize; 01229 if (mx > chwidth) 01230 mx=chwidth; 01231 if (my > chheight) 01232 my=chheight; 01233 01234 QRect result; 01235 01236 int x=area.x()/chunksize; 01237 while(x<mx) { 01238 int y=area.y()/chunksize; 01239 while(y<my) { 01240 Q3CanvasChunk& ch=chunk(x,y); 01241 if (ch.hasChanged()) 01242 result |= QRect(x,y,1,1); 01243 y++; 01244 } 01245 x++; 01246 } 01247 01248 if (!result.isEmpty()) { 01249 result.rLeft() *= chunksize; 01250 result.rTop() *= chunksize; 01251 result.rRight() *= chunksize; 01252 result.rBottom() *= chunksize; 01253 result.rRight() += chunksize; 01254 result.rBottom() += chunksize; 01255 } 01256 01257 return result; 01258 }
Here is the call graph for this function:

| void Q3Canvas::ensureOffScrSize | ( | int | osw, | |
| int | osh | |||
| ) | [private] |
Definition at line 1260 of file q3canvas.cpp.
References QPixmap::height(), offscr, and QPixmap::width().
01261 { 01262 if (osw > offscr.width() || osh > offscr.height()) 01263 offscr.resize(QMAX(osw,offscr.width()), 01264 QMAX(osh,offscr.height())); 01265 else if (offscr.width() == 0 || offscr.height() == 0) 01266 offscr.resize(QMAX(offscr.width(), 1), 01267 QMAX(offscr.height(), 1)); 01268 }
Here is the call graph for this function:

| void Q3Canvas::initTiles | ( | QPixmap | p, | |
| int | h, | |||
| int | v, | |||
| int | tilewidth, | |||
| int | tileheight | |||
| ) | [private] |
| void qt_unview | ( | Q3Canvas * | c | ) | [friend] |
Definition at line 658 of file q3canvas.cpp.
Referenced by ~Q3Canvas().
00659 { 00660 for (Q3CanvasView* view=c->d->viewList.first(); view != 0; view=c->d->viewList.next()) { 00661 view->viewing = 0; 00662 } 00663 }
QPixmap Q3Canvas::offscr [private] |
int Q3Canvas::awidth [private] |
int Q3Canvas::aheight [private] |
int Q3Canvas::chunksize [private] |
Definition at line 299 of file q3canvas.h.
Referenced by changeBounds(), chunkContaining(), drawCanvasArea(), init(), resize(), retune(), setChanged(), setTile(), and setUnchanged().
int Q3Canvas::maxclusters [private] |
int Q3Canvas::chwidth [private] |
Definition at line 301 of file q3canvas.h.
Referenced by changeBounds(), chunk(), drawCanvasArea(), init(), resize(), retune(), setChanged(), and setUnchanged().
int Q3Canvas::chheight [private] |
Definition at line 301 of file q3canvas.h.
Referenced by changeBounds(), drawCanvasArea(), init(), resize(), retune(), setChanged(), and setUnchanged().
Q3CanvasChunk* Q3Canvas::chunks [private] |
Definition at line 302 of file q3canvas.h.
Referenced by chunk(), init(), resize(), retune(), and ~Q3Canvas().
Q3CanvasData* Q3Canvas::d [private] |
Definition at line 304 of file q3canvas.h.
Referenced by addAnimation(), addItem(), addView(), advance(), allItems(), init(), removeAnimation(), removeItem(), removeView(), resize(), retune(), setBackgroundColor(), setBackgroundPixmap(), update(), and ~Q3Canvas().
ushort* Q3Canvas::grid [private] |
Definition at line 307 of file q3canvas.h.
Referenced by drawBackground(), init(), setTile(), setTiles(), and ~Q3Canvas().
ushort Q3Canvas::htiles [private] |
Definition at line 308 of file q3canvas.h.
Referenced by addView(), init(), setTile(), and setTiles().
ushort Q3Canvas::vtiles [private] |
ushort Q3Canvas::tilew [private] |
Definition at line 310 of file q3canvas.h.
Referenced by drawBackground(), setTile(), and setTiles().
ushort Q3Canvas::tileh [private] |
Definition at line 311 of file q3canvas.h.
Referenced by drawBackground(), setTile(), and setTiles().
bool Q3Canvas::oneone [private] |
Definition at line 312 of file q3canvas.h.
QPixmap Q3Canvas::pm [private] |
Definition at line 313 of file q3canvas.h.
Referenced by addView(), backgroundPixmap(), drawBackground(), and setTiles().
QTimer* Q3Canvas::update_timer [private] |
Definition at line 314 of file q3canvas.h.
Referenced by init(), setAdvancePeriod(), and setUpdatePeriod().
QColor Q3Canvas::bgcolor [private] |
Definition at line 315 of file q3canvas.h.
Referenced by backgroundColor(), drawBackground(), init(), and setBackgroundColor().
bool Q3Canvas::debug_redraw_areas [private] |
bool Q3Canvas::dblbuf [private] |
1.5.1