1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the examples of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*
|
---|
43 | * KAsteroids - Copyright (c) Martin R. Jones 1997
|
---|
44 | *
|
---|
45 | * Part of the KDE project
|
---|
46 | */
|
---|
47 | // --- toplevel.cpp ---
|
---|
48 | #include <q3accel.h>
|
---|
49 | #include <qlabel.h>
|
---|
50 | #include <qlayout.h>
|
---|
51 | #include <qlcdnumber.h>
|
---|
52 | #include <qpushbutton.h>
|
---|
53 |
|
---|
54 | #include <qapplication.h>
|
---|
55 | //Added by qt3to4:
|
---|
56 | #include <Q3HBoxLayout>
|
---|
57 | #include <QShowEvent>
|
---|
58 | #include <Q3Frame>
|
---|
59 | #include <QPixmap>
|
---|
60 | #include <QHideEvent>
|
---|
61 | #include <QKeyEvent>
|
---|
62 | #include <Q3VBoxLayout>
|
---|
63 |
|
---|
64 | #include "toplevel.h"
|
---|
65 | #include "ledmeter.h"
|
---|
66 |
|
---|
67 |
|
---|
68 | #define SB_SCORE 1
|
---|
69 | #define SB_LEVEL 2
|
---|
70 | #define SB_SHIPS 3
|
---|
71 |
|
---|
72 | struct SLevel
|
---|
73 | {
|
---|
74 | int nrocks;
|
---|
75 | double rockSpeed;
|
---|
76 | };
|
---|
77 |
|
---|
78 | #define MAX_LEVELS 16
|
---|
79 |
|
---|
80 | SLevel levels[MAX_LEVELS] =
|
---|
81 | {
|
---|
82 | { 1, 0.4 },
|
---|
83 | { 1, 0.6 },
|
---|
84 | { 2, 0.5 },
|
---|
85 | { 2, 0.7 },
|
---|
86 | { 2, 0.8 },
|
---|
87 | { 3, 0.6 },
|
---|
88 | { 3, 0.7 },
|
---|
89 | { 3, 0.8 },
|
---|
90 | { 4, 0.6 },
|
---|
91 | { 4, 0.7 },
|
---|
92 | { 4, 0.8 },
|
---|
93 | { 5, 0.7 },
|
---|
94 | { 5, 0.8 },
|
---|
95 | { 5, 0.9 },
|
---|
96 | { 5, 1.0 }
|
---|
97 | };
|
---|
98 |
|
---|
99 | const char *soundEvents[] =
|
---|
100 | {
|
---|
101 | "ShipDestroyed",
|
---|
102 | "RockDestroyed",
|
---|
103 | 0
|
---|
104 | };
|
---|
105 |
|
---|
106 | const char *soundDefaults[] =
|
---|
107 | {
|
---|
108 | "Explosion.wav",
|
---|
109 | "ploop.wav",
|
---|
110 | 0
|
---|
111 | };
|
---|
112 |
|
---|
113 |
|
---|
114 | KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name )
|
---|
115 | : Q3MainWindow( parent, name, 0 )
|
---|
116 | {
|
---|
117 | QWidget *border = new QWidget( this );
|
---|
118 | border->setBackgroundColor( Qt::black );
|
---|
119 | setCentralWidget( border );
|
---|
120 |
|
---|
121 | Q3VBoxLayout *borderLayout = new Q3VBoxLayout( border );
|
---|
122 | borderLayout->addStretch( 1 );
|
---|
123 |
|
---|
124 | QWidget *mainWin = new QWidget( border );
|
---|
125 | mainWin->setFixedSize(640, 480);
|
---|
126 | borderLayout->addWidget( mainWin, 0, Qt::AlignHCenter );
|
---|
127 |
|
---|
128 | borderLayout->addStretch( 1 );
|
---|
129 |
|
---|
130 | view = new KAsteroidsView( mainWin );
|
---|
131 | view->setFocusPolicy( Qt::StrongFocus );
|
---|
132 | connect( view, SIGNAL( shipKilled() ), SLOT( slotShipKilled() ) );
|
---|
133 | connect( view, SIGNAL( rockHit(int) ), SLOT( slotRockHit(int) ) );
|
---|
134 | connect( view, SIGNAL( rocksRemoved() ), SLOT( slotRocksRemoved() ) );
|
---|
135 | connect( view, SIGNAL( updateVitals() ), SLOT( slotUpdateVitals() ) );
|
---|
136 |
|
---|
137 | Q3VBoxLayout *vb = new Q3VBoxLayout( mainWin );
|
---|
138 | Q3HBoxLayout *hb = new Q3HBoxLayout;
|
---|
139 | Q3HBoxLayout *hbd = new Q3HBoxLayout;
|
---|
140 | vb->addLayout( hb );
|
---|
141 |
|
---|
142 | QFont labelFont( "helvetica", 24 );
|
---|
143 | QColorGroup grp( Qt::darkGreen, Qt::black, QColor( 128, 128, 128 ),
|
---|
144 | QColor( 64, 64, 64 ), Qt::black, Qt::darkGreen, Qt::black );
|
---|
145 | QPalette pal( grp, grp, grp );
|
---|
146 |
|
---|
147 | mainWin->setPalette( pal );
|
---|
148 |
|
---|
149 | hb->addSpacing( 10 );
|
---|
150 |
|
---|
151 | QLabel *label;
|
---|
152 | label = new QLabel( tr("Score"), mainWin );
|
---|
153 | label->setFont( labelFont );
|
---|
154 | label->setPalette( pal );
|
---|
155 | label->setFixedWidth( label->sizeHint().width() );
|
---|
156 | hb->addWidget( label );
|
---|
157 |
|
---|
158 | scoreLCD = new QLCDNumber( 6, mainWin );
|
---|
159 | scoreLCD->setFrameStyle( Q3Frame::NoFrame );
|
---|
160 | scoreLCD->setSegmentStyle( QLCDNumber::Flat );
|
---|
161 | scoreLCD->setFixedWidth( 150 );
|
---|
162 | scoreLCD->setPalette( pal );
|
---|
163 | hb->addWidget( scoreLCD );
|
---|
164 | hb->addStretch( 10 );
|
---|
165 |
|
---|
166 | label = new QLabel( tr("Level"), mainWin );
|
---|
167 | label->setFont( labelFont );
|
---|
168 | label->setPalette( pal );
|
---|
169 | label->setFixedWidth( label->sizeHint().width() );
|
---|
170 | hb->addWidget( label );
|
---|
171 |
|
---|
172 | levelLCD = new QLCDNumber( 2, mainWin );
|
---|
|
---|