⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3canvas.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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.    \sa setBackgroundColor(), backgroundPixmap()*/QColor Q3Canvas::backgroundColor() const{    return bgcolor;}/*!    Sets the solid background to be the color \a c.    \sa backgroundColor(), setBackgroundPixmap(), setTiles()*/void Q3Canvas::setBackgroundColor(const QColor& c){    if (bgcolor != c) {	bgcolor = c;	Q3CanvasView* view=d->viewList.first();	while (view != 0) {	    /* XXX this doesn't look right. Shouldn't this	       be more like setBackgroundPixmap? : Ian */	    view->viewport()->setEraseColor(bgcolor);	    view=d->viewList.next();	}	setAllChanged();    }}/*!    Returns the pixmap set by setBackgroundPixmap(). By default,    this is a null pixmap.    \sa setBackgroundPixmap(), backgroundColor()*/QPixmap Q3Canvas::backgroundPixmap() const{    return pm;}/*!    Sets the solid background to be the pixmap \a p repeated as    necessary to cover the entire canvas.    \sa backgroundPixmap(), setBackgroundColor(), setTiles()*/void Q3Canvas::setBackgroundPixmap(const QPixmap& p){    setTiles(p, 1, 1, p.width(), p.height());    Q3CanvasView* view = d->viewList.first();    while (view != 0) {	view->updateContents();	view = d->viewList.next();    }}/*!    This virtual function is called for all updates of the canvas. It    renders any background graphics using the painter \a painter, in    the area \a 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.    \sa setBackgroundColor(), setBackgroundPixmap(), setTiles()*/void Q3Canvas::drawBackground(QPainter& painter, const QRect& clip){    if (pm.isNull()) {	painter.fillRect(clip,bgcolor);    } else if (!grid) {	for (int x=clip.x()/pm.width();	    x<(clip.x()+clip.width()+pm.width()-1)/pm.width(); x++)	{	    for (int y=clip.y()/pm.height();		y<(clip.y()+clip.height()+pm.height()-1)/pm.height(); y++)	    {		painter.drawPixmap(x*pm.width(), y*pm.height(),pm);	    }	}    } else {	const int x1 = clip.left()/tilew;	int x2 = clip.right()/tilew;	const int y1 = clip.top()/tileh;	int y2 = clip.bottom()/tileh;	const int roww = pm.width()/tilew;	for (int j=y1; j<=y2; j++) {	    int jj = j%tilesVertically();	    for (int i=x1; i<=x2; i++) {		int t = tile(i%tilesHorizontally(), jj);		int tx = t % roww;		int ty = t / roww;		painter.drawPixmap(i*tilew, j*tileh, pm,				tx*tilew, ty*tileh, tilew, tileh);	    }	}    }}/*!    This virtual function is called for all updates of the canvas. It    renders any foreground graphics using the painter \a painter, in    the area \a 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.*/void Q3Canvas::drawForeground(QPainter& painter, const QRect& clip){    if (debug_redraw_areas) {	painter.setPen(red);	painter.setBrush(NoBrush);	painter.drawRect(clip);    }}/*!    If \a 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.*/void Q3Canvas::setDoubleBuffering(bool y){    dblbuf = y;}/*!    Sets the Q3Canvas to be composed of \a h tiles horizontally and \a    v tiles vertically. Each tile will be an image \a tilewidth by \a    tileheight pixels from pixmap \a p.    The pixmap \a 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.    \table    \row \i 0 \i 1 \i 2 \i 3    \row \i 4 \i 5 \i 6 \i 7    \endtable    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 \a p must be a multiple of \a tilewidth    and \a 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 \a h, \a v, \a tilewidth, and    \a tileheight.*/void Q3Canvas::setTiles(QPixmap p,			int h, int v, int tilewidth, int tileheight){    if (!p.isNull() && (!tilewidth || !tileheight ||	 p.width() % tilewidth != 0 || p.height() % tileheight != 0))    	return;    htiles = h;    vtiles = v;    delete[] grid;    pm = p;    if (h && v && !p.isNull()) {	grid = new ushort[h*v];	memset(grid, 0, h*v*sizeof(ushort));	tilew = tilewidth;	tileh = tileheight;    } else {	grid = 0;    }    if (h + v > 10) {	int s = scm(tilewidth,tileheight);	retune(s < 128 ? s : QMAX(tilewidth,tileheight));    }    setAllChanged();}/*!    \fn int Q3Canvas::tile(int x, int y) const    Returns the tile at position (\a x, \a y). Initially, all tiles    are 0.    The parameters must be within range, i.e.	0 \< \a x \< tilesHorizontally() and	0 \< \a y \< tilesVertically().    \sa setTile()*//*!    \fn int Q3Canvas::tilesHorizontally() const    Returns the number of tiles horizontally.*//*!    \fn int Q3Canvas::tilesVertically() const    Returns the number of tiles vertically.*//*!    \fn int Q3Canvas::tileWidth() const    Returns the width of each tile.*//*!    \fn int Q3Canvas::tileHeight() const    Returns the height of each tile.*//*!    Sets the tile at (\a x, \a y) to use tile number \a 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.    \table    \row \i 0 \i 1 \i 2 \i 3    \row \i 4 \i 5 \i 6 \i 7    \endtable    \sa tile() setTiles()*/void Q3Canvas::setTile(int x, int y, int tilenum){    ushort& t = grid[x+y*htiles];    if (t != tilenum) {	t = tilenum;	if (tilew == tileh && tilew == chunksize)	    setChangedChunk(x, y);	    // common case	else	    setChanged(QRect(x*tilew,y*tileh,tilew,tileh));    }}// lesser-used data in canvas item, plus room for extension.// Be careful adding to this - check all usages.class Q3CanvasItemExtra {    Q3CanvasItemExtra() : vx(0.0), vy(0.0) { }    double vx,vy;    friend class Q3CanvasItem;};/*!    \class Q3CanvasItem qcanvas.h    \compat    \brief The Q3CanvasItem class provides an abstract graphic object on a Q3Canvas.    A variety of Q3CanvasItem 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.    Q3CanvasItem is not intended for direct subclassing. It is much easier    to subclass one of its subclasses, e.g. Q3CanvasPolygonalItem (the    commonest base class), Q3CanvasRectangle, Q3CanvasSprite, Q3CanvasEllipse    or Q3CanvasText.    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().    Items appear on the canvas after their \link show() show()\endlink    function has been called (or \link setVisible()    setVisible(true)\endlink), and \e after update() has been called. The    canvas only shows items that are \link setVisible() visible\endlink,    and then only if \l update() is called. If you created the canvas    without passing a width and height to the constructor you'll also need    to call \link Q3Canvas::resize() resize()\endlink. Since the canvas    background defaults to white and canvas items default to white,    you may need to change colors to see your items.    A Q3CanvasItem 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 \e next advance(1) and use collisions() to see what    collisions have occurred.    Use Q3CanvasSprite or your own subclass of Q3CanvasSprite to create canvas    items which are animated, i.e. which change over time.    The size of a canvas item is given by boundingRect(). Use    boundingRectAdvanced() to see what the size of the canvas item will be    \e after the next advance(1) call.    The rtti() function is used for identifying subclasses of Q3CanvasItem.    The canvas() function returns a pointer to the canvas which contains the    canvas item.    Q3CanvasItem provides the show() and isVisible() functions like those in    QWidget.    Q3CanvasItem 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    Q3CanvasItem itself. You can make use of these booleans in your subclasses.    By default, canvas items have no velocity, no size, and are not in    motion. The subclasses provided in Qt do not change these defaults    except where noted.    \sa QtCanvas, {Porting to Graphics View}*//*!    \enum Q3CanvasItem::RttiValues    This enum is used to name the different types of canvas item.    \value Rtti_Item Canvas item abstract base class    \value Rtti_Ellipse    \value Rtti_Line    \value Rtti_Polygon    \value Rtti_PolygonalItem    \value Rtti_Rectangle    \value Rtti_Spline    \value Rtti_Sprite    \value Rtti_Text*//*!    \fn void Q3CanvasItem::update()    Call this function to repaint the canvas's changed chunks.*//*!    Constructs a Q3CanvasItem on canvas \a canvas.    \sa setCanvas()*/Q3CanvasItem::Q3CanvasItem(Q3Canvas* canvas) :    cnv(canvas),    myx(0),myy(0),myz(0){    ani=0;    vis=0;    val=0;    sel=0;    ena=0;    act=0;    ext = 0;    if (cnv) cnv->addItem(this);}/*!    Destroys the Q3CanvasItem and removes it from its canvas.*/Q3CanvasItem::~Q3CanvasItem(){    if (cnv) {	cnv->removeItem(this);	cnv->removeAnimation(this);    }    delete ext;}Q3CanvasItemExtra& Q3CanvasItem::extra(){    if (!ext)	ext = new Q3CanvasItemExtra;    return *ext;}/*!    \fn double Q3CanvasItem::x() const    Returns the horizontal position of the canvas item. Note that    subclasses often have an origin other than the top-left corner.*//*!    \fn double Q3CanvasItem::y() const    Returns the vertical position of the canvas item. Note that    subclasses often have an origin other than the top-left corner.*//*!    \fn double Q3CanvasItem::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.*//*!    \fn void Q3CanvasItem::setX(double x)    Moves the canvas item so that its x-position is \a x.    \sa x(), move()*//*!    \fn void Q3CanvasItem::setY(double y)    Moves the canvas item so that its y-position is \a y.    \sa y(), move()*//*!    \fn void Q3CanvasItem::setZ(double z)    Sets the z index of the canvas item to \a z. Higher-z items    obscure (are in front of) lower-z items.    \sa z(), move()*//*!    Moves the canvas item relative to its current position by (\a dx,    \a dy).*/void Q3CanvasItem::moveBy(double dx, double dy){    if (dx || dy) {	removeFromChunks();	myx += dx;	myy += dy;	addToChunks();    }}/*!    Moves the canvas item to the absolute position (\a x, \a y).*/void Q3CanvasItem::move(double x, double y){    moveBy(x-myx, y-myy);}/*!    Returns true if the canvas item is in motion; otherwise returns    false.    \sa setVelocity(), setAnimated()*/bool Q3CanvasItem::animated() const{    return (bool)ani;}/*!    Sets the canvas item to be in motion if \a y is true, or not if \a    y is false. The speed and direction of the motion is set with    setVelocity(), or with setXVelocity() and setYVelocity().    \sa advance(), Q3Canvas::advance()*/void Q3CanvasItem::setAnimated(bool y)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -