diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-03-01 11:23:15 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-03-01 11:23:15 (GMT) |
commit | 3a4dc08d08ce0388dd183a24923871e3e03ba531 (patch) | |
tree | d2a4746d190b4c07ce2c5fc78d28f8c72df170cf /demos/declarative | |
parent | 75d61cbd7d2c72abb1fcf486c97bbb7429aea81b (diff) | |
download | Qt-3a4dc08d08ce0388dd183a24923871e3e03ba531.zip Qt-3a4dc08d08ce0388dd183a24923871e3e03ba531.tar.gz Qt-3a4dc08d08ce0388dd183a24923871e3e03ba531.tar.bz2 |
Make Minehunt demo compile.
It still isn't working though. Investigations continue.
Task-number: QTBUG-8549
Diffstat (limited to 'demos/declarative')
-rw-r--r-- | demos/declarative/minehunt/main.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp index 0e99731..37dc8a5 100644 --- a/demos/declarative/minehunt/main.cpp +++ b/demos/declarative/minehunt/main.cpp @@ -100,8 +100,8 @@ public: MyWidget(int = 370, int = 480, QWidget *parent=0, Qt::WindowFlags flags=0); ~MyWidget(); - Q_PROPERTY(QList<Tile *> *tiles READ tiles CONSTANT); - QList<Tile *> *tiles() { return &_tiles; } + Q_PROPERTY(QDeclarativeListProperty<Tile> tiles READ tiles CONSTANT); + QDeclarativeListProperty<Tile> tiles() { return _tilesProperty; } Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged); bool isPlaying() {return playing;} @@ -116,8 +116,8 @@ public: int numFlags() const{return nFlags;} public slots: - Q_INVOKABLE void flip(int row, int col); - Q_INVOKABLE void flag(int row, int col); + Q_INVOKABLE bool flip(int row, int col); + Q_INVOKABLE bool flag(int row, int col); void setBoard(); void reset(); @@ -136,6 +136,7 @@ private: QDeclarativeView *canvas; QList<Tile *> _tiles; + QDeclarativeListProperty<Tile> _tilesProperty; int numCols; int numRows; bool playing; @@ -145,6 +146,7 @@ private: int nFlags; }; +Q_DECLARE_METATYPE(QList<Tile*>) MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags) : QWidget(parent, flags), canvas(0), numCols(9), numRows(9), playing(true), won(false) { @@ -155,7 +157,6 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags for(int ii = 0; ii < numRows * numCols; ++ii) { _tiles << new Tile; } - reset(); QVBoxLayout *vbox = new QVBoxLayout; @@ -166,9 +167,10 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags canvas->setFixedSize(width, height); vbox->addWidget(canvas); + _tilesProperty = QDeclarativeListProperty<Tile>(this, _tiles); + QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->addDefaultObject(this); - ctxt->setContextProperty("tiles", QVariant::fromValue<QList<Tile*>*>(&_tiles));//QTBUG-5675 canvas->setSource(QUrl::fromLocalFile(fileName)); } @@ -235,14 +237,14 @@ int MyWidget::getHint(int row, int col) return hint; } -void MyWidget::flip(int row, int col) +bool MyWidget::flip(int row, int col) { if(!playing) - return; + return false; Tile *t = tile(row, col); if (!t || t->hasFlag()) - return; + return false; if(t->flipped()){ int flags = 0; @@ -255,7 +257,7 @@ void MyWidget::flip(int row, int col) flags++; } if(!t->hint() || t->hint() != flags) - return; + return false; for (int c = col-1; c <= col+1; c++) for (int r = row-1; r <= row+1; r++) { Tile *nearT = tile(r, c); @@ -263,7 +265,7 @@ void MyWidget::flip(int row, int col) flip( r, c ); } } - return; + return true; } t->flip(); @@ -297,17 +299,19 @@ void MyWidget::flip(int row, int col) hasWonChanged(); setPlaying(false); } + return true; } -void MyWidget::flag(int row, int col) +bool MyWidget::flag(int row, int col) { Tile *t = tile(row, col); if(!t) - return; + return false; t->setHasFlag(!t->hasFlag()); nFlags += (t->hasFlag()?1:-1); emit numFlagsChanged(); + return true; } ///////////////////////////////////////////////////////// |