Diffstat (limited to 'noncore/games/minesweep/minefield.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/minesweep/minefield.cpp | 104 |
1 files changed, 65 insertions, 39 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,5 +1,5 @@ | |||
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 | ** |
@@ -21,3 +21,4 @@ | |||
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qtopia/config.h> |
23 | #include <qtopia/qpeapplication.h> | ||
23 | 24 | ||
@@ -71,3 +72,3 @@ static const char *pix_mine[]={ | |||
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 | ||
@@ -186,3 +187,5 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
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() ); |
@@ -190,3 +193,3 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
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 | } |
@@ -195,3 +198,5 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
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() ); |
@@ -199,6 +204,8 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
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 ); |
@@ -207,3 +214,5 @@ void Mine::paint( QPainter* p, const QColorGroup &cg, const QRect& cr ) | |||
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 ); |
@@ -285,2 +294,3 @@ MineField::MineField( QWidget* parent, const char* name ) | |||
285 | { | 294 | { |
295 | viewport()->setBackgroundMode( NoBackground ); | ||
286 | setState( GameOver ); | 296 | setState( GameOver ); |
@@ -301,3 +311,5 @@ MineField::MineField( QWidget* parent, const char* name ) | |||
301 | cellSize = -1; | 311 | cellSize = -1; |
302 | mines = 0; | 312 | |
313 | numRows = numCols = 0; | ||
314 | mines = NULL; | ||
303 | } | 315 | } |
@@ -306,12 +318,6 @@ MineField::~MineField() | |||
306 | { | 318 | { |
307 | int i; | 319 | for ( int i = 0; i < numCols*numRows; i++ ) |
308 | if ( mines ) | ||
309 | { | ||
310 | for ( i = 0; i < numCols*numRows; i++ ) | ||
311 | { | ||
312 | delete mines[i]; | 320 | delete mines[i]; |
313 | } | ||
314 | delete[] mines; | 321 | delete[] mines; |
315 | } | 322 | } |
316 | } | ||
317 | 323 | ||
@@ -329,10 +335,5 @@ void MineField::setup( int level ) | |||
329 | int i; | 335 | int i; |
330 | if ( mines ) | ||
331 | { | ||
332 | for ( i = 0; i < numCols*numRows; i++ ) | 336 | for ( i = 0; i < numCols*numRows; i++ ) |
333 | { | ||
334 | delete mines[i]; | 337 | delete mines[i]; |
335 | } | ||
336 | delete[] mines; | 338 | delete[] mines; |
337 | } | ||
338 | 339 | ||
@@ -345,5 +346,5 @@ void MineField::setup( int level ) | |||
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; |
@@ -399,3 +400,7 @@ void MineField::setAvailableRect( const QRect &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 ); |
@@ -409,4 +414,4 @@ 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; |
@@ -421,6 +426,3 @@ void MineField::setCellSize( int cellsize ) | |||
421 | { | 426 | { |
422 | cellSize = cellsize; | 427 | int b = 2; |
423 | |||
424 | int w = availableRect.width(); | ||
425 | int h = availableRect.height(); | ||
426 | 428 | ||
@@ -429,9 +431,20 @@ void MineField::setCellSize( int cellsize ) | |||
429 | 431 | ||
432 | int w = QMIN( availableRect.width(), w2+b ); | ||
433 | int h = QMIN( availableRect.height(), h2+b ); | ||
434 | |||
435 | // | ||
436 | // Don't rely on the change in cellsize to force a resize, | ||
437 | // as it's possible to have the same size cells when going | ||
438 | // from a large play area to a small one. | ||
439 | // | ||
430 | resizeContents( w2, h2 ); | 440 | resizeContents( w2, h2 ); |
431 | 441 | ||
432 | int b = 5; | 442 | if ( availableRect.height() < h2 && |
443 | availableRect.width() - w > style().scrollBarExtent().width() ) { | ||
444 | w += style().scrollBarExtent().width(); | ||
445 | } | ||
433 | 446 | ||
434 | setGeometry( availableRect.x() + (w-w2)/2, availableRect.y() + (h-h2)/2, | 447 | setGeometry( availableRect.x() + (availableRect.width()-w)/2, |
435 | w2+b, h2+b ); | 448 | availableRect.y() + (availableRect.height()-h)/2, w, h ); |
436 | // QMIN(w,w2+b), QMIN(h,h2+b) ); | 449 | cellSize = cellsize; |
437 | } | 450 | } |
@@ -615,2 +628,3 @@ void MineField::updateMine( int row, int col ) | |||
615 | if ( m->state() == Mine::Flagged ) { | 628 | if ( m->state() == Mine::Flagged ) { |
629 | if (mineguess > 0) { | ||
616 | --mineguess; | 630 | --mineguess; |
@@ -619,2 +633,5 @@ void MineField::updateMine( int row, int col ) | |||
619 | --minecount; | 633 | --minecount; |
634 | } else { | ||
635 | m->setState(Mine::Hidden); | ||
636 | } | ||
620 | } else if ( wasFlagged ) { | 637 | } else if ( wasFlagged ) { |
@@ -683,2 +700,3 @@ void MineField::readConfig(Config& cfg) | |||
683 | QString grid = cfg.readEntry("Grid"); | 700 | QString grid = cfg.readEntry("Grid"); |
701 | int x; | ||
684 | if ( !grid.isEmpty() ) { | 702 | if ( !grid.isEmpty() ) { |
@@ -687,3 +705,3 @@ void MineField::readConfig(Config& cfg) | |||
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++ ) { |
@@ -713,3 +731,3 @@ void MineField::readConfig(Config& cfg) | |||
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++ ) { |
@@ -725 +743,9 @@ void MineField::readConfig(Config& cfg) | |||
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 | |||