Diffstat (limited to 'noncore/games/minesweep/minesweep.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/minesweep/minesweep.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index 6492462..c84fe53 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -206,89 +206,104 @@ void ResultIndicator::center() | |||
206 | 206 | ||
207 | void ResultIndicator::timerEvent( QTimerEvent *te ) | 207 | void 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 | ||
222 | class MineFrame : public QFrame | ||
223 | { | ||
224 | public: | ||
225 | MineFrame( QWidget *parent, const char *name = 0 ) | ||
226 | :QFrame( parent, name ) {} | ||
227 | void setField( MineField *f ) { field = f; } | ||
228 | protected: | ||
229 | void resizeEvent( QResizeEvent *e ) { | ||
230 | field->setAvailableRect( contentsRect()); | ||
231 | QFrame::resizeEvent(e); | ||
232 | } | ||
233 | private: | ||
234 | MineField *field; | ||
235 | }; | ||
236 | |||
237 | |||
238 | |||
222 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | 239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) |
223 | : QMainWindow( parent, name, f ) | 240 | : QMainWindow( parent, name, f ) |
224 | { | 241 | { |
225 | srand(::time(0)); | 242 | srand(::time(0)); |
226 | setCaption( tr("Mine Hunt") ); | 243 | setCaption( tr("Mine Hunt") ); |
227 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); | 244 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); |
228 | 245 | ||
229 | QPEToolBar *menuToolBar = new QPEToolBar( this ); | 246 | QPEToolBar *toolBar = new QPEToolBar( this ); |
230 | QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar ); | 247 | toolBar->setHorizontalStretchable( TRUE ); |
248 | |||
249 | QPEMenuBar *menuBar = new QPEMenuBar( toolBar ); | ||
231 | 250 | ||
232 | QPopupMenu *gameMenu = new QPopupMenu( this ); | 251 | QPopupMenu *gameMenu = new QPopupMenu( this ); |
233 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 252 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
234 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 253 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
235 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 254 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); |
236 | 255 | ||
237 | menuBar->insertItem( tr("Game"), gameMenu ); | 256 | menuBar->insertItem( tr("Game"), gameMenu ); |
238 | |||
239 | QPEToolBar *toolBar = new QPEToolBar( this ); | ||
240 | toolBar->setHorizontalStretchable( TRUE ); | ||
241 | 257 | ||
242 | guessLCD = new QLCDNumber( toolBar ); | 258 | guessLCD = new QLCDNumber( toolBar ); |
243 | toolBar->setStretchableWidget( guessLCD ); | 259 | toolBar->setStretchableWidget( guessLCD ); |
244 | 260 | ||
245 | QPalette lcdPal( red ); | 261 | QPalette lcdPal( red ); |
246 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); | 262 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); |
247 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); | 263 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); |
248 | 264 | ||
249 | // guessLCD->setPalette( lcdPal ); | 265 | // guessLCD->setPalette( lcdPal ); |
250 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); | 266 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); |
251 | guessLCD->setFrameStyle( QFrame::NoFrame ); | 267 | guessLCD->setFrameStyle( QFrame::NoFrame ); |
252 | guessLCD->setNumDigits( 2 ); | 268 | guessLCD->setNumDigits( 2 ); |
253 | guessLCD->setBackgroundMode( PaletteButton ); | 269 | guessLCD->setBackgroundMode( PaletteButton ); |
254 | newGameButton = new QPushButton( toolBar ); | 270 | newGameButton = new QPushButton( toolBar ); |
255 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 271 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
256 | newGameButton->setFocusPolicy(QWidget::NoFocus); | 272 | newGameButton->setFocusPolicy(QWidget::NoFocus); |
257 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); | 273 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); |
258 | 274 | ||
259 | timeLCD = new QLCDNumber( toolBar ); | 275 | timeLCD = new QLCDNumber( toolBar ); |
260 | // timeLCD->setPalette( lcdPal ); | 276 | // timeLCD->setPalette( lcdPal ); |
261 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); | 277 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); |
262 | timeLCD->setFrameStyle( QFrame::NoFrame ); | 278 | timeLCD->setFrameStyle( QFrame::NoFrame ); |
263 | timeLCD->setNumDigits( 5 ); // "mm:ss" | 279 | timeLCD->setNumDigits( 5 ); // "mm:ss" |
264 | timeLCD->setBackgroundMode( PaletteButton ); | 280 | timeLCD->setBackgroundMode( PaletteButton ); |
265 | 281 | ||
266 | setToolBarsMovable ( FALSE ); | 282 | setToolBarsMovable ( FALSE ); |
267 | 283 | ||
268 | addToolBar( menuToolBar ); | ||
269 | addToolBar( toolBar ); | 284 | addToolBar( toolBar ); |
270 | 285 | ||
271 | QFrame *mainframe = new QFrame( this ); | 286 | MineFrame *mainframe = new MineFrame( this ); |
272 | mainframe->setFrameShape( QFrame::Box ); | 287 | mainframe->setFrameShape( QFrame::Box ); |
273 | mainframe->setFrameShadow( QFrame::Raised ); | 288 | mainframe->setFrameShadow( QFrame::Raised ); |
274 | mainframe->setMargin(5); | 289 | |
275 | mainframe->setLineWidth(2); | 290 | mainframe->setLineWidth(2); |
276 | QBoxLayout *box = new QVBoxLayout( mainframe ); | 291 | |
277 | field = new MineField( mainframe ); | 292 | field = new MineField( mainframe ); |
278 | box->addWidget( field, 0, AlignCenter ); | 293 | mainframe->setField( field ); |
279 | QFont fnt = field->font(); | 294 | QFont fnt = field->font(); |
280 | fnt.setBold( TRUE ); | 295 | fnt.setBold( TRUE ); |
281 | field->setFont( QFont( fnt ) ); | 296 | field->setFont( QFont( fnt ) ); |
282 | field->setFocus(); | 297 | field->setFocus(); |
283 | setCentralWidget( mainframe ); | 298 | setCentralWidget( mainframe ); |
284 | 299 | ||
285 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); | 300 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); |
286 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); | 301 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); |
287 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 302 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
288 | 303 | ||
289 | timer = new QTimer( this ); | 304 | timer = new QTimer( this ); |
290 | 305 | ||
291 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 306 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
292 | 307 | ||
293 | readConfig(); | 308 | readConfig(); |
294 | } | 309 | } |