1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/tutorial.doc:1301 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>t10/cannon.cpp Example File</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>t10/cannon.cpp Example File</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <pre>/****************************************************************
|
---|
36 | **
|
---|
37 | ** Implementation CannonField class, Qt tutorial 10
|
---|
38 | **
|
---|
39 | ****************************************************************/
|
---|
40 |
|
---|
41 | #include "cannon.h"
|
---|
42 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
43 | #include <<a href="qpixmap-h.html">qpixmap.h</a>>
|
---|
44 |
|
---|
45 |
|
---|
46 | <a name="f48"></a>CannonField::CannonField( <a href="qwidget.html">QWidget</a> *parent, const char *name )
|
---|
47 | : <a href="qwidget.html">QWidget</a>( parent, name )
|
---|
48 | {
|
---|
49 | ang = 45;
|
---|
50 | f = 0;
|
---|
51 | <a href="qwidget.html#setPalette">setPalette</a>( QPalette( QColor( 250, 250, 200) ) );
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | void <a name="f49"></a>CannonField::setAngle( int degrees )
|
---|
56 | {
|
---|
57 | if ( degrees < 5 )
|
---|
58 | degrees = 5;
|
---|
59 | if ( degrees > 70 )
|
---|
60 | degrees = 70;
|
---|
61 | if ( ang == degrees )
|
---|
62 | return;
|
---|
63 | ang = degrees;
|
---|
64 | <a href="qwidget.html#repaint">repaint</a>( cannonRect(), FALSE );
|
---|
65 | emit angleChanged( ang );
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 | void <a name="f50"></a>CannonField::setForce( int newton )
|
---|
70 | {
|
---|
71 | if ( newton < 0 )
|
---|
72 | newton = 0;
|
---|
73 | if ( f == newton )
|
---|
74 | return;
|
---|
75 | f = newton;
|
---|
76 | emit forceChanged( f );
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | void CannonField::<a href="qwidget.html#paintEvent">paintEvent</a>( <a href="qpaintevent.html">QPaintEvent</a> *e )
|
---|
81 | {
|
---|
82 | if ( !e-><a href="qpaintevent.html#rect">rect</a>().intersects( cannonRect() ) )
|
---|
83 | return;
|
---|
84 |
|
---|
85 | <a href="qrect.html">QRect</a> cr = cannonRect();
|
---|
86 | <a href="qpixmap.html">QPixmap</a> pix( cr.<a href="qrect.html#size">size</a>() );
|
---|
87 | pix.<a href="qpixmap.html#fill">fill</a>( this, cr.<a href="qrect.html#topLeft">topLeft</a>() );
|
---|
88 |
|
---|
89 | <a href="qpainter.html">QPainter</a> p( &pix );
|
---|
90 | p.<a href="qpainter.html#setBrush">setBrush</a>( blue );
|
---|
91 | p.<a href="qpainter.html#setPen">setPen</a>( NoPen );
|
---|
92 | p.<a href="qpainter.html#translate">translate</a>( 0, pix.<a href="qpixmap.html#height">height</a>() - 1 );
|
---|
93 | p.<a href="qpainter.html#drawPie">drawPie</a>( QRect( -35,-35, 70, 70 ), 0, 90*16 );
|
---|
94 | p.<a href="qpainter.html#rotate">rotate</a>( -ang );
|
---|
95 | p.<a href="qpainter.html#drawRect">drawRect</a>( QRect(33, -4, 15, 8) );
|
---|
96 | p.<a href="qpainter.html#end">end</a>();
|
---|
97 |
|
---|
98 | p.<a href="qpainter.html#begin">begin</a>( this );
|
---|
99 | p.<a href="qpainter.html#drawPixmap">drawPixmap</a>( cr.<a href="qrect.html#topLeft">topLeft</a>(), pix );
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | QRect <a name="f51"></a>CannonField::cannonRect() const
|
---|
104 | {
|
---|
105 | <a href="qrect.html">QRect</a> r( 0, 0, 50, 50 );
|
---|
106 | r.<a href="qrect.html#moveBottomLeft">moveBottomLeft</a>( <a href="qwidget.html#rect">rect</a>().bottomLeft() );
|
---|
107 | return r;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | QSizePolicy CannonField::<a href="qwidget.html#sizePolicy">sizePolicy</a>() const
|
---|
112 | {
|
---|
113 | return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
---|
114 | }
|
---|
115 | </pre><!-- eof -->
|
---|
116 | <p><address><hr><div align=center>
|
---|
117 | <table width=100% cellspacing=0 border=0><tr>
|
---|
118 | <td>Copyright © 2007
|
---|
119 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
120 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
121 | </table></div></address></body>
|
---|
122 | </html>
|
---|