1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
'\" t
.TH QCanvasView 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QCanvasView \- On-screen view of a QCanvas
.SH SYNOPSIS
\fC#include <ntqcanvas.h>\fR
.PP
Inherits QScrollView.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQCanvasView\fR ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )"
.br
.ti -1c
.BI "\fBQCanvasView\fR ( QCanvas * canvas, QWidget * parent = 0, const char * name = 0, WFlags f = 0 )"
.br
.ti -1c
.BI "\fB~QCanvasView\fR ()"
.br
.ti -1c
.BI "QCanvas * \fBcanvas\fR () const"
.br
.ti -1c
.BI "void \fBsetCanvas\fR ( QCanvas * canvas )"
.br
.ti -1c
.BI "const QWMatrix & \fBworldMatrix\fR () const"
.br
.ti -1c
.BI "const QWMatrix & \fBinverseWorldMatrix\fR () const"
.br
.ti -1c
.BI "bool \fBsetWorldMatrix\fR ( const QWMatrix & wm )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual void \fBdrawContents\fR ( QPainter * p, int cx, int cy, int cw, int ch )"
.br
.ti -1c
.BI "virtual QSize \fBsizeHint\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QCanvasView class provides an on-screen view of a QCanvas.
.PP
A QCanvasView is widget which provides a view of a QCanvas.
.PP
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:
.PP
.nf
.br
void MyCanvasView::contentsMousePressEvent( QMouseEvent* e )
.br
{
.br
QCanvasItemList l = canvas()->collisions(e->pos());
.br
for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
.br
if ( (*it)->rtti() == QCanvasRectangle::RTTI )
.br
tqDebug("A QCanvasRectangle lies somewhere at this point");
.br
}
.br
}
.br
.fi
.PP
The canvas view shows canvas canvas(); this can be changed using setCanvas().
.PP
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:
.PP
.nf
.br
QWMatrix wm;
.br
wm.scale( 2, 2 ); // Zooms in by 2 times
.br
wm.rotate( 90 ); // Rotates 90 degrees counter clockwise
.br
// around the origin.
.br
wm.translate( 0, -canvas->height() );
.br
// moves the canvas down so what was visible
.br
// before is still visible.
.br
myCanvasView->setWorldMatrix( wm );
.br
.fi
.PP
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().
.PP
Example:
.PP
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.
.PP
.nf
.br
QRect rc = QRect( myCanvasView->contentsX(), myCanvasView->contentsY(),
.br
myCanvasView->visibleWidth(), myCanvasView->visibleHeight() );
.br
QRect canvasRect = myCanvasView->inverseWorldMatrix().mapRect(rc);
.br
.fi
.PP
See also QWMatrix, QPainter::setWorldMatrix(), Graphics Classes, and Image Processing Classes.
.PP
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QCanvasView::QCanvasView ( QWidget * parent = 0, const char * name = 0, WFlags f = 0 )"
Constructs a QCanvasView with parent \fIparent\fR, and name \fIname\fR, using the widget flags \fIf\fR. The canvas view is not associated with a canvas, so you must to call setCanvas() to view a canvas.
.SH "QCanvasView::QCanvasView ( QCanvas * canvas, QWidget * 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.
.PP
Constructs a QCanvasView which views canvas \fIcanvas\fR, with parent \fIparent\fR, and name \fIname\fR, using the widget flags \fIf\fR.
.SH "QCanvasView::~QCanvasView ()"
Destroys the canvas view. The associated canvas is \fInot\fR deleted.
.SH "QCanvas * QCanvasView::canvas () const"
Returns a pointer to the canvas which the QCanvasView is currently showing.
.SH "void QCanvasView::drawContents ( QPainter * p, int cx, int cy, int cw, int ch )\fC [virtual protected]\fR"
Repaints part of the QCanvas that the canvas view is showing starting at \fIcx\fR by \fIcy\fR, with a width of \fIcw\fR and a height of \fIch\fR using the painter \fIp\fR.
.PP
\fBWarning:\fR 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.
.PP
See also QCanvas::setDoubleBuffering().
.PP
Reimplemented from QScrollView.
.SH "const QWMatrix & QCanvasView::inverseWorldMatrix () const"
Returns a reference to the inverse of the canvas view's current transformation matrix.
.PP
See also setWorldMatrix() and worldMatrix().
.SH "void QCanvasView::setCanvas ( QCanvas * canvas )"
Sets the canvas that the QCanvasView is showing to the canvas \fIcanvas\fR.
.SH "bool QCanvasView::setWorldMatrix ( const QWMatrix & wm )"
Sets the transformation matrix of the QCanvasView to \fIwm\fR. 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).
.PP
When you use this, you should note that the performance of the QCanvasView will decrease considerably.
.PP
Returns FALSE if \fIwm\fR is not invertable; otherwise returns TRUE.
.PP
See also worldMatrix(), inverseWorldMatrix(), and QWMatrix::isInvertible().
.PP
Example: canvas/canvas.cpp.
.SH "QSize QCanvasView::sizeHint () const\fC [virtual protected]\fR"
Suggests a size sufficient to view the entire canvas.
.SH "const QWMatrix & QCanvasView::worldMatrix () const"
Returns a reference to the canvas view's current transformation matrix.
.PP
See also setWorldMatrix() and inverseWorldMatrix().
.PP
Example: canvas/canvas.cpp.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qcanvasview.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqcanvasview.3qt) and the Qt
version (3.3.8).
|