summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/declarative/minehunt/main.cpp34
-rw-r--r--demos/declarative/minehunt/minehunt.qml14
-rw-r--r--doc/src/declarative/advtutorial.qdoc5
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/Block.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/pics/background.pngbin313930 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/pics/redStone.pngbin2902 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame1/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/Block.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/pics/background.pngbin313930 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/pics/redStone.pngbin2902 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame2/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/Block.qml6
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/pics/background.pngbin313930 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/pics/blueStone.pngbin3054 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/pics/greenStone.pngbin2932 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/pics/redStone.pngbin2902 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame3/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml12
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/content/pics/background.pngbin313930 -> 0 bytes
-rw-r--r--examples/declarative/tutorials/samegame/samegame4/samegame.qml2
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/background.jpgbin0 -> 36473 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/blueStar.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/blueStar.png)bin278 -> 278 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/blueStone.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/blueStone.png)bin3054 -> 3054 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/greenStar.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/greenStar.png)bin273 -> 273 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/greenStone.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/greenStone.png)bin2932 -> 2932 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/redStar.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/redStar.png)bin274 -> 274 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/redStone.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/redStone.png)bin2902 -> 2902 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/star.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/star.png)bin262 -> 262 bytes
-rw-r--r--examples/declarative/tutorials/samegame/shared/pics/yellowStone.png (renamed from examples/declarative/tutorials/samegame/samegame4/content/pics/yellowStone.png)bin3056 -> 3056 bytes
29 files changed, 48 insertions, 35 deletions
diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/main.cpp
index 0e99731..e7a1d7c 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,22 +299,28 @@ 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;
}
/////////////////////////////////////////////////////////
int main(int argc, char ** argv)
{
+#ifdef Q_WS_X11
+ // native on X11 is terrible for this demo.
+ QApplication::setGraphicsSystem("raster");
+#endif
QApplication app(argc, argv);
bool frameless = false;
diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml
index 617a6ed..8a3cab1 100644
--- a/demos/declarative/minehunt/minehunt.qml
+++ b/demos/declarative/minehunt/minehunt.qml
@@ -31,7 +31,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "pics/flag.png"
- opacity: model.hasFlag
+ opacity: modelData.hasFlag
opacity: Behavior {
NumberAnimation {
property: "opacity"
@@ -47,16 +47,16 @@ Item {
Text {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
- text: model.hint
+ text: modelData.hint
color: "white"
font.bold: true
- opacity: !model.hasMine && model.hint > 0
+ opacity: !modelData.hasMine && modelData.hint > 0
}
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
source: "pics/bomb.png"
- opacity: model.hasMine
+ opacity: modelData.hasMine
}
Explosion {
id: expl
@@ -65,7 +65,7 @@ Item {
states: [
State {
name: "back"
- when: model.flipped
+ when: modelData.flipped
PropertyChanges { target: flipable; angle: 180 }
}
]
@@ -81,7 +81,7 @@ Item {
else
ret = 0;
if (ret > 0) {
- if (model.hasMine && model.flipped) {
+ if (modelData.hasMine && modelData.flipped) {
ret*3;
} else {
ret;
@@ -96,7 +96,7 @@ Item {
properties: "angle"
}
ScriptAction{
- script: if(model.hasMine && model.flipped){expl.explode = true;}
+ script: if(modelData.hasMine && modelData.flipped){expl.explode = true;}
}
}
}
diff --git a/doc/src/declarative/advtutorial.qdoc b/doc/src/declarative/advtutorial.qdoc
index b7d964c..e420e6d 100644
--- a/doc/src/declarative/advtutorial.qdoc
+++ b/doc/src/declarative/advtutorial.qdoc
@@ -106,6 +106,11 @@ more than just an image. Note that we've set the image to be the size of the ite
This will be used later, when we dynamically create and size the block items the image will be scaled automatically
to the correct size.
+Note that because there are several stages to this tutorial they share images. This is done by having a shared resources
+folder containing the images, and all stages of the tutorial refer to the same shared folder. This is the reason for the
+'../shared/pics' part of the image source. The image source can be any relative or absolute path, and it is relative to the
+location of the file the Image element is in, with ../ meaning to go up one level.
+
You should be familiar with all that goes on in these files so far. This is a
very basic start and doesn't move at all - next we will populate the game canvas
with some blocks.
diff --git a/examples/declarative/tutorials/samegame/samegame1/Block.qml b/examples/declarative/tutorials/samegame/samegame1/Block.qml
index b76e61a..f133b17 100644
--- a/examples/declarative/tutorials/samegame/samegame1/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/Block.qml
@@ -5,7 +5,7 @@ Item {
id:block
Image { id: img
- source: "pics/redStone.png";
+ source: "../shared/pics/redStone.png";
anchors.fill: parent
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame1/pics/background.png b/examples/declarative/tutorials/samegame/samegame1/pics/background.png
deleted file mode 100644
index 3734a27..0000000
--- a/examples/declarative/tutorials/samegame/samegame1/pics/background.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame1/pics/redStone.png b/examples/declarative/tutorials/samegame/samegame1/pics/redStone.png
deleted file mode 100644
index 36b09a2..0000000
--- a/examples/declarative/tutorials/samegame/samegame1/pics/redStone.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame1/samegame.qml b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
index c2d3939..5ed30c9 100644
--- a/examples/declarative/tutorials/samegame/samegame1/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame1/samegame.qml
@@ -12,7 +12,7 @@ Rectangle {
Image {
id: background
- anchors.fill: parent; source: "pics/background.png"
+ anchors.fill: parent; source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/Block.qml b/examples/declarative/tutorials/samegame/samegame2/Block.qml
index 228ac4e..e4b3354 100644
--- a/examples/declarative/tutorials/samegame/samegame2/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/Block.qml
@@ -4,7 +4,7 @@ Item {
id:block
Image { id: img
- source: "pics/redStone.png";
+ source: "../shared/pics/redStone.png";
anchors.fill: parent
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame2/pics/background.png b/examples/declarative/tutorials/samegame/samegame2/pics/background.png
deleted file mode 100644
index 3734a27..0000000
--- a/examples/declarative/tutorials/samegame/samegame2/pics/background.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png b/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png
deleted file mode 100644
index 36b09a2..0000000
--- a/examples/declarative/tutorials/samegame/samegame2/pics/redStone.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame2/samegame.qml b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
index 8d837da..7e0bc0c 100644
--- a/examples/declarative/tutorials/samegame/samegame2/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame2/samegame.qml
@@ -14,7 +14,7 @@ Rectangle {
Image {
id: background
- anchors.fill: parent; source: "pics/background.png"
+ anchors.fill: parent; source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame3/Block.qml b/examples/declarative/tutorials/samegame/samegame3/Block.qml
index 30a8d3a..7620104 100644
--- a/examples/declarative/tutorials/samegame/samegame3/Block.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/Block.qml
@@ -8,11 +8,11 @@ Item {
Image { id: img
source: {
if(type == 0){
- "pics/redStone.png";
+ "../shared/pics/redStone.png";
} else if(type == 1) {
- "pics/blueStone.png";
+ "../shared/pics/blueStone.png";
} else {
- "pics/greenStone.png";
+ "../shared/pics/greenStone.png";
}
}
anchors.fill: parent
diff --git a/examples/declarative/tutorials/samegame/samegame3/pics/background.png b/examples/declarative/tutorials/samegame/samegame3/pics/background.png
deleted file mode 100644
index 3734a27..0000000
--- a/examples/declarative/tutorials/samegame/samegame3/pics/background.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame3/pics/blueStone.png b/examples/declarative/tutorials/samegame/samegame3/pics/blueStone.png
deleted file mode 100644
index 20e43c7..0000000
--- a/examples/declarative/tutorials/samegame/samegame3/pics/blueStone.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame3/pics/greenStone.png b/examples/declarative/tutorials/samegame/samegame3/pics/greenStone.png
deleted file mode 100644
index b568a19..0000000
--- a/examples/declarative/tutorials/samegame/samegame3/pics/greenStone.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame3/pics/redStone.png b/examples/declarative/tutorials/samegame/samegame3/pics/redStone.png
deleted file mode 100644
index 36b09a2..0000000
--- a/examples/declarative/tutorials/samegame/samegame3/pics/redStone.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
index c616397..168bf9b 100644
--- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml
@@ -13,7 +13,7 @@ Rectangle {
Image {
id: background
- anchors.fill: parent; source: "pics/background.png"
+ anchors.fill: parent; source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
index 4c2ba43..85c2c93 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml
@@ -16,11 +16,11 @@ Item { id:block
Image { id: img
source: {
if(type == 0){
- "pics/redStone.png";
+ "../../shared/pics/redStone.png";
} else if(type == 1) {
- "pics/blueStone.png";
+ "../../shared/pics/blueStone.png";
} else {
- "pics/greenStone.png";
+ "../../shared/pics/greenStone.png";
}
}
opacity: 0
@@ -38,11 +38,11 @@ Item { id:block
velocity: 100; velocityDeviation:30;
source: {
if(type == 0){
- "pics/redStar.png";
+ "../../shared/pics/redStar.png";
} else if (type == 1) {
- "pics/blueStar.png";
+ "../../shared/pics/blueStar.png";
} else {
- "pics/greenStar.png";
+ "../../shared/pics/greenStar.png";
}
}
}
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/background.png b/examples/declarative/tutorials/samegame/samegame4/content/pics/background.png
deleted file mode 100644
index 3734a27..0000000
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/background.png
+++ /dev/null
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
index a228e60..c2e8018 100644
--- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml
+++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml
@@ -12,7 +12,7 @@ Rectangle {
Image {
id: background
- anchors.fill: parent; source: "content/pics/background.png"
+ anchors.fill: parent; source: "../shared/pics/background.jpg"
fillMode: Image.PreserveAspectCrop
}
diff --git a/examples/declarative/tutorials/samegame/shared/pics/background.jpg b/examples/declarative/tutorials/samegame/shared/pics/background.jpg
new file mode 100644
index 0000000..903d395
--- /dev/null
+++ b/examples/declarative/tutorials/samegame/shared/pics/background.jpg
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/blueStar.png b/examples/declarative/tutorials/samegame/shared/pics/blueStar.png
index ff9588f..ff9588f 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/blueStar.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/blueStar.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/blueStone.png b/examples/declarative/tutorials/samegame/shared/pics/blueStone.png
index 20e43c7..20e43c7 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/blueStone.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/blueStone.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/greenStar.png b/examples/declarative/tutorials/samegame/shared/pics/greenStar.png
index cd06854..cd06854 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/greenStar.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/greenStar.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/greenStone.png b/examples/declarative/tutorials/samegame/shared/pics/greenStone.png
index b568a19..b568a19 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/greenStone.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/greenStone.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/redStar.png b/examples/declarative/tutorials/samegame/shared/pics/redStar.png
index 0a4dffe..0a4dffe 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/redStar.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/redStar.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/redStone.png b/examples/declarative/tutorials/samegame/shared/pics/redStone.png
index 36b09a2..36b09a2 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/redStone.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/redStone.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/star.png b/examples/declarative/tutorials/samegame/shared/pics/star.png
index defbde5..defbde5 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/star.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/star.png
Binary files differ
diff --git a/examples/declarative/tutorials/samegame/samegame4/content/pics/yellowStone.png b/examples/declarative/tutorials/samegame/shared/pics/yellowStone.png
index b1ce762..b1ce762 100644
--- a/examples/declarative/tutorials/samegame/samegame4/content/pics/yellowStone.png
+++ b/examples/declarative/tutorials/samegame/shared/pics/yellowStone.png
Binary files differ