summaryrefslogtreecommitdiffstats
path: root/tutorial/t10
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial/t10')
-rw-r--r--tutorial/t10/cannon.cpp80
-rw-r--r--tutorial/t10/cannon.h43
-rw-r--r--tutorial/t10/lcdrange.cpp47
-rw-r--r--tutorial/t10/lcdrange.h35
-rw-r--r--tutorial/t10/main.cpp75
-rw-r--r--tutorial/t10/t10.pro9
6 files changed, 289 insertions, 0 deletions
diff --git a/tutorial/t10/cannon.cpp b/tutorial/t10/cannon.cpp
new file mode 100644
index 000000000..fa2b2c103
--- /dev/null
+++ b/tutorial/t10/cannon.cpp
@@ -0,0 +1,80 @@
+/****************************************************************
+**
+** Implementation CannonField class, TQt tutorial 10
+**
+****************************************************************/
+
+#include "cannon.h"
+#include <qpainter.h>
+#include <qpixmap.h>
+
+
+CannonField::CannonField( TQWidget *parent, const char *name )
+ : TQWidget( parent, name )
+{
+ ang = 45;
+ f = 0;
+ setPalette( TQPalette( TQColor( 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( cannonRect(), FALSE );
+ emit angleChanged( ang );
+}
+
+
+void CannonField::setForce( int newton )
+{
+ if ( newton < 0 )
+ newton = 0;
+ if ( f == newton )
+ return;
+ f = newton;
+ emit forceChanged( f );
+}
+
+
+void CannonField::paintEvent( TQPaintEvent *e )
+{
+ if ( !e->rect().intersects( cannonRect() ) )
+ return;
+
+ TQRect cr = cannonRect();
+ TQPixmap pix( cr.size() );
+ pix.fill( this, cr.topLeft() );
+
+ TQPainter p( &pix );
+ p.setBrush( blue );
+ p.setPen( NoPen );
+ p.translate( 0, pix.height() - 1 );
+ p.drawPie( TQRect( -35,-35, 70, 70 ), 0, 90*16 );
+ p.rotate( -ang );
+ p.drawRect( TQRect(33, -4, 15, 8) );
+ p.end();
+
+ p.begin( this );
+ p.drawPixmap( cr.topLeft(), pix );
+}
+
+
+TQRect CannonField::cannonRect() const
+{
+ TQRect r( 0, 0, 50, 50 );
+ r.moveBottomLeft( rect().bottomLeft() );
+ return r;
+}
+
+
+TQSizePolicy CannonField::sizePolicy() const
+{
+ return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding );
+}
diff --git a/tutorial/t10/cannon.h b/tutorial/t10/cannon.h
new file mode 100644
index 000000000..1b1c16828
--- /dev/null
+++ b/tutorial/t10/cannon.h
@@ -0,0 +1,43 @@
+/****************************************************************
+**
+** Definition of CannonField class, TQt tutorial 10
+**
+****************************************************************/
+
+#ifndef CANNON_H
+#define CANNON_H
+
+#include <qwidget.h>
+
+
+class CannonField : public TQWidget
+{
+ Q_OBJECT
+public:
+ CannonField( TQWidget *parent=0, const char *name=0 );
+
+ TQSizePolicy sizePolicy() const;
+
+ int angle() const { return ang; }
+ int force() const { return f; }
+
+public slots:
+ void setAngle( int degrees );
+ void setForce( int newton );
+
+signals:
+ void angleChanged( int );
+ void forceChanged( int );
+
+protected:
+ void paintEvent( TQPaintEvent * );
+
+private:
+ TQRect cannonRect() const;
+
+ int ang;
+ int f;
+};
+
+
+#endif // CANNON_H
diff --git a/tutorial/t10/lcdrange.cpp b/tutorial/t10/lcdrange.cpp
new file mode 100644
index 000000000..ca0aba8a8
--- /dev/null
+++ b/tutorial/t10/lcdrange.cpp
@@ -0,0 +1,47 @@
+/****************************************************************
+**
+** Implementation of LCDRange class, TQt tutorial 8
+**
+****************************************************************/
+
+#include "lcdrange.h"
+
+#include <qslider.h>
+#include <qlcdnumber.h>
+
+LCDRange::LCDRange( TQWidget *parent, const char *name )
+ : TQVBox( parent, name )
+{
+ TQLCDNumber *lcd = new TQLCDNumber( 2, this, "lcd" );
+ slider = new TQSlider( Horizontal, this, "slider" );
+ slider->setRange( 0, 99 );
+ slider->setValue( 0 );
+ connect( slider, SIGNAL(valueChanged(int)),
+ lcd, SLOT(display(int)) );
+ connect( slider, SIGNAL(valueChanged(int)),
+ SIGNAL(valueChanged(int)) );
+
+ setFocusProxy( slider );
+}
+
+int LCDRange::value() const
+{
+ return slider->value();
+}
+
+void LCDRange::setValue( int value )
+{
+ slider->setValue( value );
+}
+
+void LCDRange::setRange( int minVal, int maxVal )
+{
+ if ( minVal < 0 || maxVal > 99 || minVal > maxVal ) {
+ qWarning( "LCDRange::setRange(%d,%d)\n"
+ "\tRange must be 0..99\n"
+ "\tand minVal must not be greater than maxVal",
+ minVal, maxVal );
+ return;
+ }
+ slider->setRange( minVal, maxVal );
+}
diff --git a/tutorial/t10/lcdrange.h b/tutorial/t10/lcdrange.h
new file mode 100644
index 000000000..4a79a6ca9
--- /dev/null
+++ b/tutorial/t10/lcdrange.h
@@ -0,0 +1,35 @@
+/****************************************************************
+**
+** Definition of LCDRange class, TQt tutorial 8
+**
+****************************************************************/
+
+#ifndef LCDRANGE_H
+#define LCDRANGE_H
+
+#include <qvbox.h>
+
+class TQSlider;
+
+
+class LCDRange : public TQVBox
+{
+ Q_OBJECT
+public:
+ LCDRange( TQWidget *parent=0, const char *name=0 );
+
+ int value() const;
+
+public slots:
+ void setValue( int );
+ void setRange( int minVal, int maxVal );
+
+signals:
+ void valueChanged( int );
+
+private:
+ TQSlider *slider;
+};
+
+
+#endif // LCDRANGE_H
diff --git a/tutorial/t10/main.cpp b/tutorial/t10/main.cpp
new file mode 100644
index 000000000..a0c659d72
--- /dev/null
+++ b/tutorial/t10/main.cpp
@@ -0,0 +1,75 @@
+/****************************************************************
+**
+** TQt tutorial 10
+**
+****************************************************************/
+
+#include <qapplication.h>
+#include <qpushbutton.h>
+#include <qlcdnumber.h>
+#include <qfont.h>
+#include <qlayout.h>
+
+#include "lcdrange.h"
+#include "cannon.h"
+
+
+class MyWidget: public TQWidget
+{
+public:
+ MyWidget( TQWidget *parent=0, const char *name=0 );
+};
+
+
+MyWidget::MyWidget( TQWidget *parent, const char *name )
+ : TQWidget( parent, name )
+{
+ TQPushButton *tquit = new TQPushButton( "&Quit", this, "tquit" );
+ tquit->setFont( TQFont( "Times", 18, TQFont::Bold ) );
+
+ connect( tquit, SIGNAL(clicked()), qApp, SLOT(tquit()) );
+
+ LCDRange *angle = new LCDRange( this, "angle" );
+ angle->setRange( 5, 70 );
+
+ LCDRange *force = new LCDRange( this, "force" );
+ force->setRange( 10, 50 );
+
+ CannonField *cannonField = new CannonField( this, "cannonField" );
+
+ connect( angle, SIGNAL(valueChanged(int)),
+ cannonField, SLOT(setAngle(int)) );
+ connect( cannonField, SIGNAL(angleChanged(int)),
+ angle, SLOT(setValue(int)) );
+
+ connect( force, SIGNAL(valueChanged(int)),
+ cannonField, SLOT(setForce(int)) );
+ connect( cannonField, SIGNAL(forceChanged(int)),
+ force, SLOT(setValue(int)) );
+
+ TQGridLayout *grid = new TQGridLayout( this, 2, 2, 10 );
+ grid->addWidget( tquit, 0, 0 );
+ grid->addWidget( cannonField, 1, 1 );
+ grid->setColStretch( 1, 10 );
+
+ TQVBoxLayout *leftBox = new TQVBoxLayout;
+ grid->addLayout( leftBox, 1, 0 );
+ leftBox->addWidget( angle );
+ leftBox->addWidget( force );
+
+ angle->setValue( 60 );
+ force->setValue( 25 );
+ angle->setFocus();
+}
+
+int main( int argc, char **argv )
+{
+ TQApplication::setColorSpec( TQApplication::CustomColor );
+ TQApplication a( argc, argv );
+
+ MyWidget w;
+ w.setGeometry( 100, 100, 500, 355 );
+ a.setMainWidget( &w );
+ w.show();
+ return a.exec();
+}
diff --git a/tutorial/t10/t10.pro b/tutorial/t10/t10.pro
new file mode 100644
index 000000000..202b939a6
--- /dev/null
+++ b/tutorial/t10/t10.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+CONFIG += qt warn_on release
+HEADERS = cannon.h \
+ lcdrange.h
+SOURCES = cannon.cpp \
+ lcdrange.cpp \
+ main.cpp
+TARGET = t10
+REQUIRES=full-config