diff options
author | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /tutorial/t8 | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'tutorial/t8')
-rw-r--r-- | tutorial/t8/cannon.cpp | 45 | ||||
-rw-r--r-- | tutorial/t8/cannon.h | 36 | ||||
-rw-r--r-- | tutorial/t8/lcdrange.cpp | 47 | ||||
-rw-r--r-- | tutorial/t8/lcdrange.h | 35 | ||||
-rw-r--r-- | tutorial/t8/main.cpp | 65 | ||||
-rw-r--r-- | tutorial/t8/t8.pro | 9 |
6 files changed, 237 insertions, 0 deletions
diff --git a/tutorial/t8/cannon.cpp b/tutorial/t8/cannon.cpp new file mode 100644 index 000000000..d5f3b6ba0 --- /dev/null +++ b/tutorial/t8/cannon.cpp @@ -0,0 +1,45 @@ +/**************************************************************** +** +** Implementation CannonField class, TQt tutorial 8 +** +****************************************************************/ + +#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 * ) +{ + TQString s = "Angle = " + TQString::number( ang ); + TQPainter p( this ); + p.drawText( 200, 200, s ); +} + + +TQSizePolicy CannonField::sizePolicy() const +{ + return TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ); +} + diff --git a/tutorial/t8/cannon.h b/tutorial/t8/cannon.h new file mode 100644 index 000000000..bbd271d1a --- /dev/null +++ b/tutorial/t8/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/t8/lcdrange.cpp b/tutorial/t8/lcdrange.cpp new file mode 100644 index 000000000..ca0aba8a8 --- /dev/null +++ b/tutorial/t8/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/t8/lcdrange.h b/tutorial/t8/lcdrange.h new file mode 100644 index 000000000..4a79a6ca9 --- /dev/null +++ b/tutorial/t8/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/t8/main.cpp b/tutorial/t8/main.cpp new file mode 100644 index 000000000..9acd0382d --- /dev/null +++ b/tutorial/t8/main.cpp @@ -0,0 +1,65 @@ +/**************************************************************** +** +** TQt tutorial 8 +** +****************************************************************/ + +#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 ); + //2x2, 10 pixel border + + 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 a( argc, argv ); + + MyWidget w; + w.setGeometry( 100, 100, 500, 355 ); + a.setMainWidget( &w ); + w.show(); + return a.exec(); +} diff --git a/tutorial/t8/t8.pro b/tutorial/t8/t8.pro new file mode 100644 index 000000000..8eca4fa5c --- /dev/null +++ b/tutorial/t8/t8.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 = t8 +REQUIRES=large-config |