summaryrefslogtreecommitdiff
path: root/noncore/games/minesweep
Side-by-side diff
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
@@ -22,3 +22,3 @@
-#include <qtable.h>
+#include <qscrollview.h>
@@ -27,3 +27,3 @@ class Config;
-class MineField : public QTable
+class MineField : public QScrollView
{
@@ -43,2 +43,3 @@ public:
+ void setAvailableRect( const QRect & );
public slots:
@@ -54,13 +55,18 @@ signals:
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:
@@ -71,2 +77,5 @@ protected slots:
private:
+ int findCellSize();
+ void setCellSize( int );
+
State stat;
@@ -79,2 +88,4 @@ private:
int currCol;
+ int numRows, numCols;
+
int minecount;
@@ -83,3 +94,6 @@ private:
int lev;
+ QRect availableRect;
+ int cellSize;
QTimer *holdTimer;
+ Mine **mines;
};
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
@@ -221,2 +221,19 @@ 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 )
@@ -228,4 +245,6 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
- QPEToolBar *menuToolBar = new QPEToolBar( this );
- QPEMenuBar *menuBar = new QPEMenuBar( menuToolBar );
+ QPEToolBar *toolBar = new QPEToolBar( this );
+ toolBar->setHorizontalStretchable( TRUE );
+
+ QPEMenuBar *menuBar = new QPEMenuBar( toolBar );
@@ -237,5 +256,2 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
menuBar->insertItem( tr("Game"), gameMenu );
-
- QPEToolBar *toolBar = new QPEToolBar( this );
- toolBar->setHorizontalStretchable( TRUE );
@@ -267,13 +283,12 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
- 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();