summaryrefslogtreecommitdiff
path: root/noncore/games/minesweep
Unidiff
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 @@
22 22
23#include <qtable.h> 23#include <qscrollview.h>
24 24
@@ -27,3 +27,3 @@ class Config;
27 27
28class MineField : public QTable 28class MineField : public QScrollView
29{ 29{
@@ -43,2 +43,3 @@ public:
43 43
44 void setAvailableRect( const QRect & );
44public slots: 45public slots:
@@ -54,13 +55,18 @@ signals:
54protected: 55protected:
55 void paintFocus( QPainter*, const QRect& ); 56
56 void viewportMousePressEvent( QMouseEvent* ); 57 void contentsMousePressEvent( QMouseEvent* );
57 void viewportMouseReleaseEvent( QMouseEvent* ); 58 void contentsMouseReleaseEvent( QMouseEvent* );
58 void keyPressEvent( QKeyEvent* ); 59 void keyPressEvent( QKeyEvent* );
59 void keyReleaseEvent( QKeyEvent* ); 60 void keyReleaseEvent( QKeyEvent* );
60 61 void drawContents( QPainter * p, int clipx, int clipy, int clipw, int cliph );
62
61 int getHint( int row, int col ); 63 int getHint( int row, int col );
62 void setHint( Mine* ); 64 void setHint( int r, int c );
63 void updateMine( int row, int col ); 65 void updateMine( int row, int col );
64 void paletteChange( const QPalette & ); 66 void paletteChange( const QPalette & );
65 67 void updateCell( int r, int c );
68 bool onBoard( int r, int c ) const { return r >= 0 && r < numRows && c >= 0 && c < numCols; }
69 Mine *mine( int row, int col ) { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
70 const Mine *mine( int row, int col ) const { return onBoard(row, col ) ? mines[row+numCols*col] : 0; }
71
66protected slots: 72protected slots:
@@ -71,2 +77,5 @@ protected slots:
71private: 77private:
78 int findCellSize();
79 void setCellSize( int );
80
72 State stat; 81 State stat;
@@ -79,2 +88,4 @@ private:
79 int currCol; 88 int currCol;
89 int numRows, numCols;
90
80 int minecount; 91 int minecount;
@@ -83,3 +94,6 @@ private:
83 int lev; 94 int lev;
95 QRect availableRect;
96 int cellSize;
84 QTimer *holdTimer; 97 QTimer *holdTimer;
98 Mine **mines;
85}; 99};
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 )
221 221
222class MineFrame : public QFrame
223{
224public:
225 MineFrame( QWidget *parent, const char *name = 0 )
226 :QFrame( parent, name ) {}
227 void setField( MineField *f ) { field = f; }
228protected:
229 void resizeEvent( QResizeEvent *e ) {
230 field->setAvailableRect( contentsRect());
231 QFrame::resizeEvent(e);
232 }
233private:
234 MineField *field;
235};
236
237
238
222MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) 239MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
@@ -228,4 +245,6 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
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
@@ -237,5 +256,2 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
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
@@ -267,13 +283,12 @@ MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f )
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();