Q3CanvasView Class

The Q3CanvasView class provides an on-screen view of a Q3Canvas . 更多...

头: #include <Q3CanvasView>
继承: Q3ScrollView

公共函数

Q3CanvasView (QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)
Q3CanvasView (Q3Canvas * canvas , QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)
~Q3CanvasView ()
Q3Canvas * canvas () const
const QMatrix & inverseWorldMatrix () const
void setCanvas (Q3Canvas * canvas )
bool setWorldMatrix (const QMatrix & wm )
const QMatrix & worldMatrix () const

重实现保护函数

virtual void drawContents (QPainter * p , int cx , int cy , int cw , int ch )
virtual QSize sizeHint () const

额外继承成员

详细描述

The Q3CanvasView class provides an on-screen view of a Q3Canvas .

A Q3CanvasView is widget which provides a view of a Q3Canvas .

If you want users to be able to interact with a canvas view, subclass Q3CanvasView . You might then reimplement Q3ScrollView::contentsMousePressEvent ()。例如:

void MyCanvasView::contentsMousePressEvent(QMouseEvent* e)
{
    Q3CanvasItemList l = canvas()->collisions(e->pos());
    for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
        if ((*it)->rtti() == Q3CanvasRectangle::RTTI)
            qDebug("A Q3CanvasRectangle lies somewhere at this point");
    }
}
					

The canvas view shows canvas canvas (); this can be changed using setCanvas ().

A transformation matrix can be used to transform the view of the canvas in various ways, for example, zooming in or out or rotating. For example:

QMatrix wm;
wm.scale(2, 2);   // Zooms in by 2 times
wm.rotate(90);    // Rotates 90 degrees counter clockwise
                  // around the origin.
wm.translate(0, -canvas->height());
                  // moves the canvas down so what was visible
                  // before is still visible.
myCanvasView->setWorldMatrix(wm);
					

使用 setWorldMatrix () to set the canvas view's world matrix: you must ensure that the world matrix is invertible. The current world matrix is retrievable with worldMatrix (), and its inversion is retrievable with inverseWorldMatrix ().

范例:

The following code finds the part of the canvas that is visible in this view, i.e. the bounding rectangle of the view in canvas coordinates.

QRect rc = QRect(myCanvasView->contentsX(), myCanvasView->contentsY(),
                 myCanvasView->visibleWidth(), myCanvasView->visibleHeight());
QRect canvasRect = myCanvasView->inverseWorldMatrix().mapRect(rc);
					

另请参阅 QMatrix , QPainter::setWorldMatrix (), QtCanvas ,和 Porting to Graphics View .

成员函数文档编制

Q3CanvasView:: Q3CanvasView ( QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)

构造 Q3CanvasView 采用父级 parent , and name name , using the widget flags f . The canvas view is not associated with a canvas, so you must to call setCanvas () to view a canvas.

Q3CanvasView:: Q3CanvasView ( Q3Canvas * canvas , QWidget * parent = 0, const char * name = 0, Qt::WindowFlags f = 0)

这是重载函数。

构造 Q3CanvasView which views canvas canvas ,采用父级 parent , and name name , using the widget flags f .

Q3CanvasView:: ~Q3CanvasView ()

Destroys the canvas view. The associated canvas is not deleted.

Q3Canvas * Q3CanvasView:: canvas () const

Returns a pointer to the canvas which the Q3CanvasView is currently showing.

另请参阅 setCanvas ().

[virtual protected] void Q3CanvasView:: drawContents ( QPainter * p , int cx , int cy , int cw , int ch )

重实现自 Q3ScrollView::drawContents ().

Repaints part of the Q3Canvas that the canvas view is showing starting at cx by cy , with a width of cw 和高度 ch using the painter p .

const QMatrix & Q3CanvasView:: inverseWorldMatrix () const

Returns a reference to the inverse of the canvas view's current transformation matrix.

另请参阅 setWorldMatrix () 和 worldMatrix ().

void Q3CanvasView:: setCanvas ( Q3Canvas * canvas )

Sets the canvas that the Q3CanvasView is showing to the canvas canvas .

另请参阅 canvas ().

bool Q3CanvasView:: setWorldMatrix (const QMatrix & wm )

Sets the transformation matrix of the Q3CanvasView to wm . The matrix must be invertible (i.e. if you create a world matrix that zooms out by 2 times, then the inverse of this matrix is one that will zoom in by 2 times).

When you use this, you should note that the performance of the Q3CanvasView will decrease considerably.

Returns false if wm is not invertable; otherwise returns true.

另请参阅 worldMatrix (), inverseWorldMatrix (),和 QMatrix::isInvertible ().

[virtual protected] QSize Q3CanvasView:: sizeHint () const

重实现自 QWidget::sizeHint ().

Suggests a size sufficient to view the entire canvas.

const QMatrix & Q3CanvasView:: worldMatrix () const

Returns a reference to the canvas view's current transformation matrix.

另请参阅 setWorldMatrix () 和 inverseWorldMatrix ().