summaryrefslogtreecommitdiffstats
path: root/tutorial/t8/cannon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/t8/cannon.cpp')
-rw-r--r--tutorial/t8/cannon.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tutorial/t8/cannon.cpp b/tutorial/t8/cannon.cpp
new file mode 100644
index 0000000..fd9d203
--- /dev/null
+++ b/tutorial/t8/cannon.cpp
@@ -0,0 +1,45 @@
+/****************************************************************
+**
+** Implementation CannonField class, Qt tutorial 8
+**
+****************************************************************/
+
+#include "cannon.h"
+#include <qpainter.h>
+
+
+CannonField::CannonField( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ ang = 45;
+ setPalette( QPalette( QColor( 250, 250, 200) ) );
+}
+
+
+void CannonField::setAngle( int degrees )
+{
+ if ( degrees < 5 )
+ degrees = 5;
+ if ( degrees > 70 )
+ degrees = 70;
+ if ( ang == degrees )
+ return;
+ ang = degrees;
+ repaint();
+ emit angleChanged( ang );
+}
+
+
+void CannonField::paintEvent( QPaintEvent * )
+{
+ QString s = "Angle = " + QString::number( ang );
+ QPainter p( this );
+ p.drawText( 200, 200, s );
+}
+
+
+QSizePolicy CannonField::sizePolicy() const
+{
+ return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
+}
+