summaryrefslogtreecommitdiffstats
path: root/demos/declarative/minehunt
diff options
context:
space:
mode:
Diffstat (limited to 'demos/declarative/minehunt')
-rw-r--r--demos/declarative/minehunt/Description.qml34
-rw-r--r--demos/declarative/minehunt/MinehuntCore/Explosion.qml (renamed from demos/declarative/minehunt/Explosion.qml)0
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg (renamed from demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg)bin30730 -> 30730 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/back.png (renamed from demos/declarative/minehunt/pics/back.png)bin558 -> 558 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png (renamed from demos/declarative/minehunt/pics/bomb-color.png)bin284 -> 284 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/bomb.png (renamed from demos/declarative/minehunt/pics/bomb.png)bin535 -> 535 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/face-sad.png (renamed from demos/declarative/minehunt/pics/face-sad.png)bin14844 -> 14844 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png (renamed from demos/declarative/minehunt/pics/face-smile-big.png)bin13810 -> 13810 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/face-smile.png (renamed from demos/declarative/minehunt/pics/face-smile.png)bin15408 -> 15408 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/flag-color.png (renamed from demos/declarative/minehunt/pics/flag-color.png)bin219 -> 219 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/flag.png (renamed from demos/declarative/minehunt/pics/flag.png)bin196 -> 196 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/front.png (renamed from demos/declarative/minehunt/pics/front.png)bin580 -> 580 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/pics/star.png (renamed from demos/declarative/minehunt/pics/star.png)bin2677 -> 2677 bytes
-rw-r--r--demos/declarative/minehunt/MinehuntCore/qmldir2
-rw-r--r--demos/declarative/minehunt/README3
-rw-r--r--demos/declarative/minehunt/minehunt.cpp (renamed from demos/declarative/minehunt/main.cpp)126
-rw-r--r--demos/declarative/minehunt/minehunt.pro16
-rw-r--r--demos/declarative/minehunt/minehunt.qml26
-rw-r--r--demos/declarative/minehunt/test.qml13
19 files changed, 67 insertions, 153 deletions
diff --git a/demos/declarative/minehunt/Description.qml b/demos/declarative/minehunt/Description.qml
deleted file mode 100644
index cc4d3b2..0000000
--- a/demos/declarative/minehunt/Description.qml
+++ /dev/null
@@ -1,34 +0,0 @@
-import Qt 4.6
-
-Item {
- id: page
- height: myText.height + 20
- property var text
- MouseArea {
- anchors.fill: parent
- drag.target: page
- drag.axis: "XandYAxis"
- drag.minimumX: 0
- drag.maximumX: 1000
- drag.minimumY: 0
- drag.maximumY: 1000
- }
- Rectangle {
- radius: 10
- anchors.fill: parent
- color: "lightsteelblue"
- }
- Item {
- x: 10
- y: 10
- width: parent.width - 20
- height: parent.height - 20
- Text {
- id: myText
- text: page.text
- width: parent.width
- clip: true
- wrap: true
- }
- }
-}
diff --git a/demos/declarative/minehunt/Explosion.qml b/demos/declarative/minehunt/MinehuntCore/Explosion.qml
index e337c46..e337c46 100644
--- a/demos/declarative/minehunt/Explosion.qml
+++ b/demos/declarative/minehunt/MinehuntCore/Explosion.qml
diff --git a/demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg b/demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg
index 445567f..445567f 100644
--- a/demos/declarative/minehunt/pics/No-Ones-Laughing-3.jpg
+++ b/demos/declarative/minehunt/MinehuntCore/pics/No-Ones-Laughing-3.jpg
Binary files differ
diff --git a/demos/declarative/minehunt/pics/back.png b/demos/declarative/minehunt/MinehuntCore/pics/back.png
index f6b3f0b..f6b3f0b 100644
--- a/demos/declarative/minehunt/pics/back.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/back.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/bomb-color.png b/demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png
index 61ad0a9..61ad0a9 100644
--- a/demos/declarative/minehunt/pics/bomb-color.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/bomb-color.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/bomb.png b/demos/declarative/minehunt/MinehuntCore/pics/bomb.png
index a992575..a992575 100644
--- a/demos/declarative/minehunt/pics/bomb.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/bomb.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/face-sad.png b/demos/declarative/minehunt/MinehuntCore/pics/face-sad.png
index cf00aaf..cf00aaf 100644
--- a/demos/declarative/minehunt/pics/face-sad.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/face-sad.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/face-smile-big.png b/demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png
index f9c2335..f9c2335 100644
--- a/demos/declarative/minehunt/pics/face-smile-big.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/face-smile-big.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/face-smile.png b/demos/declarative/minehunt/MinehuntCore/pics/face-smile.png
index 3d66d72..3d66d72 100644
--- a/demos/declarative/minehunt/pics/face-smile.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/face-smile.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/flag-color.png b/demos/declarative/minehunt/MinehuntCore/pics/flag-color.png
index aadad0f..aadad0f 100644
--- a/demos/declarative/minehunt/pics/flag-color.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/flag-color.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/flag.png b/demos/declarative/minehunt/MinehuntCore/pics/flag.png
index 39cde4d..39cde4d 100644
--- a/demos/declarative/minehunt/pics/flag.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/flag.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/front.png b/demos/declarative/minehunt/MinehuntCore/pics/front.png
index 834331b..834331b 100644
--- a/demos/declarative/minehunt/pics/front.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/front.png
Binary files differ
diff --git a/demos/declarative/minehunt/pics/star.png b/demos/declarative/minehunt/MinehuntCore/pics/star.png
index 3772359..3772359 100644
--- a/demos/declarative/minehunt/pics/star.png
+++ b/demos/declarative/minehunt/MinehuntCore/pics/star.png
Binary files differ
diff --git a/demos/declarative/minehunt/MinehuntCore/qmldir b/demos/declarative/minehunt/MinehuntCore/qmldir
new file mode 100644
index 0000000..862c396
--- /dev/null
+++ b/demos/declarative/minehunt/MinehuntCore/qmldir
@@ -0,0 +1,2 @@
+plugin minehunt
+Explosion 1.0 Explosion.qml
diff --git a/demos/declarative/minehunt/README b/demos/declarative/minehunt/README
new file mode 100644
index 0000000..7379dcf
--- /dev/null
+++ b/demos/declarative/minehunt/README
@@ -0,0 +1,3 @@
+To run, simply load the minehunt.qml file with the qml runtime.
+
+Note that on X11, this demo has problems with the native graphicssystem. If you are using the X11 window system, please pass -graphicssystem raster to the qml binary.
diff --git a/demos/declarative/minehunt/main.cpp b/demos/declarative/minehunt/minehunt.cpp
index e7a1d7c..89845ef 100644
--- a/demos/declarative/minehunt/main.cpp
+++ b/demos/declarative/minehunt/minehunt.cpp
@@ -38,21 +38,15 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "qdeclarativeengine.h"
-#include "qdeclarativecontext.h"
-#include "qdeclarative.h"
-#include <qdeclarativeitem.h>
-#include <qdeclarativeview.h>
-
-#include <QWidget>
-#include <QApplication>
-#include <QFile>
+
+#include <stdlib.h>
+#include <qdeclarativeextensionplugin.h>
+#include <qdeclarativecontext.h>
+#include <qdeclarativeengine.h>
+#include <qdeclarative.h>
+
#include <QTime>
#include <QTimer>
-#include <QVBoxLayout>
-#include <QFileInfo>
-
-QString fileName = "minehunt.qml";
class Tile : public QObject
{
@@ -91,17 +85,14 @@ private:
bool _flipped;
};
-QML_DECLARE_TYPE(Tile);
-
-class MyWidget : public QWidget
+class MinehuntGame : public QObject
{
-Q_OBJECT
+ Q_OBJECT
public:
- MyWidget(int = 370, int = 480, QWidget *parent=0, Qt::WindowFlags flags=0);
- ~MyWidget();
+ MinehuntGame();
Q_PROPERTY(QDeclarativeListProperty<Tile> tiles READ tiles CONSTANT);
- QDeclarativeListProperty<Tile> tiles() { return _tilesProperty; }
+ QDeclarativeListProperty<Tile> tiles() { return QDeclarativeListProperty<Tile>(this, _tiles); }
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged);
bool isPlaying() {return playing;}
@@ -133,10 +124,7 @@ private:
int getHint(int row, int col);
void setPlaying(bool b){if(b==playing) return; playing=b; emit isPlayingChanged();}
- QDeclarativeView *canvas;
-
QList<Tile *> _tiles;
- QDeclarativeListProperty<Tile> _tilesProperty;
int numCols;
int numRows;
bool playing;
@@ -146,11 +134,10 @@ 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)
+MinehuntGame::MinehuntGame()
+: numCols(9), numRows(9), playing(true), won(false)
{
- setObjectName("mainWidget");
+ setObjectName("mainObject");
srand(QTime(0,0,0).secsTo(QTime::currentTime()));
//initialize array
@@ -159,27 +146,9 @@ MyWidget::MyWidget(int width, int height, QWidget *parent, Qt::WindowFlags flags
}
reset();
- QVBoxLayout *vbox = new QVBoxLayout;
- vbox->setMargin(0);
- setLayout(vbox);
-
- canvas = new QDeclarativeView(this);
- canvas->setFixedSize(width, height);
- vbox->addWidget(canvas);
-
- _tilesProperty = QDeclarativeListProperty<Tile>(this, _tiles);
-
- QDeclarativeContext *ctxt = canvas->rootContext();
- ctxt->addDefaultObject(this);
-
- canvas->setSource(QUrl::fromLocalFile(fileName));
-}
-
-MyWidget::~MyWidget()
-{
}
-void MyWidget::setBoard()
+void MinehuntGame::setBoard()
{
foreach(Tile* t, _tiles){
t->setHasMine(false);
@@ -213,7 +182,7 @@ void MyWidget::setBoard()
setPlaying(true);
}
-void MyWidget::reset()
+void MinehuntGame::reset()
{
foreach(Tile* t, _tiles){
t->unflip();
@@ -225,7 +194,7 @@ void MyWidget::reset()
QTimer::singleShot(600,this, SLOT(setBoard()));
}
-int MyWidget::getHint(int row, int col)
+int MinehuntGame::getHint(int row, int col)
{
int hint = 0;
for (int c = col-1; c <= col+1; c++)
@@ -237,7 +206,7 @@ int MyWidget::getHint(int row, int col)
return hint;
}
-bool MyWidget::flip(int row, int col)
+bool MinehuntGame::flip(int row, int col)
{
if(!playing)
return false;
@@ -302,7 +271,7 @@ bool MyWidget::flip(int row, int col)
return true;
}
-bool MyWidget::flag(int row, int col)
+bool MinehuntGame::flag(int row, int col)
{
Tile *t = tile(row, col);
if(!t)
@@ -313,42 +282,33 @@ bool MyWidget::flag(int row, int col)
emit numFlagsChanged();
return true;
}
-/////////////////////////////////////////////////////////
-int main(int argc, char ** argv)
+QML_DECLARE_TYPE(Tile);
+QML_DECLARE_TYPE(MinehuntGame);
+
+class MinehuntExtensionPlugin : public QDeclarativeExtensionPlugin
{
-#ifdef Q_WS_X11
- // native on X11 is terrible for this demo.
- QApplication::setGraphicsSystem("raster");
-#endif
- QApplication app(argc, argv);
-
- bool frameless = false;
-
- int width = 370;
- int height = 480;
-
- QML_REGISTER_TYPE(0,0,0,Tile,Tile);
-
- for (int i = 1; i < argc; ++i) {
- QString arg = argv[i];
- if (arg == "-frameless") {
- frameless = true;
- } else if(arg == "-width" && i < (argc - 1)) {
- ++i;
- width = ::atoi(argv[i]);
- } else if(arg == "-height" && i < (argc - 1)) {
- ++i;
- height = ::atoi(argv[i]);
- } else if (arg[0] != '-') {
- fileName = arg;
- }
+ Q_OBJECT
+
+ public:
+ void registerTypes(const char *uri) {
+ Q_UNUSED(uri);
+ QML_REGISTER_TYPE(SameGameCore, 0, 1, Tile, Tile);
+ QML_REGISTER_TYPE(SameGameCore, 0, 1, Game, MinehuntGame);
}
- MyWidget wid(width, height, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget);
- wid.show();
+ void initializeEngine(QDeclarativeEngine *engine, const char *uri) {
+ Q_UNUSED(uri);
- return app.exec();
-}
+ srand(QTime(0,0,0).secsTo(QTime::currentTime()));
+
+ MinehuntGame* game = new MinehuntGame();
+
+ engine->rootContext()->addDefaultObject(game);
+ }
+};
+
+#include "minehunt.moc"
+
+Q_EXPORT_PLUGIN(MinehuntExtensionPlugin);
-#include "main.moc"
diff --git a/demos/declarative/minehunt/minehunt.pro b/demos/declarative/minehunt/minehunt.pro
index 01791b1..a497b0f 100644
--- a/demos/declarative/minehunt/minehunt.pro
+++ b/demos/declarative/minehunt/minehunt.pro
@@ -1,9 +1,11 @@
-SOURCES = main.cpp
+TEMPLATE = lib
+TARGET = minehunt
+QT += declarative
+CONFIG += qt plugin
-QT += script declarative
-contains(QT_CONFIG, opengles2)|contains(QT_CONFIG, opengles1): QT += opengl
+TARGET = $$qtLibraryTarget($$TARGET)
+DESTDIR = MinehuntCore
+
+# Input
+SOURCES += minehunt.cpp
-target.path = $$[QT_INSTALL_EXAMPLES]/declarative/minehunt
-sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS minehunt.pro
-sources.path = $$[QT_INSTALL_EXAMPLES]/declarative/minehunt
-INSTALLS += target sources
diff --git a/demos/declarative/minehunt/minehunt.qml b/demos/declarative/minehunt/minehunt.qml
index 8a3cab1..9e99706 100644
--- a/demos/declarative/minehunt/minehunt.qml
+++ b/demos/declarative/minehunt/minehunt.qml
@@ -1,4 +1,5 @@
import Qt 4.6
+import MinehuntCore 1.0
Item {
id: field
@@ -24,15 +25,15 @@ Item {
angle: flipable.angle;
}
front: Image {
- source: "pics/front.png"
+ source: "MinehuntCore/pics/front.png"
width: 40
height: 40
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
- source: "pics/flag.png"
+ source: "MinehuntCore/pics/flag.png"
opacity: modelData.hasFlag
- opacity: Behavior {
+ Behavior on opacity {
NumberAnimation {
property: "opacity"
duration: 250
@@ -41,7 +42,7 @@ Item {
}
}
back: Image {
- source: "pics/back.png"
+ source: "MinehuntCore/pics/back.png"
width: 40
height: 40
Text {
@@ -55,7 +56,7 @@ Item {
Image {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
- source: "pics/bomb.png"
+ source: "MinehuntCore/pics/bomb.png"
opacity: modelData.hasMine
}
Explosion {
@@ -120,16 +121,9 @@ Item {
}
]
Image {
- source: "pics/No-Ones-Laughing-3.jpg"
+ source: "MinehuntCore/pics/No-Ones-Laughing-3.jpg"
fillMode: Image.Tile
}
- Description {
- text: "Use the 'minehunt' executable to run this demo!"
- width: 300
- opacity: tiles?0:1
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.verticalCenter: parent.verticalCenter
- }
Repeater {
id: repeater
model: tiles
@@ -156,7 +150,7 @@ Item {
Image {
// x: 100
// y: 20
- source: "pics/bomb-color.png"
+ source: "MinehuntCore/pics/bomb-color.png"
}
Text {
// x: 100
@@ -172,7 +166,7 @@ Item {
Image {
// x: 140
// y: 20
- source: "pics/flag-color.png"
+ source: "MinehuntCore/pics/flag-color.png"
}
Text {
// x: 140
@@ -187,7 +181,7 @@ Item {
y: 390
anchors.right: field.right
anchors.rightMargin: 20
- source: isPlaying ? 'pics/face-smile.png' : hasWon ? 'pics/face-smile-big.png': 'pics/face-sad.png'
+ source: isPlaying ? 'MinehuntCore/pics/face-smile.png' : hasWon ? 'MinehuntCore/pics/face-smile-big.png': 'MinehuntCore/pics/face-sad.png'
MouseArea {
anchors.fill: parent
onPressed: { reset() }
diff --git a/demos/declarative/minehunt/test.qml b/demos/declarative/minehunt/test.qml
deleted file mode 100644
index 11ed182..0000000
--- a/demos/declarative/minehunt/test.qml
+++ /dev/null
@@ -1,13 +0,0 @@
-import Qt 4.6
-
- Image {
- source: "pics/front.png"
- width: 40
- height: 40
- Image {
- anchors.horizontalCenter: parent.horizontalCenter
- anchors.verticalCenter: parent.verticalCenter
- source: "pics/flag.png"
- opacity: 1
- }
- }