Eneboo - Documentación para desarrolladores
Métodos públicos | Métodos protegidos | Amigas
Referencia de la Clase QCanvasView

The QCanvasView class provides an on-screen view of a QCanvas.canvasA QCanvasView is widget which provides a view of a QCanvas. Más...

#include <qcanvas.h>

Diagrama de herencias de QCanvasView
QScrollView QScrollView QFrame QFrame QFrame QFrame QWidget QWidget QWidget QWidget QWidget QWidget QWidget QWidget

Lista de todos los miembros.

Métodos públicos

 QCanvasView (QWidget *parent=0, const char *name=0, WFlags f=0)
 QCanvasView (QCanvas *viewing, QWidget *parent=0, const char *name=0, WFlags f=0)
 ~QCanvasView ()
QCanvascanvas () const
void setCanvas (QCanvas *v)
const QWMatrixworldMatrix () const
const QWMatrixinverseWorldMatrix () const
bool setWorldMatrix (const QWMatrix &)
 QCanvasView (QWidget *parent=0, const char *name=0, WFlags f=0)
 QCanvasView (QCanvas *viewing, QWidget *parent=0, const char *name=0, WFlags f=0)
 ~QCanvasView ()
QCanvascanvas () const
void setCanvas (QCanvas *v)
const QWMatrixworldMatrix () const
const QWMatrixinverseWorldMatrix () const
bool setWorldMatrix (const QWMatrix &)

Métodos protegidos

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

Amigas

void qt_unview (QCanvas *c)
void qt_unview (QCanvas *c)

Descripción detallada

The QCanvasView class provides an on-screen view of a QCanvas.

canvas

A QCanvasView is widget which provides a view of a QCanvas.

If you want users to be able to interact with a canvas view, subclass QCanvasView. You might then reimplement QScrollView::contentsMousePressEvent(). For example, assuming no transformation matrix is set:

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

    QWMatrix 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);
Ver también:
QWMatrix QPainter::setWorldMatrix()

Documentación del constructor y destructor

QCanvasView::QCanvasView ( QWidget parent = 0,
const char *  name = 0,
WFlags  f = 0 
)

Constructs a QCanvasView with parent 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.

QCanvasView::QCanvasView ( QCanvas canvas,
QWidget parent = 0,
const char *  name = 0,
WFlags  f = 0 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Constructs a QCanvasView which views canvas canvas, with parent parent, and name name, using the widget flags f.

QCanvasView::~QCanvasView ( )

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

QCanvasView::QCanvasView ( QWidget parent = 0,
const char *  name = 0,
WFlags  f = 0 
)
QCanvasView::QCanvasView ( QCanvas viewing,
QWidget parent = 0,
const char *  name = 0,
WFlags  f = 0 
)
QCanvasView::~QCanvasView ( )

Documentación de las funciones miembro

QCanvas * QCanvasView::canvas ( ) const [inline]

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

QCanvas* QCanvasView::canvas ( ) const [inline]
void QCanvasView::drawContents ( QPainter p,
int  cx,
int  cy,
int  cw,
int  ch 
) [protected, virtual]

Repaints part of the QCanvas 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.

Atención:
When double buffering is enabled, drawContents() will not respect the current settings of the painter when setting up the painter for the double buffer (e.g., viewport() and window()). Also, be aware that QCanvas::update() bypasses drawContents(), which means any reimplementation of drawContents() is not called.
Ver también:
QCanvas::setDoubleBuffering()

Reimplementado de QScrollView.

void QCanvasView::drawContents ( QPainter p,
int  clipx,
int  clipy,
int  clipw,
int  cliph 
) [protected, virtual]

Reimplement this function if you are viewing a drawing area rather than a widget.

The function should draw the rectangle (clipx, clipy, clipw, cliph) of the contents using painter p. The clip rectangle is in the scrollview's coordinates.

For example:

    {
        // Fill a 40000 by 50000 rectangle at (100000,150000)

        // Calculate the coordinates...
        int x1 = 100000, y1 = 150000;
        int x2 = x1+40000-1, y2 = y1+50000-1;

        // Clip the coordinates so X/Windows will not have problems...
        if (x1 < clipx) x1=clipx;
        if (y1 < clipy) y1=clipy;
        if (x2 > clipx+clipw-1) x2=clipx+clipw-1;
        if (y2 > clipy+cliph-1) y2=clipy+cliph-1;

        // Paint using the small coordinates...
        if ( x2 >= x1 && y2 >= y1 )
            p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red);
    }

The clip rectangle and translation of the painter p is already set appropriately.

Reimplementado de QScrollView.

const QWMatrix & QCanvasView::inverseWorldMatrix ( ) const

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

Ver también:
setWorldMatrix() worldMatrix()
const QWMatrix& QCanvasView::inverseWorldMatrix ( ) const
void QCanvasView::setCanvas ( QCanvas canvas)

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

void QCanvasView::setCanvas ( QCanvas v)
bool QCanvasView::setWorldMatrix ( const QWMatrix wm)

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

Returns FALSE if wm is not invertable; otherwise returns TRUE.

Ver también:
worldMatrix() inverseWorldMatrix() QWMatrix::isInvertible()
bool QCanvasView::setWorldMatrix ( const QWMatrix )
QSize QCanvasView::sizeHint ( ) const [protected, virtual]

Suggests a size sufficient to view the entire canvas.

Reimplementado de QScrollView.

QSize QCanvasView::sizeHint ( ) const [protected, virtual]

Reimplementado de QScrollView.

const QWMatrix & QCanvasView::worldMatrix ( ) const

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

Ver también:
setWorldMatrix() inverseWorldMatrix()
const QWMatrix& QCanvasView::worldMatrix ( ) const

Documentación de las funciones relacionadas y clases amigas

void qt_unview ( QCanvas c) [friend]
void qt_unview ( QCanvas c) [friend]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'