summaryrefslogtreecommitdiff
path: root/noncore/games/minesweep
Unidiff
Diffstat (limited to 'noncore/games/minesweep') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/minesweep/minesweep.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp
index c84fe53..814070b 100644
--- a/noncore/games/minesweep/minesweep.cpp
+++ b/noncore/games/minesweep/minesweep.cpp
@@ -153,193 +153,193 @@ static const char * dead_xpm[] = {
153" "}; 153" "};
154 154
155 155
156class ResultIndicator : private QLabel 156class ResultIndicator : private QLabel
157{ 157{
158public: 158public:
159 static void showResult( QWidget *ref, bool won ); 159 static void showResult( QWidget *ref, bool won );
160private: 160private:
161 ResultIndicator( QWidget *parent, const char *name, WFlags f) 161 ResultIndicator( QWidget *parent, const char *name, WFlags f)
162 :QLabel( parent, name, f ) {} 162 :QLabel( parent, name, f ) {}
163 163
164 void timerEvent( QTimerEvent *); 164 void timerEvent( QTimerEvent *);
165 void center(); 165 void center();
166 bool twoStage; 166 bool twoStage;
167 int timerId; 167 int timerId;
168}; 168};
169 169
170void ResultIndicator::showResult( QWidget *ref, bool won ) 170void ResultIndicator::showResult( QWidget *ref, bool won )
171{ 171{
172 ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); 172 ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel );
173 173
174 r->setAlignment( AlignCenter ); 174 r->setAlignment( AlignCenter );
175 r->setFrameStyle( Sunken|StyledPanel ); 175 r->setFrameStyle( Sunken|StyledPanel );
176 if ( won ) { 176 if ( won ) {
177 r->setText( MineSweep::tr("You won!") ); 177 r->setText( MineSweep::tr("You won!") );
178 r->center(); 178 r->center();
179 r->show(); 179 r->show();
180 r->twoStage = FALSE; 180 r->twoStage = FALSE;
181 r->timerId = r->startTimer(1500); 181 r->timerId = r->startTimer(1500);
182 } else { 182 } else {
183 QPalette p( red ); 183 QPalette p( red );
184 r->setPalette( p ); 184 r->setPalette( p );
185 r->setText( MineSweep::tr("You exploded!") ); 185 r->setText( MineSweep::tr("You exploded!") );
186 r->resize( ref->size() ); 186 r->resize( ref->size() );
187 r->move( ref->mapToGlobal(QPoint(0,0)) ); 187 r->move( ref->mapToGlobal(QPoint(0,0)) );
188 r->show(); 188 r->show();
189 r->twoStage = TRUE; 189 r->twoStage = TRUE;
190 r->timerId =r->startTimer(200); 190 r->timerId =r->startTimer(200);
191 } 191 }
192} 192}
193 193
194void ResultIndicator::center() 194void ResultIndicator::center()
195{ 195{
196 QWidget *w = parentWidget(); 196 QWidget *w = parentWidget();
197 197
198 QPoint pp = w->mapToGlobal( QPoint(0,0) ); 198 QPoint pp = w->mapToGlobal( QPoint(0,0) );
199 QSize s = sizeHint()*3; 199 QSize s = sizeHint()*3;
200 pp = QPoint( pp.x() + w->width()/2 - s.width()/2, 200 pp = QPoint( pp.x() + w->width()/2 - s.width()/2,
201 pp.y() + w->height()/ 2 - s.height()/2 ); 201 pp.y() + w->height()/ 2 - s.height()/2 );
202 202
203 setGeometry( QRect(pp, s) ); 203 setGeometry( QRect(pp, s) );
204 204
205} 205}
206 206
207void ResultIndicator::timerEvent( QTimerEvent *te ) 207void ResultIndicator::timerEvent( QTimerEvent *te )
208{ 208{
209 if ( te->timerId() != timerId ) 209 if ( te->timerId() != timerId )
210 return; 210 return;
211 killTimer( timerId ); 211 killTimer( timerId );
212 if ( twoStage ) { 212 if ( twoStage ) {
213 center(); 213 center();
214 twoStage = FALSE; 214 twoStage = FALSE;
215 timerId = startTimer( 1000 ); 215 timerId = startTimer( 1000 );
216 } else { 216 } else {
217 delete this; 217 delete this;
218 } 218 }
219} 219}
220 220
221 221
222class MineFrame : public QFrame 222class MineFrame : public QFrame
223{ 223{
224public: 224public:
225 MineFrame( QWidget *parent, const char *name = 0 ) 225 MineFrame( QWidget *parent, const char *name = 0 )
226 :QFrame( parent, name ) {} 226 :QFrame( parent, name ) {}
227 void setField( MineField *f ) { field = f; } 227 void setField( MineField *f ) { field = f; }
228protected: 228protected:
229 void resizeEvent( QResizeEvent *e ) { 229 void resizeEvent( QResizeEvent *e ) {
230 field->setAvailableRect( contentsRect()); 230 field->setAvailableRect( contentsRect());
231 QFrame::resizeEvent(e); 231 QFrame::resizeEvent(e);
232 } 232 }
233private: 233private:
234 MineField *field; 234 MineField *field;
235}; 235};
236 236
237 237
238 238
239MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) 239MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
240: QMainWindow( parent, name, f ) 240: QMainWindow( parent, name, f )
241{ 241{
242 srand(::time(0)); 242 srand(::time(0));
243 setCaption( tr("Mine Hunt") ); 243 setCaption( tr("Mine Hunt") );
244 setIcon( Resource::loadPixmap( "minesweep_icon" ) ); 244 setIcon( Resource::loadPixmap( "minesweep_icon" ) );
245 245
246 QPEToolBar *toolBar = new QPEToolBar( this ); 246 QPEToolBar *toolBar = new QPEToolBar( this );
247 toolBar->setHorizontalStretchable( TRUE ); 247 toolBar->setHorizontalStretchable( TRUE );
248 248
249 QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); 249 QMenuBar *menuBar = new QMenuBar( toolBar );
250 250
251 QPopupMenu *gameMenu = new QPopupMenu( this ); 251 QPopupMenu *gameMenu = new QPopupMenu( this );
252 gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); 252 gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) );
253 gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); 253 gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) );
254 gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); 254 gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) );
255 255
256 menuBar->insertItem( tr("Game"), gameMenu ); 256 menuBar->insertItem( tr("Game"), gameMenu );
257 257
258 guessLCD = new QLCDNumber( toolBar ); 258 guessLCD = new QLCDNumber( toolBar );
259 toolBar->setStretchableWidget( guessLCD ); 259 toolBar->setStretchableWidget( guessLCD );
260 260
261 QPalette lcdPal( red ); 261 QPalette lcdPal( red );
262 lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); 262 lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() );
263 lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); 263 lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() );
264 264
265// guessLCD->setPalette( lcdPal ); 265// guessLCD->setPalette( lcdPal );
266 guessLCD->setSegmentStyle( QLCDNumber::Flat ); 266 guessLCD->setSegmentStyle( QLCDNumber::Flat );
267 guessLCD->setFrameStyle( QFrame::NoFrame ); 267 guessLCD->setFrameStyle( QFrame::NoFrame );
268 guessLCD->setNumDigits( 2 ); 268 guessLCD->setNumDigits( 2 );
269 guessLCD->setBackgroundMode( PaletteButton ); 269 guessLCD->setBackgroundMode( PaletteButton );
270 newGameButton = new QPushButton( toolBar ); 270 newGameButton = new QPushButton( toolBar );
271 newGameButton->setPixmap( QPixmap( pix_new ) ); 271 newGameButton->setPixmap( QPixmap( pix_new ) );
272 newGameButton->setFocusPolicy(QWidget::NoFocus); 272 newGameButton->setFocusPolicy(QWidget::NoFocus);
273 connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); 273 connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) );
274 274
275 timeLCD = new QLCDNumber( toolBar ); 275 timeLCD = new QLCDNumber( toolBar );
276// timeLCD->setPalette( lcdPal ); 276// timeLCD->setPalette( lcdPal );
277 timeLCD->setSegmentStyle( QLCDNumber::Flat ); 277 timeLCD->setSegmentStyle( QLCDNumber::Flat );
278 timeLCD->setFrameStyle( QFrame::NoFrame ); 278 timeLCD->setFrameStyle( QFrame::NoFrame );
279 timeLCD->setNumDigits( 5 ); // "mm:ss" 279 timeLCD->setNumDigits( 5 ); // "mm:ss"
280 timeLCD->setBackgroundMode( PaletteButton ); 280 timeLCD->setBackgroundMode( PaletteButton );
281 281
282 setToolBarsMovable ( FALSE ); 282 setToolBarsMovable ( FALSE );
283 283
284 addToolBar( toolBar ); 284 addToolBar( toolBar );
285 285
286 MineFrame *mainframe = new MineFrame( this ); 286 MineFrame *mainframe = new MineFrame( this );
287 mainframe->setFrameShape( QFrame::Box ); 287 mainframe->setFrameShape( QFrame::Box );
288 mainframe->setFrameShadow( QFrame::Raised ); 288 mainframe->setFrameShadow( QFrame::Raised );
289 289
290 mainframe->setLineWidth(2); 290 mainframe->setLineWidth(2);
291 291
292 field = new MineField( mainframe ); 292 field = new MineField( mainframe );
293 mainframe->setField( field ); 293 mainframe->setField( field );
294 QFont fnt = field->font(); 294 QFont fnt = field->font();
295 fnt.setBold( TRUE ); 295 fnt.setBold( TRUE );
296 field->setFont( QFont( fnt ) ); 296 field->setFont( QFont( fnt ) );
297 field->setFocus(); 297 field->setFocus();
298 setCentralWidget( mainframe ); 298 setCentralWidget( mainframe );
299 299
300 connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); 300 connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) );
301 connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); 301 connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) );
302 connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); 302 connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) );
303 303
304 timer = new QTimer( this ); 304 timer = new QTimer( this );
305 305
306 connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); 306 connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) );
307 307
308 readConfig(); 308 readConfig();
309} 309}
310 310
311MineSweep::~MineSweep() 311MineSweep::~MineSweep()
312{ 312{
313 writeConfig(); 313 writeConfig();
314} 314}
315 315
316void MineSweep::gameOver( bool won ) 316void MineSweep::gameOver( bool won )
317{ 317{
318 field->showMines(); 318 field->showMines();
319 if ( won ) { 319 if ( won ) {
320 newGameButton->setPixmap( QPixmap( happy_xpm ) ); 320 newGameButton->setPixmap( QPixmap( happy_xpm ) );
321 } else { 321 } else {
322 newGameButton->setPixmap( QPixmap( dead_xpm ) ); 322 newGameButton->setPixmap( QPixmap( dead_xpm ) );
323 } 323 }
324 ResultIndicator::showResult( this, won ); 324 ResultIndicator::showResult( this, won );
325 timer->stop(); 325 timer->stop();
326} 326}
327 327
328void MineSweep::newGame() 328void MineSweep::newGame()
329{ 329{
330 newGame(field->level()); 330 newGame(field->level());
331} 331}
332 332
333void MineSweep::newGame(int level) 333void MineSweep::newGame(int level)
334{ 334{
335 timeLCD->display( "0:00" ); 335 timeLCD->display( "0:00" );
336 field->setup( level ); 336 field->setup( level );
337 newGameButton->setPixmap( QPixmap( pix_new ) ); 337 newGameButton->setPixmap( QPixmap( pix_new ) );
338 timer->stop(); 338 timer->stop();
339} 339}
340 340
341void MineSweep::startPlaying() 341void MineSweep::startPlaying()
342{ 342{
343 newGameButton->setPixmap( QPixmap( worried_xpm ) ); 343 newGameButton->setPixmap( QPixmap( worried_xpm ) );
344 starttime = QDateTime::currentDateTime(); 344 starttime = QDateTime::currentDateTime();
345 timer->start( 1000 ); 345 timer->start( 1000 );