author | zecke <zecke> | 2004-02-06 12:28:33 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-02-06 12:28:33 (UTC) |
commit | c0207d7284d0f91a3a20f4abda2c6846c8dd8595 (patch) (unidiff) | |
tree | c95157ef87c805d870a68400858ff65b1ded03ac | |
parent | 0c74629e8f5c12a9b5a282b817f884fa10dee491 (diff) | |
download | opie-c0207d7284d0f91a3a20f4abda2c6846c8dd8595.zip opie-c0207d7284d0f91a3a20f4abda2c6846c8dd8595.tar.gz opie-c0207d7284d0f91a3a20f4abda2c6846c8dd8595.tar.bz2 |
Merge with Qtopia sources
-rw-r--r-- | noncore/games/minesweep/minefield.cpp | 144 | ||||
-rw-r--r-- | noncore/games/minesweep/minefield.h | 7 | ||||
-rw-r--r-- | noncore/games/minesweep/minesweep.cpp | 34 |
3 files changed, 110 insertions, 75 deletions
diff --git a/noncore/games/minesweep/minefield.cpp b/noncore/games/minesweep/minefield.cpp index 04cfb97..1790110 100644 --- a/noncore/games/minesweep/minefield.cpp +++ b/noncore/games/minesweep/minefield.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
@@ -20,5 +20,6 @@ | |||
20 | #include "minefield.h" | 20 | #include "minefield.h" |
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qtopia/config.h> |
23 | #include <qtopia/qpeapplication.h> | ||
23 | 24 | ||
24 | #include <qpainter.h> | 25 | #include <qpainter.h> |
@@ -70,5 +71,5 @@ static const char *pix_mine[]={ | |||
70 | 71 | ||
71 | static const int maxGrid = 28; | 72 | static const int maxGrid = 28; |
72 | static const int minGrid = 9; | 73 | static const int minGrid = 12; |
73 | 74 | ||
74 | 75 | ||
@@ -185,26 +186,34 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
185 | int x = cr.x(); | 186 | int x = cr.x(); |
186 | int y = cr.y(); | 187 | int y = cr.y(); |
187 | if ( !knownField ) { | 188 | if ( !knownField || knownField->width() != cr.width() || |
189 | knownField->height() != cr.height() ) { | ||
190 | delete knownField; | ||
188 | knownField = new QPixmap( cr.width(), cr.height() ); | 191 | knownField = new QPixmap( cr.width(), cr.height() ); |
189 | QPainter pp( knownField ); | 192 | QPainter pp( knownField ); |
190 | QBrush br( cg.button().dark(115) ); | 193 | QBrush br( cg.button().dark(115) ); |
191 | qDrawWinButton( &pp, cr, cg, TRUE, &br ); | 194 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, TRUE, &br ); |
192 | } | 195 | } |
193 | 196 | ||
194 | const int pmmarg=cr.width()/5; | 197 | const int pmmarg=cr.width()/5; |
195 | 198 | ||
196 | if ( !unknownField ) { | 199 | if ( !unknownField || unknownField->width() != cr.width() || |
200 | unknownField->height() != cr.height() ) { | ||
201 | delete unknownField; | ||
197 | unknownField = new QPixmap( cr.width(), cr.height() ); | 202 | unknownField = new QPixmap( cr.width(), cr.height() ); |
198 | QPainter pp( unknownField ); | 203 | QPainter pp( unknownField ); |
199 | QBrush br( cg.button() ); | 204 | QBrush br( cg.button() ); |
200 | qDrawWinButton( &pp, cr, cg, FALSE, &br ); | 205 | qDrawWinButton( &pp, QRect( 0, 0, cr.width(), cr.height() ), cg, FALSE, &br ); |
201 | } | 206 | } |
202 | 207 | ||
203 | if ( !flag_pix ) { | 208 | if ( !flag_pix || flag_pix->width() != cr.width()-pmmarg*2 || |
209 | flag_pix->height() != cr.height()-pmmarg*2 ) { | ||
210 | delete flag_pix; | ||
204 | flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); | 211 | flag_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); |
205 | flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); | 212 | flag_pix->convertFromImage( QImage(pix_flag).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); |
206 | } | 213 | } |
207 | 214 | ||
208 | if ( !mine_pix ) { | 215 | if ( !mine_pix || mine_pix->width() != cr.width()-pmmarg*2 || |
216 | mine_pix->height() != cr.height()-pmmarg*2 ) { | ||
217 | delete mine_pix; | ||
209 | mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); | 218 | mine_pix = new QPixmap( cr.width()-pmmarg*2, cr.height()-pmmarg*2 ); |
210 | mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); | 219 | mine_pix->convertFromImage( QImage(pix_mine).smoothScale(cr.width()-pmmarg*2, cr.height()-pmmarg*2) ); |
@@ -284,8 +293,9 @@ MineField::MineField( QWidget* parent, const char* name ) | |||
284 | : QScrollView( parent, name ) | 293 | : QScrollView( parent, name ) |
285 | { | 294 | { |
295 | viewport()->setBackgroundMode( NoBackground ); | ||
286 | setState( GameOver ); | 296 | setState( GameOver ); |
287 | 297 | ||
288 | setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); | 298 | setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Maximum ) ); |
289 | 299 | ||
290 | setFocusPolicy( QWidget::NoFocus ); | 300 | setFocusPolicy( QWidget::NoFocus ); |
291 | 301 | ||
@@ -300,18 +310,14 @@ MineField::MineField( QWidget* parent, const char* name ) | |||
300 | nonminecount=0; | 310 | nonminecount=0; |
301 | cellSize = -1; | 311 | cellSize = -1; |
302 | mines = 0; | 312 | |
313 | numRows = numCols = 0; | ||
314 | mines = NULL; | ||
303 | } | 315 | } |
304 | 316 | ||
305 | MineField::~MineField() | 317 | MineField::~MineField() |
306 | { | 318 | { |
307 | int i; | 319 | for ( int i = 0; i < numCols*numRows; i++ ) |
308 | if ( mines ) | 320 | delete mines[i]; |
309 | { | 321 | delete[] mines; |
310 | for ( i = 0; i < numCols*numRows; i++ ) | ||
311 | { | ||
312 | delete mines[i]; | ||
313 | } | ||
314 | delete[] mines; | ||
315 | } | ||
316 | } | 322 | } |
317 | 323 | ||
@@ -328,12 +334,7 @@ void MineField::setup( int level ) | |||
328 | 334 | ||
329 | int i; | 335 | int i; |
330 | if ( mines ) | 336 | for ( i = 0; i < numCols*numRows; i++ ) |
331 | { | 337 | delete mines[i]; |
332 | for ( i = 0; i < numCols*numRows; i++ ) | 338 | delete[] mines; |
333 | { | ||
334 | delete mines[i]; | ||
335 | } | ||
336 | delete[] mines; | ||
337 | } | ||
338 | 339 | ||
339 | switch( lev ) { | 340 | switch( lev ) { |
@@ -344,7 +345,7 @@ void MineField::setup( int level ) | |||
344 | break; | 345 | break; |
345 | case 2: | 346 | case 2: |
346 | numRows = 16; | 347 | numRows = 13; |
347 | numCols = 16; | 348 | numCols = 13; |
348 | minecount = 45; | 349 | minecount = 33; |
349 | break; | 350 | break; |
350 | case 3: | 351 | case 3: |
@@ -354,9 +355,9 @@ void MineField::setup( int level ) | |||
354 | break; | 355 | break; |
355 | } | 356 | } |
356 | mines = new Mine*[numRows*numCols]; | 357 | mines = new Mine* [numRows*numCols]; |
357 | for ( i = 0; i < numCols*numRows; i++ ) | 358 | for ( i = 0; i < numCols*numRows; i++ ) |
358 | mines[i] = new Mine( this ); | 359 | mines[i] = new Mine( this ); |
359 | 360 | ||
360 | 361 | ||
361 | nonminecount = numRows*numCols - minecount; | 362 | nonminecount = numRows*numCols - minecount; |
362 | mineguess = minecount; | 363 | mineguess = minecount; |
@@ -372,5 +373,5 @@ void MineField::setup( int level ) | |||
372 | } | 373 | } |
373 | 374 | ||
374 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) | 375 | void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph ) |
375 | { | 376 | { |
376 | int c1 = clipx / cellSize; | 377 | int c1 = clipx / cellSize; |
@@ -378,5 +379,5 @@ void MineField::drawContents( QPainter * p, int clipx, int clipy, int clipw, int | |||
378 | int r1 = clipy / cellSize; | 379 | int r1 = clipy / cellSize; |
379 | int r2 = ( clipy + cliph - 1 ) / cellSize; | 380 | int r2 = ( clipy + cliph - 1 ) / cellSize; |
380 | 381 | ||
381 | for ( int c = c1; c <= c2 ; c++ ) { | 382 | for ( int c = c1; c <= c2 ; c++ ) { |
382 | for ( int r = r1; r <= r2 ; r++ ) { | 383 | for ( int r = r1; r <= r2 ; r++ ) { |
@@ -398,5 +399,9 @@ void MineField::setAvailableRect( const QRect &r ) | |||
398 | availableRect = r; | 399 | availableRect = r; |
399 | int newCellSize = findCellSize(); | 400 | int newCellSize = findCellSize(); |
400 | if ( newCellSize != cellSize ) { | 401 | |
402 | |||
403 | if ( newCellSize == cellSize ) { | ||
404 | setCellSize( cellSize ); | ||
405 | } else { | ||
401 | viewport()->setUpdatesEnabled( FALSE ); | 406 | viewport()->setUpdatesEnabled( FALSE ); |
402 | setCellSize( newCellSize ); | 407 | setCellSize( newCellSize ); |
@@ -408,8 +413,8 @@ void MineField::setAvailableRect( const QRect &r ) | |||
408 | int MineField::findCellSize() | 413 | int MineField::findCellSize() |
409 | { | 414 | { |
410 | int w = availableRect.width() - 1; | 415 | int w = availableRect.width() - 2; |
411 | int h = availableRect.height() - 1; | 416 | int h = availableRect.height() - 2; |
412 | int cellsize; | 417 | int cellsize; |
413 | 418 | ||
414 | cellsize = QMIN( w/numCols, h/numRows ); | 419 | cellsize = QMIN( w/numCols, h/numRows ); |
415 | cellsize = QMIN( QMAX( cellsize, minGrid ), maxGrid ); | 420 | cellsize = QMIN( QMAX( cellsize, minGrid ), maxGrid ); |
@@ -420,19 +425,27 @@ int MineField::findCellSize() | |||
420 | void MineField::setCellSize( int cellsize ) | 425 | void MineField::setCellSize( int cellsize ) |
421 | { | 426 | { |
422 | cellSize = cellsize; | 427 | int b = 2; |
423 | 428 | ||
424 | int w = availableRect.width(); | ||
425 | int h = availableRect.height(); | ||
426 | |||
427 | int w2 = cellsize*numCols; | 429 | int w2 = cellsize*numCols; |
428 | int h2 = cellsize*numRows; | 430 | int h2 = cellsize*numRows; |
429 | 431 | ||
430 | resizeContents( w2, h2 ); | 432 | int w = QMIN( availableRect.width(), w2+b ); |
431 | 433 | int h = QMIN( availableRect.height(), h2+b ); | |
432 | int b = 5; | 434 | |
433 | 435 | // | |
434 | setGeometry( availableRect.x() + (w-w2)/2, availableRect.y() + (h-h2)/2, | 436 | // Don't rely on the change in cellsize to force a resize, |
435 | w2+b, h2+b ); | 437 | // as it's possible to have the same size cells when going |
436 | // QMIN(w,w2+b), QMIN(h,h2+b) ); | 438 | // from a large play area to a small one. |
439 | // | ||
440 | resizeContents(w2, h2); | ||
441 | |||
442 | if ( availableRect.height() < h2 && | ||
443 | availableRect.width() - w > style().scrollBarExtent().width() ) { | ||
444 | w += style().scrollBarExtent().width(); | ||
445 | } | ||
446 | |||
447 | setGeometry( availableRect.x() + (availableRect.width()-w)/2, | ||
448 | availableRect.y() + (availableRect.height()-h)/2, w, h ); | ||
449 | cellSize = cellsize; | ||
437 | } | 450 | } |
438 | 451 | ||
@@ -614,8 +627,12 @@ void MineField::updateMine( int row, int col ) | |||
614 | if ( flagAction != NoAction ) { | 627 | if ( flagAction != NoAction ) { |
615 | if ( m->state() == Mine::Flagged ) { | 628 | if ( m->state() == Mine::Flagged ) { |
616 | --mineguess; | 629 | if (mineguess > 0) { |
617 | emit mineCount( mineguess ); | 630 | --mineguess; |
618 | if ( m->isMined() ) | 631 | emit mineCount( mineguess ); |
619 | --minecount; | 632 | if ( m->isMined() ) |
633 | --minecount; | ||
634 | } else { | ||
635 | m->setState(Mine::Hidden); | ||
636 | } | ||
620 | } else if ( wasFlagged ) { | 637 | } else if ( wasFlagged ) { |
621 | ++mineguess; | 638 | ++mineguess; |
@@ -682,9 +699,10 @@ void MineField::readConfig(Config& cfg) | |||
682 | currRow = currCol = 0; | 699 | currRow = currCol = 0; |
683 | QString grid = cfg.readEntry("Grid"); | 700 | QString grid = cfg.readEntry("Grid"); |
701 | int x; | ||
684 | if ( !grid.isEmpty() ) { | 702 | if ( !grid.isEmpty() ) { |
685 | int i=0; | 703 | int i=0; |
686 | minecount=0; | 704 | minecount=0; |
687 | mineguess=0; | 705 | mineguess=0; |
688 | for ( int x = 0; x < numCols; x++ ) { | 706 | for ( x = 0; x < numCols; x++ ) { |
689 | for ( int y = 0; y < numRows; y++ ) { | 707 | for ( int y = 0; y < numRows; y++ ) { |
690 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat | 708 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat |
@@ -712,5 +730,5 @@ void MineField::readConfig(Config& cfg) | |||
712 | } | 730 | } |
713 | } | 731 | } |
714 | for ( int x = 0; x < numCols; x++ ) { | 732 | for ( x = 0; x < numCols; x++ ) { |
715 | for ( int y = 0; y < numRows; y++ ) { | 733 | for ( int y = 0; y < numRows; y++ ) { |
716 | Mine* m = mine( y, x ); | 734 | Mine* m = mine( y, x ); |
@@ -724,2 +742,10 @@ void MineField::readConfig(Config& cfg) | |||
724 | } | 742 | } |
725 | 743 | ||
744 | QSize MineField::sizeHint() const | ||
745 | { | ||
746 | if ( qApp->desktop()->width() >= 240 ) | ||
747 | return QSize(200,200); | ||
748 | else | ||
749 | return QSize(160, 160); | ||
750 | } | ||
751 | |||
diff --git a/noncore/games/minesweep/minefield.h b/noncore/games/minesweep/minefield.h index 1349c35..e243d77 100644 --- a/noncore/games/minesweep/minefield.h +++ b/noncore/games/minesweep/minefield.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
@@ -43,4 +43,7 @@ public: | |||
43 | 43 | ||
44 | void setAvailableRect( const QRect & ); | 44 | void setAvailableRect( const QRect & ); |
45 | |||
46 | QSize sizeHint() const; | ||
47 | |||
45 | public slots: | 48 | public slots: |
46 | void setup( int level ); | 49 | void setup( int level ); |
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index 7214a73..d707dab 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
@@ -22,9 +22,9 @@ | |||
22 | #include "minefield.h" | 22 | #include "minefield.h" |
23 | 23 | ||
24 | #include <qpe/qpeapplication.h> | 24 | #include <qtopia/qpeapplication.h> |
25 | #include <qpe/resource.h> | 25 | #include <qtopia/resource.h> |
26 | #include <qpe/config.h> | 26 | #include <qtopia/config.h> |
27 | 27 | ||
28 | #include <qpe/qpetoolbar.h> | 28 | #include <qtoolbar.h> |
29 | #include <qmenubar.h> | 29 | #include <qmenubar.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
@@ -199,4 +199,5 @@ void ResultIndicator::center() | |||
199 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | 199 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); |
200 | QSize s = sizeHint()*3; | 200 | QSize s = sizeHint()*3; |
201 | s.setWidth( QMIN(s.width(), w->width()) ); | ||
201 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, | 202 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, |
202 | pp.y() + w->height()/ 2 - s.height()/2 ); | 203 | pp.y() + w->height()/ 2 - s.height()/2 ); |
@@ -225,6 +226,9 @@ class MineFrame : public QFrame | |||
225 | public: | 226 | public: |
226 | MineFrame( QWidget *parent, const char *name = 0 ) | 227 | MineFrame( QWidget *parent, const char *name = 0 ) |
227 | :QFrame( parent, name ) {} | 228 | :QFrame( parent, name ), field(0) {} |
228 | void setField( MineField *f ) { field = f; } | 229 | void setField( MineField *f ) { |
230 | field = f; | ||
231 | setMinimumSize( field->sizeHint() ); | ||
232 | } | ||
229 | protected: | 233 | protected: |
230 | void resizeEvent( QResizeEvent *e ) { | 234 | void resizeEvent( QResizeEvent *e ) { |
@@ -241,8 +245,8 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | |||
241 | : QMainWindow( parent, name, f ) | 245 | : QMainWindow( parent, name, f ) |
242 | { | 246 | { |
243 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); | ||
244 | srand(::time(0)); | 247 | srand(::time(0)); |
245 | setCaption( tr("Mine Hunt") ); | 248 | setCaption( tr("Mine Hunt") ); |
246 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); | 249 | QPEApplication::setInputMethodHint(this, QPEApplication::AlwaysOff ); |
250 | setIcon( Resource::loadPixmap( "minesweep/MineHunt" ) ); | ||
247 | 251 | ||
248 | QToolBar *toolBar = new QToolBar( this ); | 252 | QToolBar *toolBar = new QToolBar( this ); |
@@ -254,5 +258,8 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | |||
254 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 258 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
255 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 259 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
256 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 260 | |
261 | if (qApp->desktop()->width() >= 240) { | ||
262 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | ||
263 | } | ||
257 | 264 | ||
258 | menuBar->insertItem( tr("Game"), gameMenu ); | 265 | menuBar->insertItem( tr("Game"), gameMenu ); |
@@ -300,10 +307,9 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | |||
300 | setCentralWidget( mainframe ); | 307 | setCentralWidget( mainframe ); |
301 | 308 | ||
302 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); | 309 | connect( field, SIGNAL( gameOver(bool) ), this, SLOT( gameOver(bool) ) ); |
303 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); | 310 | connect( field, SIGNAL( mineCount(int) ), this, SLOT( setCounter(int) ) ); |
304 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 311 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
305 | 312 | ||
306 | timer = new QTimer( this ); | 313 | timer = new QTimer( this ); |
307 | |||
308 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 314 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
309 | 315 | ||