summaryrefslogtreecommitdiff
path: root/noncore/games/minesweep/minesweep.cpp
Unidiff
Diffstat (limited to 'noncore/games/minesweep/minesweep.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/minesweep/minesweep.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp
index 48644b3..7214a73 100644
--- a/noncore/games/minesweep/minesweep.cpp
+++ b/noncore/games/minesweep/minesweep.cpp
@@ -18,12 +18,13 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "minesweep.h" 21#include "minesweep.h"
22#include "minefield.h" 22#include "minefield.h"
23 23
24#include <qpe/qpeapplication.h>
24#include <qpe/resource.h> 25#include <qpe/resource.h>
25#include <qpe/config.h> 26#include <qpe/config.h>
26 27
27#include <qpe/qpetoolbar.h> 28#include <qpe/qpetoolbar.h>
28#include <qmenubar.h> 29#include <qmenubar.h>
29#include <qpopupmenu.h> 30#include <qpopupmenu.h>
@@ -152,28 +153,28 @@ static const char * dead_xpm[] = {
152" ###### ", 153" ###### ",
153" "}; 154" "};
154 155
155 156
156class ResultIndicator : private QLabel 157class ResultIndicator : private QLabel
157{ 158{
158public: 159public:
159 static void showResult( QWidget *ref, bool won ); 160 static void showResult( QWidget *ref, bool won );
160private: 161private:
161 ResultIndicator( QWidget *parent, const char *name, WFlags f) 162 ResultIndicator( QWidget *parent, const char *name, WFlags f)
162 :QLabel( parent, name, f ) {} 163 :QLabel( parent, name, f ) {}
163 164
164 void timerEvent( QTimerEvent *); 165 void timerEvent( QTimerEvent *);
165 void center(); 166 void center();
166 bool twoStage; 167 bool twoStage;
167 int timerId; 168 int timerId;
168}; 169};
169 170
170void ResultIndicator::showResult( QWidget *ref, bool won ) 171void ResultIndicator::showResult( QWidget *ref, bool won )
171{ 172{
172 ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); 173 ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel );
173 174
174 r->setAlignment( AlignCenter ); 175 r->setAlignment( AlignCenter );
175 r->setFrameStyle( Sunken|StyledPanel ); 176 r->setFrameStyle( Sunken|StyledPanel );
176 if ( won ) { 177 if ( won ) {
177 r->setText( MineSweep::tr("You won!") ); 178 r->setText( MineSweep::tr("You won!") );
178 r->center(); 179 r->center();
179 r->show(); 180 r->show();
@@ -192,19 +193,19 @@ void ResultIndicator::showResult( QWidget *ref, bool won )
192} 193}
193 194
194void ResultIndicator::center() 195void ResultIndicator::center()
195{ 196{
196 QWidget *w = parentWidget(); 197 QWidget *w = parentWidget();
197 198
198 QPoint pp = w->mapToGlobal( QPoint(0,0) ); 199 QPoint pp = w->mapToGlobal( QPoint(0,0) );
199 QSize s = sizeHint()*3; 200 QSize s = sizeHint()*3;
200 pp = QPoint( pp.x() + w->width()/2 - s.width()/2, 201 pp = QPoint( pp.x() + w->width()/2 - s.width()/2,
201 pp.y() + w->height()/ 2 - s.height()/2 ); 202 pp.y() + w->height()/ 2 - s.height()/2 );
202 203
203 setGeometry( QRect(pp, s) ); 204 setGeometry( QRect(pp, s) );
204 205
205} 206}
206 207
207void ResultIndicator::timerEvent( QTimerEvent *te ) 208void ResultIndicator::timerEvent( QTimerEvent *te )
208{ 209{
209 if ( te->timerId() != timerId ) 210 if ( te->timerId() != timerId )
210 return; 211 return;
@@ -225,23 +226,24 @@ public:
225 MineFrame( QWidget *parent, const char *name = 0 ) 226 MineFrame( QWidget *parent, const char *name = 0 )
226 :QFrame( parent, name ) {} 227 :QFrame( parent, name ) {}
227 void setField( MineField *f ) { field = f; } 228 void setField( MineField *f ) { field = f; }
228protected: 229protected:
229 void resizeEvent( QResizeEvent *e ) { 230 void resizeEvent( QResizeEvent *e ) {
230 field->setAvailableRect( contentsRect()); 231 field->setAvailableRect( contentsRect());
231 QFrame::resizeEvent(e); 232 QFrame::resizeEvent(e);
232 } 233 }
233private: 234private:
234 MineField *field; 235 MineField *field;
235}; 236};
236 237
237 238
238 239
239MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) 240MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
240: QMainWindow( parent, name, f ) 241: QMainWindow( parent, name, f )
241{ 242{
243 QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff );
242 srand(::time(0)); 244 srand(::time(0));
243 setCaption( tr("Mine Hunt") ); 245 setCaption( tr("Mine Hunt") );
244 setIcon( Resource::loadPixmap( "minesweep_icon" ) ); 246 setIcon( Resource::loadPixmap( "minesweep_icon" ) );
245 247
246 QToolBar *toolBar = new QToolBar( this ); 248 QToolBar *toolBar = new QToolBar( this );
247 toolBar->setHorizontalStretchable( TRUE ); 249 toolBar->setHorizontalStretchable( TRUE );
@@ -251,37 +253,37 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
251 QPopupMenu *gameMenu = new QPopupMenu( this ); 253 QPopupMenu *gameMenu = new QPopupMenu( this );
252 gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); 254 gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) );
253 gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); 255 gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) );
254 gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); 256 gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) );
255 257
256 menuBar->insertItem( tr("Game"), gameMenu ); 258 menuBar->insertItem( tr("Game"), gameMenu );
257 259
258 guessLCD = new QLCDNumber( toolBar ); 260 guessLCD = new QLCDNumber( toolBar );
259 toolBar->setStretchableWidget( guessLCD ); 261 toolBar->setStretchableWidget( guessLCD );
260 262
261 QPalette lcdPal( red ); 263 QPalette lcdPal( red );
262 lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); 264 lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() );
263 lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); 265 lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() );
264 266
265// guessLCD->setPalette( lcdPal ); 267// guessLCD->setPalette( lcdPal );
266 guessLCD->setSegmentStyle( QLCDNumber::Flat ); 268 guessLCD->setSegmentStyle( QLCDNumber::Flat );
267 guessLCD->setFrameStyle( QFrame::NoFrame ); 269 guessLCD->setFrameStyle( QFrame::NoFrame );
268 guessLCD->setNumDigits( 2 ); 270 guessLCD->setNumDigits( 2 );
269 guessLCD->setBackgroundMode( PaletteButton ); 271 guessLCD->setBackgroundMode( PaletteButton );
270 newGameButton = new QPushButton( toolBar ); 272 newGameButton = new QPushButton( toolBar );
271 newGameButton->setPixmap( QPixmap( pix_new ) ); 273 newGameButton->setPixmap( QPixmap( pix_new ) );
272 newGameButton->setFocusPolicy(QWidget::NoFocus); 274 newGameButton->setFocusPolicy(QWidget::NoFocus);
273 connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); 275 connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) );
274 276
275 timeLCD = new QLCDNumber( toolBar ); 277 timeLCD = new QLCDNumber( toolBar );
276// timeLCD->setPalette( lcdPal ); 278// timeLCD->setPalette( lcdPal );
277 timeLCD->setSegmentStyle( QLCDNumber::Flat ); 279 timeLCD->setSegmentStyle( QLCDNumber::Flat );
278 timeLCD->setFrameStyle( QFrame::NoFrame ); 280 timeLCD->setFrameStyle( QFrame::NoFrame );
279 timeLCD->setNumDigits( 5 ); // "mm:ss" 281 timeLCD->setNumDigits( 5 ); // "mm:ss"
280 timeLCD->setBackgroundMode( PaletteButton ); 282 timeLCD->setBackgroundMode( PaletteButton );
281 283
282 setToolBarsMovable ( FALSE ); 284 setToolBarsMovable ( FALSE );
283 285
284 addToolBar( toolBar ); 286 addToolBar( toolBar );
285 287
286 MineFrame *mainframe = new MineFrame( this ); 288 MineFrame *mainframe = new MineFrame( this );
287 mainframe->setFrameShape( QFrame::Box ); 289 mainframe->setFrameShape( QFrame::Box );
@@ -293,13 +295,13 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
293 mainframe->setField( field ); 295 mainframe->setField( field );
294 QFont fnt = field->font(); 296 QFont fnt = field->font();
295 fnt.setBold( TRUE ); 297 fnt.setBold( TRUE );
296 field->setFont( QFont( fnt ) ); 298 field->setFont( QFont( fnt ) );
297 field->setFocus(); 299 field->setFocus();
298 setCentralWidget( mainframe ); 300 setCentralWidget( mainframe );
299 301
300 connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); 302 connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) );
301 connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); 303 connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) );
302 connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); 304 connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) );
303 305
304 timer = new QTimer( this ); 306 timer = new QTimer( this );
305 307