QtCanvasView Class Reference

The QtCanvasView class provides an on-screen view of a QtCanvas. More...

#include <QtCanvasView>

Inherits QScrollArea.

Properties

Public Functions

Public Slots

Protected Functions

Additional Inherited Members


Detailed Description

The QtCanvasView class provides an on-screen view of a QtCanvas.

A QtCanvasView is widget which provides a view of a QtCanvas.

If you want users to be able to interact with a canvas view, subclass QtCanvasView. You might then reimplement QtScrollView::contentsMousePressEvent(). For example:

    void MyCanvasView::contentsMousePressEvent(QMouseEvent* e)
    {
        QtCanvasItemList l = canvas()->collisions(e->pos());
        for (QtCanvasItemList::Iterator it = l.begin(); it!= l.end(); ++it) {
            if ((*it)->rtti() == QtCanvasRectangle::RTTI)
                qDebug("A QtCanvasRectangle 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);

Use 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().

Example:

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);

See also QMatrix and QPainter::setWorldMatrix().


Property Documentation

highQualityRendering : bool

This property holds whether high quality rendering is turned on.

If high quality rendering is turned on, the canvas view will paint itself using the QPainter::Antialiasing and QPainter::SmoothPixmapTransform rendering flags.

Enabling these flag will usually improve the visual appearance on the screen at the cost of rendering speed.

Access functions:


Member Function Documentation

QtCanvasView::QtCanvasView ( QWidget * parent = 0 )

Constructs a QtCanvasView with parent parent. The canvas view is not associated with a canvas, so you must to call setCanvas() to view a canvas.

QtCanvasView::QtCanvasView ( QtCanvas * canvas, QWidget * parent = 0 )

Constructs a QtCanvasView which views canvas canvas, with parent parent.

QtCanvasView::~QtCanvasView ()

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

QtCanvas * QtCanvasView::canvas () const

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

See also setCanvas().

void QtCanvasView::contentsContextMenuEvent ( QContextMenuEvent * )   [virtual protected]

void QtCanvasView::contentsDragEnterEvent ( QDragEnterEvent * )   [virtual protected]

void QtCanvasView::contentsDragLeaveEvent ( QDragLeaveEvent * )   [virtual protected]

void QtCanvasView::contentsDragMoveEvent ( QDragMoveEvent * )   [virtual protected]

void QtCanvasView::contentsDropEvent ( QDropEvent * )   [virtual protected]

void QtCanvasView::contentsMouseDoubleClickEvent ( QMouseEvent * )   [virtual protected]

void QtCanvasView::contentsMouseMoveEvent ( QMouseEvent * )   [virtual protected]

void QtCanvasView::contentsMousePressEvent ( QMouseEvent * )   [virtual protected]

void QtCanvasView::contentsMouseReleaseEvent ( QMouseEvent * )   [virtual protected]

void QtCanvasView::contentsWheelEvent ( QWheelEvent * )   [virtual protected]

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

Repaints part of the QtCanvas that the canvas view is showing starting at cx by cy, with a width of cw and a height of ch using the painter p.

const QMatrix & QtCanvasView::inverseWorldMatrix () const

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

See also setWorldMatrix() and worldMatrix().

void QtCanvasView::setCanvas ( QtCanvas * canvas )

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

See also canvas().

bool QtCanvasView::setWorldMatrix ( const QMatrix & wm )

Sets the transformation matrix of the QtCanvasView 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 QtCanvasView will decrease considerably.

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

See also worldMatrix(), inverseWorldMatrix(), and QMatrix::isInvertible().

QSize QtCanvasView::sizeHint () const   [virtual]

Suggests a size sufficient to view the entire canvas.

Reimplemented from QWidget.

const QMatrix & QtCanvasView::worldMatrix () const

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

See also setWorldMatrix() and inverseWorldMatrix().


Copyright © 2005 Trolltech Trademarks