#include <q3canvas.h>
Inheritance diagram for Q3CanvasView:


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(). For example:
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);
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);
Definition at line 326 of file q3canvas.h.
Public Member Functions | |
| Q3CanvasView (QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0) | |
| Q3CanvasView (Q3Canvas *viewing, QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0) | |
| ~Q3CanvasView () | |
| Q3Canvas * | canvas () const |
| void | setCanvas (Q3Canvas *v) |
| const QMatrix & | worldMatrix () const |
| const QMatrix & | inverseWorldMatrix () const |
| bool | setWorldMatrix (const QMatrix &) |
Protected Member Functions | |
| void | drawContents (QPainter *p, int cx, int cy, int cw, int ch) |
| QSize | sizeHint () const |
Private Slots | |
| void | updateContentsSize () |
Private Member Functions | |
| void | drawContents (QPainter *) |
Private Attributes | |
| Q3Canvas * | viewing |
| Q3CanvasViewData * | d |
Friends | |
| class | Q3Canvas |
| void | qt_unview (Q3Canvas *c) |
| Q3CanvasView::Q3CanvasView | ( | QWidget * | parent = 0, |
|
| const char * | name = 0, |
|||
| Qt::WindowFlags | f = 0 | |||
| ) |
Constructs a Q3CanvasView 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.
Definition at line 3356 of file q3canvas.cpp.
References d, setCanvas(), and viewing.
03357 : Q3ScrollView(parent,name,f|WResizeNoErase|WStaticContents) 03358 { 03359 d = new Q3CanvasViewData; 03360 viewing = 0; 03361 setCanvas(0); 03362 }
Here is the call graph for this function:

| Q3CanvasView::Q3CanvasView | ( | Q3Canvas * | canvas, | |
| QWidget * | parent = 0, |
|||
| const char * | name = 0, |
|||
| Qt::WindowFlags | f = 0 | |||
| ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructs a Q3CanvasView which views canvas canvas, with parent parent, and name name, using the widget flags f.
Definition at line 3370 of file q3canvas.cpp.
References canvas(), d, setCanvas(), and viewing.
03371 : Q3ScrollView(parent,name,f|WResizeNoErase|WStaticContents) 03372 { 03373 d = new Q3CanvasViewData; 03374 viewing = 0; 03375 setCanvas(canvas); 03376 }
Here is the call graph for this function:

| Q3CanvasView::~Q3CanvasView | ( | ) |
Destroys the canvas view. The associated canvas is not deleted.
Definition at line 3381 of file q3canvas.cpp.
References d, and setCanvas().
Here is the call graph for this function:

| Q3Canvas * Q3CanvasView::canvas | ( | ) | const [inline] |
Returns a pointer to the canvas which the Q3CanvasView is currently showing.
Definition at line 335 of file q3canvas.h.
Referenced by Q3CanvasView(), setCanvas(), and sizeHint().
00336 { return viewing; }
| void Q3CanvasView::setCanvas | ( | Q3Canvas * | canvas | ) |
Sets the canvas that the Q3CanvasView is showing to the canvas canvas.
Definition at line 3400 of file q3canvas.cpp.
References canvas(), QObject::connect(), d, QObject::disconnect(), SIGNAL, SLOT, QWidget::update(), updateContentsSize(), and viewing.
Referenced by Q3CanvasView(), and ~Q3CanvasView().
03401 { 03402 if (viewing == canvas) 03403 return; 03404 03405 if (viewing) { 03406 disconnect(viewing); 03407 viewing->removeView(this); 03408 } 03409 viewing=canvas; 03410 if (viewing) { 03411 connect(viewing,SIGNAL(resized()), this, SLOT(updateContentsSize())); 03412 viewing->addView(this); 03413 viewing->setAllChanged(); 03414 } 03415 if (d) // called by d'tor 03416 updateContentsSize(); 03417 update(); 03418 }
Here is the call graph for this function:

| const QMatrix & Q3CanvasView::worldMatrix | ( | ) | const |
Returns a reference to the canvas view's current transformation matrix.
Definition at line 3426 of file q3canvas.cpp.
References d, and Q3CanvasViewData::xform.
Referenced by Q3Canvas::drawViewArea(), and Q3Canvas::update().
| const QMatrix & Q3CanvasView::inverseWorldMatrix | ( | ) | const |
Returns a reference to the inverse of the canvas view's current transformation matrix.
Definition at line 3437 of file q3canvas.cpp.
References d, and Q3CanvasViewData::ixform.
Referenced by Q3Canvas::update().
| 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.
Definition at line 3455 of file q3canvas.cpp.
References d, QMatrix::isInvertible(), Q3CanvasViewData::ixform, QWidget::update(), updateContentsSize(), Q3ScrollView::viewport(), and Q3CanvasViewData::xform.
03456 { 03457 bool ok = wm.isInvertible(); 03458 if (ok) { 03459 d->xform = wm; 03460 d->ixform = wm.invert(); 03461 updateContentsSize(); 03462 viewport()->update(); 03463 } 03464 return ok; 03465 }
Here is the call graph for this function:

| void Q3CanvasView::drawContents | ( | QPainter * | p, | |
| int | cx, | |||
| int | cy, | |||
| int | cw, | |||
| int | ch | |||
| ) | [protected, virtual] |
Repaints part of the Q3Canvas 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.
Reimplemented from Q3ScrollView.
Definition at line 3501 of file q3canvas.cpp.
References d, Q3Canvas::drawViewArea(), Q3CanvasViewData::eraseRegion, i, QRegion::isEmpty(), p, QRegion::rects(), and viewing.
03502 { 03503 QRect r(cx,cy,cw,ch); 03504 if (!d->eraseRegion.isEmpty()) { 03505 const QVector<QRect> rects = d->eraseRegion.rects(); 03506 for (int i = 0; i < rects.size(); ++i) 03507 p->eraseRect(rects.at(i)); 03508 03509 d->eraseRegion = QRegion(); 03510 } 03511 03512 if (viewing) { 03513 viewing->drawViewArea(this,p,r,false); 03514 } else { 03515 p->eraseRect(r); 03516 } 03517 }
Here is the call graph for this function:

| QSize Q3CanvasView::sizeHint | ( | ) | const [protected, virtual] |
Suggests a size sufficient to view the entire canvas.
Reimplemented from Q3ScrollView.
Definition at line 3532 of file q3canvas.cpp.
References canvas(), QApplication::desktop(), Q3Frame::frameWidth(), QWidget::size(), and Q3ScrollView::sizeHint().
03533 { 03534 if (!canvas()) 03535 return Q3ScrollView::sizeHint(); 03536 // should maybe take transformations into account 03537 return (canvas()->size() + 2 * QSize(frameWidth(), frameWidth())) 03538 .boundedTo(3 * QApplication::desktop()->size() / 4); 03539 }
Here is the call graph for this function:

| void Q3CanvasView::drawContents | ( | QPainter * | ) | [private, virtual] |
| void Q3CanvasView::updateContentsSize | ( | ) | [private, slot] |
Definition at line 3468 of file q3canvas.cpp.
References Q3ScrollView::contentsHeight(), Q3ScrollView::contentsToViewport(), Q3ScrollView::contentsWidth(), d, Q3CanvasViewData::eraseRegion, QRect::height(), Q3Canvas::height(), QMatrix::map(), QWidget::rect(), Q3ScrollView::resizeContents(), viewing, QRect::width(), Q3Canvas::width(), and Q3CanvasViewData::xform.
Referenced by setCanvas(), and setWorldMatrix().
03469 { 03470 if (viewing) { 03471 QRect br; 03472 #ifndef QT_NO_TRANSFORMATIONS 03473 br = d->xform.map(QRect(0,0,viewing->width(),viewing->height())); 03474 #else 03475 br = QRect(0,0,viewing->width(),viewing->height()); 03476 #endif 03477 03478 if (br.width() < contentsWidth()) { 03479 QRect r(contentsToViewport(QPoint(br.width(),0)), 03480 QSize(contentsWidth()-br.width(),contentsHeight())); 03481 d->eraseRegion = r; 03482 } 03483 if (br.height() < contentsHeight()) { 03484 QRect r(contentsToViewport(QPoint(0,br.height())), 03485 QSize(contentsWidth(),contentsHeight()-br.height())); 03486 d->eraseRegion |= r; 03487 } 03488 03489 resizeContents(br.width(),br.height()); 03490 } else { 03491 d->eraseRegion = rect(); 03492 resizeContents(1,1); 03493 } 03494 }
friend class Q3Canvas [friend] |
Definition at line 348 of file q3canvas.h.
| void qt_unview | ( | Q3Canvas * | c | ) | [friend] |
Definition at line 658 of file q3canvas.cpp.
00659 { 00660 for (Q3CanvasView* view=c->d->viewList.first(); view != 0; view=c->d->viewList.next()) { 00661 view->viewing = 0; 00662 } 00663 }
Q3Canvas* Q3CanvasView::viewing [private] |
Definition at line 350 of file q3canvas.h.
Referenced by drawContents(), Q3CanvasView(), setCanvas(), and updateContentsSize().
Q3CanvasViewData* Q3CanvasView::d [private] |
Reimplemented from Q3ScrollView.
Definition at line 351 of file q3canvas.h.
Referenced by drawContents(), inverseWorldMatrix(), Q3CanvasView(), setCanvas(), setWorldMatrix(), updateContentsSize(), worldMatrix(), and ~Q3CanvasView().
1.5.1