summaryrefslogtreecommitdiffstats
path: root/tutorial/t8
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /tutorial/t8
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'tutorial/t8')
-rw-r--r--tutorial/t8/cannon.cpp45
-rw-r--r--tutorial/t8/cannon.h36
-rw-r--r--tutorial/t8/lcdrange.cpp47
-rw-r--r--tutorial/t8/lcdrange.h35
-rw-r--r--tutorial/t8/main.cpp65
-rw-r--r--tutorial/t8/t8.pro9
6 files changed, 237 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 );
+}
+
diff --git a/tutorial/t8/cannon.h b/tutorial/t8/cannon.h
new file mode 100644
index 0000000..a0928cd
--- /dev/null
+++ b/tutorial/t8/cannon.h
@@ -0,0 +1,36 @@
+/****************************************************************
+**
+** Definition of CannonField class, Qt tutorial 8
+**
+****************************************************************/
+
+#ifndef CANNON_H
+#define CANNON_H
+
+#include <qwidget.h>
+
+
+class CannonField : public QWidget
+{
+ Q_OBJECT
+public:
+ CannonField( QWidget *parent=0, const char *name=0 );
+
+ int angle() const { return ang; }
+ QSizePolicy sizePolicy() const;
+
+public slots:
+ void setAngle( int degrees );
+
+signals:
+ void angleChanged( int );
+
+protected:
+ void paintEvent( QPaintEvent * );
+
+private:
+ int ang;
+};
+
+
+#endif // CANNON_H
diff --git a/tutorial/t8/lcdrange.cpp b/tutorial/t8/lcdrange.cpp
new file mode 100644
index 0000000..b62cfbb
--- /dev/null
+++ b/tutorial/t8/lcdrange.cpp
@@ -0,0 +1,47 @@
+/****************************************************************
+**
+** Implementation of LCDRange class, Qt tutorial 8
+**
+****************************************************************/
+
+#include "lcdrange.h"
+
+#include <qslider.h>
+#include <qlcdnumber.h>
+
+LCDRange::LCDRange( QWidget *parent, const char *name )
+ : QVBox( parent, name )
+{
+ QLCDNumber *lcd = new QLCDNumber( 2, this, "lcd" );
+ slider = new QSlider( 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 0000000..5fa2d21
--- /dev/null
+++ b/tutorial/t8/lcdrange.h
@@ -0,0 +1,35 @@
+/****************************************************************
+**
+** Definition of LCDRange class, Qt tutorial 8
+**
+****************************************************************/
+
+#ifndef LCDRANGE_H
+#define LCDRANGE_H
+
+#include <qvbox.h>
+
+class QSlider;
+
+
+class LCDRange : public QVBox
+{
+ Q_OBJECT
+public:
+ LCDRange( QWidget *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:
+ QSlider *slider;
+};
+
+
+#endif // LCDRANGE_H
diff --git a/tutorial/t8/main.cpp b/tutorial/t8/main.cpp
new file mode 100644
index 0000000..5983735
--- /dev/null
+++ b/tutorial/t8/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************
+**
+** Qt 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 QWidget
+{
+public:
+ MyWidget( QWidget *parent=0, const char *name=0 );
+};
+
+
+MyWidget::MyWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QPushButton *quit = new QPushButton( "Quit", this, "quit" );
+ quit->setFont( QFont( "Times", 18, QFont::Bold ) );
+
+ connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
+
+ 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)) );
+
+ QGridLayout *grid = new QGridLayout( this, 2, 2, 10 );
+ //2x2, 10 pixel border
+
+ grid->addWidget( quit, 0, 0 );
+ grid->addWidget( angle, 1, 0, Qt::AlignTop );
+ grid->addWidget( cannonField, 1, 1 );
+ grid->setColStretch( 1, 10 );
+
+ angle->setValue( 60 );
+ angle->setFocus();
+}
+
+
+int main( int argc, char **argv )
+{
+ QApplication 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 0000000..8eca4fa
--- /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