summaryrefslogtreecommitdiff
path: root/noncore/games/minesweep
authorkergoth <kergoth>2002-06-07 18:53:14 (UTC)
committer kergoth <kergoth>2002-06-07 18:53:14 (UTC)
commit640d964cfdc7467f6cacb513087cd3acda2c04f0 (patch) (side-by-side diff)
tree9a784686c1795f8b1f81eb344598f3b549d43467 /noncore/games/minesweep
parentdfb9c76738bb68e235114c5ad43dbd26a59b98ab (diff)
downloadopie-640d964cfdc7467f6cacb513087cd3acda2c04f0.zip
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.gz
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.bz2
Backing out unintentional merge from TT branch.
Diffstat (limited to 'noncore/games/minesweep') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/minesweep/minefield.h30
-rw-r--r--noncore/games/minesweep/minesweep.cpp35
2 files changed, 47 insertions, 18 deletions
diff --git a/noncore/games/minesweep/minefield.h b/noncore/games/minesweep/minefield.h
index 4ede435..1349c35 100644
--- a/noncore/games/minesweep/minefield.h
+++ b/noncore/games/minesweep/minefield.h
@@ -20,12 +20,12 @@
#ifndef MINEFIELD_H
#define MINEFIELD_H
-#include <qtable.h>
+#include <qscrollview.h>
class Mine;
class Config;
-class MineField : public QTable
+class MineField : public QScrollView
{
Q_OBJECT
public:
@@ -41,6 +41,7 @@ public:
int level() const { return lev; }
+ void setAvailableRect( const QRect & );
public slots:
void setup( int level );
@@ -52,23 +53,31 @@ signals:
void mineCount( int );
protected:
- void paintFocus( QPainter*, const QRect& );
- void viewportMousePressEvent( QMouseEvent* );
- void viewportMouseReleaseEvent( QMouseEvent* );
+
+ void contentsMousePressEvent( QMouseEvent* );
+ void contentsMouseReleaseEvent( QMouseEvent* );
void keyPressEvent( QKeyEvent* );
void keyReleaseEvent( QKeyEvent* );
-
+ void drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph );
+
int getHint( int row, int col );
- void setHint( Mine* );
+ void setHint( int r, int c );
void updateMine( int row, int col );
void paletteChange( const QPalette & );
-
+ void updateCell( int r, int c );
+ bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; }
+ Mine *mine( int row, int col ) { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
+ const Mine *mine( int row, int col ) const { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
+
protected slots:
void cellPressed( int row, int col );
void cellClicked( int row, int col );
void held();
private:
+ int findCellSize();
+ void setCellSize( int );
+
State stat;
void MineField::setState( State st );
void MineField::placeMines();
@@ -77,11 +86,16 @@ private:
bool ignoreClick;
int currRow;
int currCol;
+ int numRows, numCols;
+
int minecount;
int mineguess;
int nonminecount;
int lev;
+ QRect availableRect;
+ int cellSize;
QTimer *holdTimer;
+ Mine **mines;
};
#endif // MINEFIELD_H
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
@@ -219,6 +219,23 @@ void ResultIndicator::timerEvent( QTimerEvent *te )
}
+class MineFrame : public QFrame
+{
+public:
+ MineFrame( QWidget *parent, const char *name = 0 )
+ :QFrame( parent, name ) {}
+ void setField( MineField *f ) { field = f; }
+protected:
+ void resizeEvent( QResizeEvent *e ) {
+ field->setAvailableRect( contentsRect());
+ QFrame::resizeEvent(e);
+ }
+private:
+ MineField *field;
+};
+
+
+
MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
: QMainWindow( parent, name, f )
{
@@ -226,8 +243,10 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
setCaption( tr("Mine Hunt") );
setIcon( Resource::loadPixmap( "minesweep_icon" ) );
- QPEToolBar *menuToolBar = new QPEToolBar( this );
- QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
+ QPEToolBar *toolBar = new QPEToolBar( this );
+ toolBar->setHorizontalStretchable( TRUE );
+
+ QPEMenuBar *menuBar = new QPEMenuBar( toolBar );
QPopupMenu *gameMenu = new QPopupMenu( this );
gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) );
@@ -235,9 +254,6 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) );
menuBar->insertItem( tr("Game"), gameMenu );
-
- QPEToolBar *toolBar = new QPEToolBar( this );
- toolBar->setHorizontalStretchable( TRUE );
guessLCD = new QLCDNumber( toolBar );
toolBar->setStretchableWidget( guessLCD );
@@ -265,17 +281,16 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
setToolBarsMovable ( FALSE );
- addToolBar( menuToolBar );
addToolBar( toolBar );
- QFrame *mainframe = new QFrame( this );
+ MineFrame *mainframe = new MineFrame( this );
mainframe->setFrameShape( QFrame::Box );
mainframe->setFrameShadow( QFrame::Raised );
- mainframe->setMargin(5);
+
mainframe->setLineWidth(2);
- QBoxLayout *box = new QVBoxLayout( mainframe );
+
field = new MineField( mainframe );
- box->addWidget( field, 0, AlignCenter );
+ mainframe->setField( field );
QFont fnt = field->font();
fnt.setBold( TRUE );
field->setFont( QFont( fnt ) );