~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/graphicsview-collidingmice.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-08-01 11:30:30 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20080801113030-c33y1z0l21t6cj5r
Tags: upstream-4.4.1
ImportĀ upstreamĀ versionĀ 4.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
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 -->
6
6
<head>
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);
76
76
 
77
77
         if (angleToCenter &lt; Pi &amp;&amp; angleToCenter &gt; Pi / 4) {
78
 
             <span class="comment">//</span> Rotate left
 
78
             <span class="comment">// Rotate left</span>
79
79
             angle += (angle &lt; -Pi / 2) ? 0.25 : -0.25;
80
80
         } else if (angleToCenter &gt;= Pi &amp;&amp; angleToCenter &lt; (Pi + Pi / 2 + Pi / 4)) {
81
 
             <span class="comment">//</span> Rotate right
 
81
             <span class="comment">// Rotate right</span>
82
82
             angle += (angle &lt; Pi / 2) ? 0.25 : -0.25;
83
83
         }
84
84
     } else if (::sin(angle) &lt; 0) {
103
103
         angleToMouse = normalizeAngle((Pi - angleToMouse) + Pi / 2);
104
104
 
105
105
         if (angleToMouse &gt;= 0 &amp;&amp; angleToMouse &lt; Pi / 2) {
106
 
             <span class="comment">//</span> Rotate right
 
106
             <span class="comment">// Rotate right</span>
107
107
             angle += 0.5;
108
108
         } else if (angleToMouse &lt;= TwoPi &amp;&amp; angleToMouse &gt; (TwoPi - Pi / 2)) {
109
 
             <span class="comment">//</span> Rotate left
 
109
             <span class="comment">// Rotate left</span>
110
110
             angle -= 0.5;
111
111
         }
112
112
     }
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 *)
140
140
 {
141
 
     <span class="comment">//</span> Body
 
141
     <span class="comment">// Body</span>
142
142
     painter-&gt;setBrush(color);
143
143
     painter-&gt;drawEllipse(-10, -20, 20, 40);
144
144
 
145
 
     <span class="comment">//</span> Eyes
 
145
     <span class="comment">// Eyes</span>
146
146
     painter-&gt;setBrush(Qt::white);
147
147
     painter-&gt;drawEllipse(-10, -17, 8, 8);
148
148
     painter-&gt;drawEllipse(2, -17, 8, 8);
149
149
 
150
 
     <span class="comment">//</span> Nose
 
150
     <span class="comment">// Nose</span>
151
151
     painter-&gt;setBrush(Qt::black);
152
152
     painter-&gt;drawEllipse(QRectF(-2, -22, 4, 4));
153
153
 
154
 
     <span class="comment">//</span> Pupils
 
154
     <span class="comment">// Pupils</span>
155
155
     painter-&gt;drawEllipse(QRectF(-8.0 + mouseEyeDirection, -17, 4, 4));
156
156
     painter-&gt;drawEllipse(QRectF(4.0 + mouseEyeDirection, -17, 4, 4));
157
157
 
158
 
     <span class="comment">//</span> Ears
 
158
     <span class="comment">// Ears</span>
159
159
     painter-&gt;setBrush(scene()-&gt;collidingItems(this).isEmpty() ? Qt::darkYellow : Qt::red);
160
160
     painter-&gt;drawEllipse(-17, -12, 16, 16);
161
161
     painter-&gt;drawEllipse(1, -12, 16, 16);
162
162
 
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 &copy; 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>
226
226
</html>