summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-03 14:36:15 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-09-03 14:36:15 (GMT)
commitf0844f9da7a834c282f6f04b2676f28de444e9dc (patch)
tree8e121429e25959043cc04c4364adbe8239e44a67 /examples
parentfe763ef6cd255ccb54d0de1894c1a772f959585e (diff)
parentf360180890298618ef3284c08789c2a243e1ba9d (diff)
downloadQt-f0844f9da7a834c282f6f04b2676f28de444e9dc.zip
Qt-f0844f9da7a834c282f6f04b2676f28de444e9dc.tar.gz
Qt-f0844f9da7a834c282f6f04b2676f28de444e9dc.tar.bz2
Merge commit 'qt/4.6' into kinetic-declarativeui
Diffstat (limited to 'examples')
-rw-r--r--examples/animation/stickman/lifecycle.cpp4
-rw-r--r--examples/animation/stickman/main.cpp43
-rw-r--r--examples/animation/stickman/node.cpp5
-rw-r--r--examples/animation/stickman/node.h3
-rw-r--r--examples/animation/stickman/stickman.cpp5
-rw-r--r--examples/animation/stickman/stickman.h15
-rw-r--r--examples/animation/stickman/stickman.pro2
-rw-r--r--examples/animation/stickman/stickman.qrc8
-rw-r--r--examples/gestures/imageviewer/imageviewer.pro12
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp6
-rw-r--r--examples/itemviews/addressbook/addresswidget.cpp2
-rw-r--r--examples/multimedia/audio/audiodevices/audiodevices.pro5
-rw-r--r--examples/multimedia/audio/audioinput/audioinput.pro4
-rw-r--r--examples/multimedia/audio/audiooutput/audiooutput.pro5
-rw-r--r--examples/multitouch/pinchzoom/mouse.h5
-rw-r--r--examples/network/fortuneclient/client.cpp15
-rw-r--r--examples/network/fortuneserver/server.cpp19
-rw-r--r--examples/script/context2d/context2d.cpp4
-rw-r--r--examples/script/context2d/main.cpp3
-rw-r--r--examples/uitools/multipleinheritance/multipleinheritance.pro5
-rw-r--r--examples/video/videographicsitem/videographicsitem.pro5
-rw-r--r--examples/video/videowidget/videowidget.pro5
-rw-r--r--examples/xml/saxbookmarks/mainwindow.cpp5
23 files changed, 121 insertions, 64 deletions
diff --git a/examples/animation/stickman/lifecycle.cpp b/examples/animation/stickman/lifecycle.cpp
index 0fff529..463a27d 100644
--- a/examples/animation/stickman/lifecycle.cpp
+++ b/examples/animation/stickman/lifecycle.cpp
@@ -100,7 +100,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
m_animationGroup = new QParallelAnimationGroup();
const int stickManNodeCount = m_stickMan->nodeCount();
for (int i=0; i<stickManNodeCount; ++i) {
- QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "position");
+ QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "pos");
m_animationGroup->addAnimation(pa);
}
@@ -186,7 +186,7 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
QState *frameState = new QState(topLevel);
const int nodeCount = animation.nodeCount();
for (int j=0; j<nodeCount; ++j)
- frameState->assignProperty(m_stickMan->node(j), "position", animation.nodePos(j));
+ frameState->assignProperty(m_stickMan->node(j), "pos", animation.nodePos(j));
//! [1]
frameState->setObjectName(QString::fromLatin1("frame %0").arg(i));
diff --git a/examples/animation/stickman/main.cpp b/examples/animation/stickman/main.cpp
index 2b9e63c..f363d5d 100644
--- a/examples/animation/stickman/main.cpp
+++ b/examples/animation/stickman/main.cpp
@@ -50,6 +50,7 @@
int main(int argc, char **argv)
{
+ Q_INIT_RESOURCE(stickman);
QApplication app(argc, argv);
StickMan *stickMan = new StickMan;
@@ -72,26 +73,30 @@ int main(int argc, char **argv)
QRectF stickManBoundingRect = stickMan->mapToScene(stickMan->boundingRect()).boundingRect();
textItem->setPos(-w / 2.0, stickManBoundingRect.bottom() + 25.0);
- QGraphicsScene *scene = new QGraphicsScene();
- scene->addItem(stickMan);
- scene->addItem(textItem);
- scene->setBackgroundBrush(Qt::black);
+ QGraphicsScene scene;
+ scene.addItem(stickMan);
+ scene.addItem(textItem);
+ scene.setBackgroundBrush(Qt::black);
- GraphicsView *view = new GraphicsView();
- view->setRenderHints(QPainter::Antialiasing);
- view->setTransformationAnchor(QGraphicsView::NoAnchor);
- view->setScene(scene);
- view->showFullScreen();
- view->setFocus();
- view->setSceneRect(scene->sceneRect());
-
- LifeCycle *cycle = new LifeCycle(stickMan, view);
- cycle->setDeathAnimation("animations/dead");
-
- cycle->addActivity("animations/jumping", Qt::Key_J);
- cycle->addActivity("animations/dancing", Qt::Key_D);
- cycle->addActivity("animations/chilling", Qt::Key_C);
- cycle->start();
+ GraphicsView view;
+ view.setRenderHints(QPainter::Antialiasing);
+ view.setTransformationAnchor(QGraphicsView::NoAnchor);
+ view.setScene(&scene);
+ view.show();
+ view.setFocus();
+
+ QRectF sceneRect = scene.sceneRect();
+ // making enough room in the scene for stickman to jump and die
+ view.resize(sceneRect.width() + 100, sceneRect.height() + 100);
+ view.setSceneRect(sceneRect);
+
+ LifeCycle cycle(stickMan, &view);
+ cycle.setDeathAnimation(":/animations/dead");
+
+ cycle.addActivity(":/animations/jumping", Qt::Key_J);
+ cycle.addActivity(":/animations/dancing", Qt::Key_D);
+ cycle.addActivity(":/animations/chilling", Qt::Key_C);
+ cycle.start();
return app.exec();
}
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp
index 51224bb..1a138b2 100644
--- a/examples/animation/stickman/node.cpp
+++ b/examples/animation/stickman/node.cpp
@@ -47,9 +47,10 @@
#include <QGraphicsSceneMouseEvent>
Node::Node(const QPointF &pos, QGraphicsItem *parent)
- : QGraphicsItem(parent), m_dragging(false)
+ : QGraphicsObject(parent), m_dragging(false)
{
setPos(pos);
+ setFlag(QGraphicsItem::ItemSendsGeometryChanges);
}
Node::~Node()
@@ -72,7 +73,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
if (change == QGraphicsItem::ItemPositionChange)
emit positionChanged();
- return QGraphicsItem::itemChange(change, value);
+ return QGraphicsObject::itemChange(change, value);
}
void Node::mousePressEvent(QGraphicsSceneMouseEvent *)
diff --git a/examples/animation/stickman/node.h b/examples/animation/stickman/node.h
index 66ee565..4360d2e 100644
--- a/examples/animation/stickman/node.h
+++ b/examples/animation/stickman/node.h
@@ -44,10 +44,9 @@
#include <QGraphicsItem>
-class Node: public QObject, public QGraphicsItem
+class Node: public QGraphicsObject
{
Q_OBJECT
- Q_PROPERTY(QPointF position READ pos WRITE setPos)
public:
Node(const QPointF &pos, QGraphicsItem *parent = 0);
~Node();
diff --git a/examples/animation/stickman/stickman.cpp b/examples/animation/stickman/stickman.cpp
index 78e9e5b..67e022b 100644
--- a/examples/animation/stickman/stickman.cpp
+++ b/examples/animation/stickman/stickman.cpp
@@ -52,7 +52,6 @@
#define M_PI 3.14159265358979323846
#endif
-static const int NodeCount = 16;
static const qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
@@ -79,7 +78,6 @@ static const qreal Coords[NodeCount * 2] = {
};
-static const int BoneCount = 24;
static const int Bones[BoneCount * 2] = {
0, 1, // neck
@@ -116,7 +114,6 @@ static const int Bones[BoneCount * 2] = {
StickMan::StickMan()
{
- m_nodes = new Node*[NodeCount];
m_sticks = true;
m_isDead = false;
m_pixmap = QPixmap("images/head.png");
@@ -129,7 +126,6 @@ StickMan::StickMan()
connect(m_nodes[i], SIGNAL(positionChanged()), this, SLOT(childPositionChanged()));
}
- m_perfectBoneLengths = new qreal[BoneCount];
for (int i=0; i<BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -146,7 +142,6 @@ StickMan::StickMan()
StickMan::~StickMan()
{
- delete m_nodes;
}
void StickMan::childPositionChanged()
diff --git a/examples/animation/stickman/stickman.h b/examples/animation/stickman/stickman.h
index e8eedfa..d663c04 100644
--- a/examples/animation/stickman/stickman.h
+++ b/examples/animation/stickman/stickman.h
@@ -42,15 +42,15 @@
#ifndef STICKMAN_H
#define STICKMAN_H
-#include <QGraphicsItem>
+#include <QGraphicsObject>
-const int LimbCount = 16;
+static const int NodeCount = 16;
+static const int BoneCount = 24;
class Node;
QT_BEGIN_NAMESPACE
-class QTimer;
QT_END_NAMESPACE
-class StickMan: public QObject, public QGraphicsItem
+class StickMan: public QGraphicsObject
{
Q_OBJECT
Q_PROPERTY(QColor penColor WRITE setPenColor READ penColor)
@@ -77,7 +77,7 @@ public:
bool isDead() const { return m_isDead; }
void setIsDead(bool isDead) { m_isDead = isDead; }
-
+
public slots:
void stabilize();
void childPositionChanged();
@@ -86,10 +86,11 @@ protected:
void timerEvent(QTimerEvent *e);
private:
+
QPointF posFor(int idx) const;
- Node **m_nodes;
- qreal *m_perfectBoneLengths;
+ Node *m_nodes[NodeCount];
+ qreal m_perfectBoneLengths[BoneCount];
uint m_sticks : 1;
uint m_isDead : 1;
diff --git a/examples/animation/stickman/stickman.pro b/examples/animation/stickman/stickman.pro
index 7f8be33..487ff3a 100644
--- a/examples/animation/stickman/stickman.pro
+++ b/examples/animation/stickman/stickman.pro
@@ -10,7 +10,7 @@ SOURCES += main.cpp \
lifecycle.cpp \
graphicsview.cpp
-INCLUDEPATH += $$PWD
+RESOURCES += stickman.qrc
# install
target.path = $$[QT_INSTALL_EXAMPLES]/animation/stickman
diff --git a/examples/animation/stickman/stickman.qrc b/examples/animation/stickman/stickman.qrc
new file mode 100644
index 0000000..e5d66cf
--- /dev/null
+++ b/examples/animation/stickman/stickman.qrc
@@ -0,0 +1,8 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>animations/chilling</file>
+ <file>animations/dancing</file>
+ <file>animations/dead</file>
+ <file>animations/jumping</file>
+</qresource>
+</RCC> \ No newline at end of file
diff --git a/examples/gestures/imageviewer/imageviewer.pro b/examples/gestures/imageviewer/imageviewer.pro
index efbca00..124175e 100644
--- a/examples/gestures/imageviewer/imageviewer.pro
+++ b/examples/gestures/imageviewer/imageviewer.pro
@@ -1,11 +1,11 @@
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += .
-
-# Input
HEADERS += imagewidget.h \
tapandholdgesture.h
SOURCES += imagewidget.cpp \
tapandholdgesture.cpp \
main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/gestures/imageviewer
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS imageviewer.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/gestures/imageviewer
+INSTALLS += target sources
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index 7dbd084..c71c461 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -123,8 +123,10 @@ void ImageWidget::panTriggered()
void ImageWidget::pinchTriggered()
{
QPinchGesture *pg = qobject_cast<QPinchGesture*>(sender());
- rotationAngle += pg->rotationAngle();
- scaleFactor += pg->scaleFactor();
+ if (pg->whatChanged() & QPinchGesture::RotationAngleChanged)
+ rotationAngle += pg->rotationAngle() - pg->lastRotationAngle();
+ if (pg->whatChanged() & QPinchGesture::ScaleFactorChanged)
+ scaleFactor += pg->scaleFactor() - pg->lastScaleFactor();
update();
}
diff --git a/examples/itemviews/addressbook/addresswidget.cpp b/examples/itemviews/addressbook/addresswidget.cpp
index 6d05c22..c8dcb57 100644
--- a/examples/itemviews/addressbook/addresswidget.cpp
+++ b/examples/itemviews/addressbook/addresswidget.cpp
@@ -104,7 +104,7 @@ void AddressWidget::editEntry()
QModelIndex index, i;
QString name;
QString address;
- int row;
+ int row = -1;
foreach (index, indexes) {
row = proxy->mapToSource(index).row();
diff --git a/examples/multimedia/audio/audiodevices/audiodevices.pro b/examples/multimedia/audio/audiodevices/audiodevices.pro
index adc4890..2c078ba 100644
--- a/examples/multimedia/audio/audiodevices/audiodevices.pro
+++ b/examples/multimedia/audio/audiodevices/audiodevices.pro
@@ -10,3 +10,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices
sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiodevices.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiodevices
INSTALLS += target sources
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7BE
+}
diff --git a/examples/multimedia/audio/audioinput/audioinput.pro b/examples/multimedia/audio/audioinput/audioinput.pro
index d930750..139240e 100644
--- a/examples/multimedia/audio/audioinput/audioinput.pro
+++ b/examples/multimedia/audio/audioinput/audioinput.pro
@@ -10,3 +10,7 @@ sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audioinput.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audioinput
INSTALLS += target sources
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7BF
+}
diff --git a/examples/multimedia/audio/audiooutput/audiooutput.pro b/examples/multimedia/audio/audiooutput/audiooutput.pro
index 08f43ce..e2069cf 100644
--- a/examples/multimedia/audio/audiooutput/audiooutput.pro
+++ b/examples/multimedia/audio/audiooutput/audiooutput.pro
@@ -9,3 +9,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput
sources.files = $$SOURCES *.h $$RESOURCES $$FORMS audiooutput.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/multimedia/audio/audiooutput
INSTALLS += target sources
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7C0
+}
diff --git a/examples/multitouch/pinchzoom/mouse.h b/examples/multitouch/pinchzoom/mouse.h
index bd47245..e4ecb75 100644
--- a/examples/multitouch/pinchzoom/mouse.h
+++ b/examples/multitouch/pinchzoom/mouse.h
@@ -42,11 +42,10 @@
#ifndef MOUSE_H
#define MOUSE_H
-#include <QGraphicsItem>
-#include <QObject>
+#include <QGraphicsObject>
//! [0]
-class Mouse : public QObject, public QGraphicsItem
+class Mouse : public QGraphicsObject
{
Q_OBJECT
diff --git a/examples/network/fortuneclient/client.cpp b/examples/network/fortuneclient/client.cpp
index b850a57..7b2991a 100644
--- a/examples/network/fortuneclient/client.cpp
+++ b/examples/network/fortuneclient/client.cpp
@@ -56,7 +56,20 @@ Client::Client(QWidget *parent)
hostLabel = new QLabel(tr("&Server name:"));
portLabel = new QLabel(tr("S&erver port:"));
- hostLineEdit = new QLineEdit("Localhost");
+ // find out which IP to connect to
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address())
+ ipAddress = ipAddressesList.at(i).toString();
+ }
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+
+ hostLineEdit = new QLineEdit(ipAddress);
portLineEdit = new QLineEdit;
portLineEdit->setValidator(new QIntValidator(1, 65535, this));
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 7564199..476ff283 100644
--- a/examples/network/fortuneserver/server.cpp
+++ b/examples/network/fortuneserver/server.cpp
@@ -63,15 +63,20 @@ Server::Server(QWidget *parent)
return;
}
//! [0]
- QList<QHostAddress> ipAddresseList = QNetworkInterface::allAddresses();
- QString ipAddresses;
- for (int i = 0; i < ipAddresseList.size(); ++i) {
- ipAddresses.append(ipAddresseList.at(i).toString()).append("\n");
+ QString ipAddress;
+ QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
+ // use the first non-localhost IPv4 address
+ for (int i = 0; i < ipAddressesList.size(); ++i) {
+ if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
+ ipAddressesList.at(i).toIPv4Address())
+ ipAddress = ipAddressesList.at(i).toString();
}
-
- statusLabel->setText(tr("The server is running on \n IP: \n%1 PORT: \n%2\n"
+ // if we did not find one, use IPv4 localhost
+ if (ipAddress.isEmpty())
+ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
+ statusLabel->setText(tr("The server is running on\nIP: \n%1 port:\n%2\n"
"Run the Fortune Client example now.")
- .arg(ipAddresses).arg(tcpServer->serverPort()));
+ .arg(ipAddress).arg(tcpServer->serverPort()));
//! [1]
//! [2]
diff --git a/examples/script/context2d/context2d.cpp b/examples/script/context2d/context2d.cpp
index 5b4a1cf..05352cd 100644
--- a/examples/script/context2d/context2d.cpp
+++ b/examples/script/context2d/context2d.cpp
@@ -369,7 +369,7 @@ void Context2D::setLineCap(const QString &capString)
style = Qt::RoundCap;
else if (capString == "square")
style = Qt::SquareCap;
- else if (capString == "butt")
+ else //if (capString == "butt")
style = Qt::FlatCap;
m_state.lineCap = style;
m_state.flags |= DirtyLineCap;
@@ -397,7 +397,7 @@ void Context2D::setLineJoin(const QString &joinString)
style = Qt::RoundJoin;
else if (joinString == "bevel")
style = Qt::BevelJoin;
- else if (joinString == "miter")
+ else //if (joinString == "miter")
style = Qt::MiterJoin;
m_state.lineJoin = style;
m_state.flags |= DirtyLineJoin;
diff --git a/examples/script/context2d/main.cpp b/examples/script/context2d/main.cpp
index a61452a..c9a8898 100644
--- a/examples/script/context2d/main.cpp
+++ b/examples/script/context2d/main.cpp
@@ -48,7 +48,6 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
Window win;
- //win.show();
- win.showFullScreen();
+ win.show();
return app.exec();
}
diff --git a/examples/uitools/multipleinheritance/multipleinheritance.pro b/examples/uitools/multipleinheritance/multipleinheritance.pro
index e8f59fb..b401c05 100644
--- a/examples/uitools/multipleinheritance/multipleinheritance.pro
+++ b/examples/uitools/multipleinheritance/multipleinheritance.pro
@@ -10,4 +10,7 @@ sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/uitools/multipleinheritance
INSTALLS += target sources
-symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7C1
+} \ No newline at end of file
diff --git a/examples/video/videographicsitem/videographicsitem.pro b/examples/video/videographicsitem/videographicsitem.pro
index 7e0b4c5..7ebd975 100644
--- a/examples/video/videographicsitem/videographicsitem.pro
+++ b/examples/video/videographicsitem/videographicsitem.pro
@@ -14,3 +14,8 @@ target.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem
sources.files = $$SOURCES $$HEADERS $$FORMS $$RESOURCES *.pro *.png images
sources.path = $$[QT_INSTALL_EXAMPLES]/video/videographicsitem
INSTALLS += target sources
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7C2
+}
diff --git a/examples/video/videowidget/videowidget.pro b/examples/video/videowidget/videowidget.pro
index a006f2f..cc0260f 100644
--- a/examples/video/videowidget/videowidget.pro
+++ b/examples/video/videowidget/videowidget.pro
@@ -12,3 +12,8 @@ SOURCES = \
videoplayer.cpp \
videowidget.cpp \
videowidgetsurface.cpp
+
+symbian {
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+ TARGET.UID3 = 0xA000D7C3
+}
diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp
index cdc9e72..6ee259b 100644
--- a/examples/xml/saxbookmarks/mainwindow.cpp
+++ b/examples/xml/saxbookmarks/mainwindow.cpp
@@ -67,7 +67,10 @@ MainWindow::MainWindow()
void MainWindow::open()
{
#if defined(Q_OS_SYMBIAN)
- QDir::setCurrent("/Data/qt/saxbookmarks");
+ // Always look for bookmarks on the same drive where the application is installed to.
+ QString bookmarksFolder = QCoreApplication::applicationFilePath().left(1);
+ bookmarksFolder.append(":/Data/qt/saxbookmarks");
+ QDir::setCurrent(bookmarksFolder);
#endif
QString fileName =
QFileDialog::getOpenFileName(this, tr("Open Bookmark File"),