source: trunk/tutorial/t9/cannon.cpp@ 127

Last change on this file since 127 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1/****************************************************************
2**
3** Implementation CannonField class, Qt tutorial 9
4**
5****************************************************************/
6
7#include "cannon.h"
8#include <qpainter.h>
9
10
11CannonField::CannonField( QWidget *parent, const char *name )
12 : QWidget( parent, name )
13{
14 ang = 45;
15 setPalette( QPalette( QColor( 250, 250, 200) ) );
16}
17
18
19void CannonField::setAngle( int degrees )
20{
21 if ( degrees < 5 )
22 degrees = 5;
23 if ( degrees > 70 )
24 degrees = 70;
25 if ( ang == degrees )
26 return;
27 ang = degrees;
28 repaint();
29 emit angleChanged( ang );
30}
31
32
33void CannonField::paintEvent( QPaintEvent * )
34{
35 QPainter p( this );
36
37 p.setBrush( blue );
38 p.setPen( NoPen );
39
40 p.translate( 0, rect().bottom() );
41 p.drawPie( QRect(-35, -35, 70, 70), 0, 90*16 );
42 p.rotate( -ang );
43 p.drawRect( QRect(33, -4, 15, 8) );
44}
45
46
47QSizePolicy CannonField::sizePolicy() const
48{
49 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
50}
Note: See TracBrowser for help on using the repository browser.