source: trunk/tutorial/t8/cannon.cpp@ 138

Last change on this file since 138 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: 955 bytes
Line 
1/****************************************************************
2**
3** Implementation CannonField class, Qt tutorial 8
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 QString s = "Angle = " + QString::number( ang );
36 QPainter p( this );
37 p.drawText( 200, 200, s );
38}
39
40
41QSizePolicy CannonField::sizePolicy() const
42{
43 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
44}
45
Note: See TracBrowser for help on using the repository browser.