|
|
Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QCanvasView class provides an on-screen view of a QCanvas. More...
#include <qcanvas.h>
Inherits QScrollView.
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);
See also QWMatrix, QPainter::setWorldMatrix(), Graphics Classes, and Image Processing Classes.
Constructs a QCanvasView which views canvas canvas, with parent parent, and name name, using the widget flags f.
Returns a pointer to the canvas which the QCanvasView is currently showing.
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 QCanvas::update() bypasses drawContents(), which means any reimplementation of drawContents() is not called.
See also QCanvas::setDoubleBuffering().
Reimplemented from QScrollView.
See also setWorldMatrix() and worldMatrix().
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.
See also worldMatrix(), inverseWorldMatrix(), and QWMatrix::isInvertible().
Example: canvas/canvas.cpp.
See also setWorldMatrix() and inverseWorldMatrix().
Example: canvas/canvas.cpp.
This file is part of the Qt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | Qt 3.3.8
|