Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQCanvasView Class Reference
[canvas module]

The TQCanvasView class provides an on-screen view of a TQCanvas. More...

`#include <ntqcanvas.h>`

Inherits TQScrollView.

List of all member functions.

## Public Members

- TQCanvasView ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- TQCanvasView ( TQCanvas * canvas, TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- ~TQCanvasView ()
- TQCanvas * canvas () const
- void setCanvas ( TQCanvas * canvas )
- const TQWMatrix & worldMatrix () const
- const TQWMatrix & inverseWorldMatrix () const
- bool setWorldMatrix ( const TQWMatrix & wm )

## Protected Members

- virtual void drawContents ( TQPainter * p, int cx, int cy, int cw, int ch )
- virtual TQSize sizeHint () const

## Detailed Description

The TQCanvasView class provides an on-screen view of a TQCanvas.

A TQCanvasView is widget which provides a view of a TQCanvas.

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

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

        TQWMatrix 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.

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

See also TQWMatrix, TQPainter::setWorldMatrix(), Graphics Classes, and Image Processing Classes.

## Member Function Documentation

### TQCanvasView::TQCanvasView ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )

Constructs a TQCanvasView 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.

### TQCanvasView::TQCanvasView ( TQCanvas * canvas, TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Constructs a TQCanvasView which views canvas canvas, with parent parent, and name name, using the widget flags f.

### TQCanvasView::~TQCanvasView ()

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

### TQCanvas * TQCanvasView::canvas () const

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

### void TQCanvasView::drawContents ( TQPainter * p, int cx, int cy, int cw, int ch )`[virtual protected]`

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

Warning: 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 TQCanvas::update() bypasses drawContents(), which means any reimplementation of drawContents() is not called.

See also TQCanvas::setDoubleBuffering().

Reimplemented from TQScrollView.

### const TQWMatrix & TQCanvasView::inverseWorldMatrix () const

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

See also setWorldMatrix() and worldMatrix().

### void TQCanvasView::setCanvas ( TQCanvas * canvas )

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

### bool TQCanvasView::setWorldMatrix ( const TQWMatrix & wm )

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

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

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

Example: canvas/canvas.cpp.

### TQSize TQCanvasView::sizeHint () const`[virtual protected]`

Suggests a size sufficient to view the entire canvas.

### const TQWMatrix & TQCanvasView::worldMatrix () const

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

See also setWorldMatrix() and inverseWorldMatrix().

Example: canvas/canvas.cpp.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.