1 | /****************************************************************
|
---|
2 | **
|
---|
3 | ** Qt tutorial 11
|
---|
4 | **
|
---|
5 | ****************************************************************/
|
---|
6 |
|
---|
7 | #include <qapplication.h>
|
---|
8 | #include <qpushbutton.h>
|
---|
9 | #include <qlcdnumber.h>
|
---|
10 | #include <qfont.h>
|
---|
11 | #include <qlayout.h>
|
---|
12 |
|
---|
13 | #include "lcdrange.h"
|
---|
14 | #include "cannon.h"
|
---|
15 |
|
---|
16 |
|
---|
17 | class MyWidget: public QWidget
|
---|
18 | {
|
---|
19 | public:
|
---|
20 | MyWidget( QWidget *parent=0, const char *name=0 );
|
---|
21 | };
|
---|
22 |
|
---|
23 |
|
---|
24 | MyWidget::MyWidget( QWidget *parent, const char *name )
|
---|
25 | : QWidget( parent, name )
|
---|
26 | {
|
---|
27 | QPushButton *quit = new QPushButton( "&Quit", this, "quit" );
|
---|
28 | quit->setFont( QFont( "Times", 18, QFont::Bold ) );
|
---|
29 |
|
---|
30 | connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
|
---|
31 |
|
---|
32 | LCDRange *angle = new LCDRange( this, "angle" );
|
---|
33 | angle->setRange( 5, 70 );
|
---|
34 |
|
---|
35 | LCDRange *force = new LCDRange( this, "force" );
|
---|
36 | force->setRange( 10, 50 );
|
---|
37 |
|
---|
38 | CannonField *cannonField = new CannonField( this, "cannonField" );
|
---|
39 |
|
---|
40 | connect( angle, SIGNAL(valueChanged(int)),
|
---|
41 | cannonField, SLOT(setAngle(int)) );
|
---|
42 | connect( cannonField, SIGNAL(angleChanged(int)),
|
---|
43 | angle, SLOT(setValue(int)) );
|
---|
44 |
|
---|
45 | connect( force, SIGNAL(valueChanged(int)),
|
---|
46 | cannonField, SLOT(setForce(int)) );
|
---|
47 | connect( cannonField, SIGNAL(forceChanged(int)),
|
---|
48 | force, SLOT(setValue(int)) );
|
---|
49 |
|
---|
50 | QPushButton *shoot = new QPushButton( "&Shoot", this, "shoot" );
|
---|
51 | shoot->setFont( QFont( "Times", 18, QFont::Bold ) );
|
---|
52 |
|
---|
53 | connect( shoot, SIGNAL(clicked()), cannonField, SLOT(shoot()) );
|
---|
54 |
|
---|
55 | QGridLayout *grid = new QGridLayout( this, 2, 2, 10 );
|
---|
56 | grid->addWidget( quit, 0, 0 );
|
---|
57 | grid->addWidget( cannonField, 1, 1 );
|
---|
58 | grid->setColStretch( 1, 10 );
|
---|
59 |
|
---|
60 | QVBoxLayout *leftBox = new QVBoxLayout;
|
---|
61 | grid->addLayout( leftBox, 1, 0 );
|
---|
62 | leftBox->addWidget( angle );
|
---|
63 | leftBox->addWidget( force );
|
---|
64 |
|
---|
65 | QHBoxLayout *topBox = new QHBoxLayout;
|
---|
66 | grid->addLayout( topBox, 0, 1 );
|
---|
67 | topBox->addWidget( shoot );
|
---|
68 | topBox->addStretch( 1 );
|
---|
69 |
|
---|
70 | angle->setValue( 60 );
|
---|
71 | force->setValue( 25 );
|
---|
72 | angle->setFocus();
|
---|
73 | }
|
---|
74 |
|
---|
75 | int main( int argc, char **argv )
|
---|
76 | {
|
---|
77 | QApplication::setColorSpec( QApplication::CustomColor );
|
---|
78 | QApplication a( argc, argv );
|
---|
79 |
|
---|
80 | MyWidget w;
|
---|
81 | w.setGeometry( 100, 100, 500, 355 );
|
---|
82 | a.setMainWidget( &w );
|
---|
83 | w.show();
|
---|
84 | return a.exec();
|
---|
85 | }
|
---|