summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-04-06 15:10:26 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-04-06 15:15:53 (GMT)
commit1bb9d8fcd59a91751c8d91e2885e2b05eff4d1bb (patch)
treebe50c79ad2211cb4ab5ee6547ff4be207bb038b7 /examples
parent9b3de2a229bfd393a13bcf08750c2284f775d8c5 (diff)
downloadQt-1bb9d8fcd59a91751c8d91e2885e2b05eff4d1bb.zip
Qt-1bb9d8fcd59a91751c8d91e2885e2b05eff4d1bb.tar.gz
Qt-1bb9d8fcd59a91751c8d91e2885e2b05eff4d1bb.tar.bz2
BT: Adjust the colliding mice example to work with coalesced updates.
It seems that Cocoa is much more strict about coalesced updates than Carbon ever was. The upshot of this is that some examples that "worked" after a fashion in Carbon, do not exhibit good frame rates with Cocoa. The reason why is that apparently Cocoa will decide to flush to the screen every time a timer fires. If you have a lot of timers that are all dependent on doing on update to the screen, you will get undesirable effects. Thankfully, it is possible to adjust the examples to follow best practices and get a good result. So, we now only do the animation once using QGraphicsScene::advance(). We are also able to make the mice less heavy (no QObject subclass). I've updated the docs and someone on the doc team has kindly volunteered to go through them. Reviewed-by: Andreas
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/collidingmice/main.cpp4
-rw-r--r--examples/graphicsview/collidingmice/mouse.cpp5
-rw-r--r--examples/graphicsview/collidingmice/mouse.h7
3 files changed, 9 insertions, 7 deletions
diff --git a/examples/graphicsview/collidingmice/main.cpp b/examples/graphicsview/collidingmice/main.cpp
index 4a44481..23c91b0 100644
--- a/examples/graphicsview/collidingmice/main.cpp
+++ b/examples/graphicsview/collidingmice/main.cpp
@@ -83,6 +83,10 @@ int main(int argc, char **argv)
view.resize(400, 300);
view.show();
+ QTimer timer;
+ QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
+ timer.start(1000 / 33);
+
return app.exec();
}
//! [6]
diff --git a/examples/graphicsview/collidingmice/mouse.cpp b/examples/graphicsview/collidingmice/mouse.cpp
index 1d10574..bbdb4e3 100644
--- a/examples/graphicsview/collidingmice/mouse.cpp
+++ b/examples/graphicsview/collidingmice/mouse.cpp
@@ -65,7 +65,6 @@ Mouse::Mouse()
color(qrand() % 256, qrand() % 256, qrand() % 256)
{
rotate(qrand() % (360 * 16));
- startTimer(1000 / 33);
}
//! [0]
@@ -123,8 +122,10 @@ void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *
//! [3]
//! [4]
-void Mouse::timerEvent(QTimerEvent *)
+void Mouse::advance(int step)
{
+ if (!step)
+ return;
//! [4]
// Don't move too far away
//! [5]
diff --git a/examples/graphicsview/collidingmice/mouse.h b/examples/graphicsview/collidingmice/mouse.h
index 832ea53..c08ce4a 100644
--- a/examples/graphicsview/collidingmice/mouse.h
+++ b/examples/graphicsview/collidingmice/mouse.h
@@ -43,13 +43,10 @@
#define MOUSE_H
#include <QGraphicsItem>
-#include <QObject>
//! [0]
-class Mouse : public QObject, public QGraphicsItem
+class Mouse : public QGraphicsItem
{
- Q_OBJECT
-
public:
Mouse();
@@ -59,7 +56,7 @@ public:
QWidget *widget);
protected:
- void timerEvent(QTimerEvent *event);
+ void advance(int step);
private:
qreal angle;