summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
Diffstat (limited to 'demos')
-rw-r--r--demos/declarative/minehunt/main.cpp34
-rw-r--r--demos/declarative/minehunt/minehunt.qml14
-rw-r--r--demos/interview/model.cpp2
-rw-r--r--demos/interview/model.h2
-rw-r--r--demos/multimedia/player/player.cpp28
-rw-r--r--demos/multimedia/player/player.h3
-rw-r--r--demos/qtdemo/qtdemo.pro2
7 files changed, 61 insertions, 24 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/demos/interview/model.cpp b/demos/interview/model.cpp
index 3f9548a..840bc60 100644
--- a/demos/interview/model.cpp
+++ b/demos/interview/model.cpp
@@ -45,6 +45,7 @@
Model::Model(int rows, int columns, QObject *parent)
: QAbstractItemModel(parent),
+ services(QPixmap(":/images/services.png")),
rc(rows), cc(columns),
tree(new QVector<Node>(rows, Node(0)))
{
@@ -105,7 +106,6 @@ QVariant Model::data(const QModelIndex &index, int role) const
QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
{
- static QIcon services(QPixmap(":/images/services.png"));
if (role == Qt::DisplayRole)
return QString::number(section);
if (role == Qt::DecorationRole)
diff --git a/demos/interview/model.h b/demos/interview/model.h
index bad83a8..c7c15f7 100644
--- a/demos/interview/model.h
+++ b/demos/interview/model.h
@@ -44,6 +44,7 @@
#include <QAbstractItemModel>
#include <QFileIconProvider>
+#include <QIcon>
#include <QVector>
class Model : public QAbstractItemModel
@@ -80,6 +81,7 @@ private:
Node *parent(Node *child) const;
int row(Node *node) const;
+ QIcon services;
int rc, cc;
QVector<Node> *tree;
QFileIconProvider iconProvider;
diff --git a/demos/multimedia/player/player.cpp b/demos/multimedia/player/player.cpp
index 49d18cb..af30a97 100644
--- a/demos/multimedia/player/player.cpp
+++ b/demos/multimedia/player/player.cpp
@@ -81,6 +81,22 @@ Player::Player(QWidget *parent)
connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex)));
+ playbackModeBox = new QComboBox;
+ playbackModeBox->addItem(tr("Linear"),
+ QVariant::fromValue<QMediaPlaylist::PlaybackMode>(QMediaPlaylist::Linear));
+ playbackModeBox->addItem(tr("Loop"),
+ QVariant::fromValue<QMediaPlaylist::PlaybackMode>(QMediaPlaylist::Loop));
+ playbackModeBox->addItem(tr("Random"),
+ QVariant::fromValue<QMediaPlaylist::PlaybackMode>(QMediaPlaylist::Random));
+ playbackModeBox->addItem(tr("Current Item Once"),
+ QVariant::fromValue<QMediaPlaylist::PlaybackMode>(QMediaPlaylist::CurrentItemOnce));
+ playbackModeBox->addItem(tr("Current Item In Loop"),
+ QVariant::fromValue<QMediaPlaylist::PlaybackMode>(QMediaPlaylist::CurrentItemInLoop));
+ playbackModeBox->setCurrentIndex(0);
+
+ connect(playbackModeBox, SIGNAL(activated(int)), SLOT(updatePlaybackMode()));
+ updatePlaybackMode();
+
slider = new QSlider(Qt::Horizontal);
slider->setRange(0, player->duration() / 1000);
@@ -126,12 +142,16 @@ Player::Player(QWidget *parent)
else
colorButton->setEnabled(false);
+ QBoxLayout *playlistLayout = new QVBoxLayout;
+ playlistLayout->addWidget(playlistView);
+ playlistLayout->addWidget(playbackModeBox);
+
QBoxLayout *displayLayout = new QHBoxLayout;
if (videoWidget)
displayLayout->addWidget(videoWidget, 2);
else
displayLayout->addWidget(coverLabel, 2);
- displayLayout->addWidget(playlistView);
+ displayLayout->addLayout(playlistLayout);
QBoxLayout *controlLayout = new QHBoxLayout;
controlLayout->setMargin(0);
@@ -333,3 +353,9 @@ void Player::showColorDialog()
}
colorDialog->show();
}
+
+void Player::updatePlaybackMode()
+{
+ playlist->setPlaybackMode(
+ playbackModeBox->itemData(playbackModeBox->currentIndex()).value<QMediaPlaylist::PlaybackMode>());
+}
diff --git a/demos/multimedia/player/player.h b/demos/multimedia/player/player.h
index 1de8b1a..cda3eb9 100644
--- a/demos/multimedia/player/player.h
+++ b/demos/multimedia/player/player.h
@@ -57,6 +57,7 @@ class QAbstractItemView;
class QLabel;
class QModelIndex;
class QSlider;
+class QComboBox;
class QMediaPlayer;
class QVideoWidget;
class PlaylistModel;
@@ -87,6 +88,7 @@ private slots:
void bufferingProgress(int progress);
void showColorDialog();
+ void updatePlaybackMode();
private:
void setTrackInfo(const QString &info);
@@ -97,6 +99,7 @@ private:
QVideoWidget *videoWidget;
QLabel *coverLabel;
QSlider *slider;
+ QComboBox *playbackModeBox;
PlaylistModel *playlistModel;
QAbstractItemView *playlistView;
QDialog *colorDialog;
diff --git a/demos/qtdemo/qtdemo.pro b/demos/qtdemo/qtdemo.pro
index 011ea0c..2a776ac 100644
--- a/demos/qtdemo/qtdemo.pro
+++ b/demos/qtdemo/qtdemo.pro
@@ -3,8 +3,6 @@ TARGET = qtdemo
DEMO_DESTDIR = $$QT_BUILD_TREE
isEmpty(DEMO_DESTDIR):DEMO_DESTDIR=../..
DESTDIR = $$DEMO_DESTDIR/bin
-OBJECTS_DIR = .obj
-MOC_DIR = .moc
INSTALLS += target sources