3
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /fasttmp/mkdist-qt-4.4.0-1209388211/qt-x11-opensource-src-4.4.0/doc/src/examples/collidingmice-example.qdoc -->
5
<!-- /fasttmp/mkdist-qt-4.4.1-1217326953/qt-all-opensource-src-4.4.1/doc/src/examples/collidingmice-example.qdoc -->
7
7
<title>Qt 4.4: Colliding Mice Example</title>
8
8
<link href="classic.css" rel="stylesheet" type="text/css" />
75
75
angleToCenter = normalizeAngle((Pi - angleToCenter) + Pi / 2);
77
77
if (angleToCenter < Pi && angleToCenter > Pi / 4) {
78
<span class="comment">//</span> Rotate left
78
<span class="comment">// Rotate left</span>
79
79
angle += (angle < -Pi / 2) ? 0.25 : -0.25;
80
80
} else if (angleToCenter >= Pi && angleToCenter < (Pi + Pi / 2 + Pi / 4)) {
81
<span class="comment">//</span> Rotate right
81
<span class="comment">// Rotate right</span>
82
82
angle += (angle < Pi / 2) ? 0.25 : -0.25;
84
84
} else if (::sin(angle) < 0) {
103
103
angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
105
105
if (angleToMouse >= 0 && angleToMouse < Pi / 2) {
106
<span class="comment">//</span> Rotate right
106
<span class="comment">// Rotate right</span>
108
108
} else if (angleToMouse <= TwoPi && angleToMouse > (TwoPi - Pi / 2)) {
109
<span class="comment">//</span> Rotate left
109
<span class="comment">// Rotate left</span>
138
138
<p>The <a href="qgraphicsitem.html#boundingRect">boundingRect()</a> function defines the outer bounds of the item as a rectangle. Note that the Graphics View framework uses the bounding rectangle to determine whether the item requires redrawing, so all painting must be restricted inside this rectangle.</p>
139
139
<pre> void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
141
<span class="comment">//</span> Body
141
<span class="comment">// Body</span>
142
142
painter->setBrush(color);
143
143
painter->drawEllipse(-10, -20, 20, 40);
145
<span class="comment">//</span> Eyes
145
<span class="comment">// Eyes</span>
146
146
painter->setBrush(Qt::white);
147
147
painter->drawEllipse(-10, -17, 8, 8);
148
148
painter->drawEllipse(2, -17, 8, 8);
150
<span class="comment">//</span> Nose
150
<span class="comment">// Nose</span>
151
151
painter->setBrush(Qt::black);
152
152
painter->drawEllipse(QRectF(-2, -22, 4, 4));
154
<span class="comment">//</span> Pupils
154
<span class="comment">// Pupils</span>
155
155
painter->drawEllipse(QRectF(-8.0 + mouseEyeDirection, -17, 4, 4));
156
156
painter->drawEllipse(QRectF(4.0 + mouseEyeDirection, -17, 4, 4));
158
<span class="comment">//</span> Ears
158
<span class="comment">// Ears</span>
159
159
painter->setBrush(scene()->collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red);
160
160
painter->drawEllipse(-17, -12, 16, 16);
161
161
painter->drawEllipse(1, -12, 16, 16);
163
<span class="comment">//</span> Tail
163
<span class="comment">// Tail</span>
164
164
QPainterPath path(QPointF(0, 20));
165
165
path.cubicTo(-5, 22, -5, 22, 0, 25);
166
166
path.cubicTo(5, 27, 5, 32, 0, 30);
221
221
<table width="100%" cellspacing="0" border="0"><tr class="address">
222
222
<td width="30%">Copyright © 2008 <a href="trolltech.html">Trolltech</a></td>
223
223
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
224
<td width="30%" align="right"><div align="right">Qt 4.4.0</div></td>
224
<td width="30%" align="right"><div align="right">Qt 4.4.1</div></td>
225
225
</tr></table></div></address></body>