diff options
Diffstat (limited to 'tutorial/t9')
-rw-r--r-- | tutorial/t9/cannon.cpp | 50 | ||||
-rw-r--r-- | tutorial/t9/cannon.h | 36 | ||||
-rw-r--r-- | tutorial/t9/lcdrange.cpp | 47 | ||||
-rw-r--r-- | tutorial/t9/lcdrange.h | 35 | ||||
-rw-r--r-- | tutorial/t9/main.cpp | 62 | ||||
-rw-r--r-- | tutorial/t9/t9.pro | 9 |
6 files changed, 239 insertions, 0 deletions
diff --git a/tutorial/t9/cannon.cpp b/tutorial/t9/cannon.cpp new file mode 100644 index 000000000..ffd47e029 --- /dev/null +++ b/tutorial/t9/cannon.cpp @@ -0,0 +1,50 @@ +/**************************************************************** +** +** Implementation CannonField class, TQt tutorial 9 +** +****************************************************************/ + +#include "cannon.h" +#include <qpainter.h> + + +CannonField::CannonField( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + ang = 45; + 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(); + emit angleChanged( ang ); +} + + +void CannonField::paintEvent( TQPaintEvent * ) +{ + TQPainter p( this ); + + p.setBrush( blue ); + p.setPen( NoPen ); + + p.translate( 0, rect().bottom() ); + p.drawPie( TQRect(-35, -35, 70, 70), 0, 90*16 ); + p.rotate( -ang ); + p.drawRect( TQRect(33, -4, 15, 8) ); +} + + +TQSizePolicy CannonField::sizePolicy() const +{ + return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ); +} diff --git a/tutorial/t9/cannon.h b/tutorial/t9/cannon.h new file mode 100644 index 000000000..bbd271d1a --- /dev/null +++ b/tutorial/t9/cannon.h @@ -0,0 +1,36 @@ +/**************************************************************** +** +** Definition of CannonField class, TQt tutorial 8 +** +****************************************************************/ + +#ifndef CANNON_H +#define CANNON_H + +#include <qwidget.h> + + +class CannonField : public TQWidget +{ + Q_OBJECT +public: + CannonField( TQWidget *parent=0, const char *name=0 ); + + int angle() const { return ang; } + TQSizePolicy sizePolicy() const; + +public slots: + void setAngle( int degrees ); + +signals: + void angleChanged( int ); + +protected: + void paintEvent( TQPaintEvent * ); + +private: + int ang; +}; + + +#endif // CANNON_H diff --git a/tutorial/t9/lcdrange.cpp b/tutorial/t9/lcdrange.cpp new file mode 100644 index 000000000..ca0aba8a8 --- /dev/null +++ b/tutorial/t9/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/t9/lcdrange.h b/tutorial/t9/lcdrange.h new file mode 100644 index 000000000..4a79a6ca9 --- /dev/null +++ b/tutorial/t9/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/t9/main.cpp b/tutorial/t9/main.cpp new file mode 100644 index 000000000..506b66f9b --- /dev/null +++ b/tutorial/t9/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************** +** +** TQt tutorial 9 +** +****************************************************************/ + +#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 ); + + CannonField *cannonField = new CannonField( this, "cannonField" ); + + connect( angle, SIGNAL(valueChanged(int)), + cannonField, SLOT(setAngle(int)) ); + connect( cannonField, SIGNAL(angleChanged(int)), + angle, SLOT(setValue(int)) ); + + TQGridLayout *grid = new TQGridLayout( this, 2, 2, 10 ); + grid->addWidget( tquit, 0, 0 ); + grid->addWidget( angle, 1, 0, TQt::AlignTop ); + grid->addWidget( cannonField, 1, 1 ); + grid->setColStretch( 1, 10 ); + + angle->setValue( 60 ); + 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/t9/t9.pro b/tutorial/t9/t9.pro new file mode 100644 index 000000000..b9d995a33 --- /dev/null +++ b/tutorial/t9/t9.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 = t9 +REQUIRES=full-config |