aboutsummaryrefslogtreecommitdiff
path: root/demos/widgetsgallery/panningbenchmark.cpp
diff options
context:
space:
mode:
authorArmin Berres <armin.berres@basyskom.de>2010-02-23 17:01:48 +0100
committerArmin Berres <armin.berres@basyskom.de>2010-02-25 17:05:32 +0100
commit7b4908c8f7b4bfea392c9422a5b3c57a05f42bda (patch)
treed7167c0a67ed22a4c4fe6ff48735cd34693b6982 /demos/widgetsgallery/panningbenchmark.cpp
parent1c40e6060f89d75a3dbb97ec67d38159910e81bb (diff)
Changes: add panning benchmark to widgetsgallery
RevBy: Bernd Lamecker Datails: Example output: Page name StaticPageBenchmark (0) PanningBenchmark StaticPageBenchmark (90) Application Menu 39.42fps | 4008ms 35.90fps | 585ms 30.38fps | 4016ms Object menu 33.17fps | 4010ms 23.03fps | 304ms 25.99fps | 4002ms Dialogs and Notifications... 36.27fps | 4025ms 25.59fps | 1094ms 28.46fps | 4005ms Navigation Bar 41.55fps | 4019ms 33.33fps | 90ms 38.40fps | 4010ms Tool Bar 42.11fps | 4013ms n/a 38.44fps | 4006ms Container 52.09fps | 4012ms n/a 50.39fps | 4009ms
Diffstat (limited to 'demos/widgetsgallery/panningbenchmark.cpp')
-rw-r--r--demos/widgetsgallery/panningbenchmark.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/demos/widgetsgallery/panningbenchmark.cpp b/demos/widgetsgallery/panningbenchmark.cpp
new file mode 100644
index 00000000..28d994e3
--- /dev/null
+++ b/demos/widgetsgallery/panningbenchmark.cpp
@@ -0,0 +1,83 @@
+#include "panningbenchmark.h"
+#include "timedemo.h"
+
+#include <DuiApplicationPage>
+#include <DuiPannableViewport>
+#include <DuiPhysics2DPanning>
+
+#include <QTimer>
+#include <qdebug.h>
+
+namespace {
+ const int updateInterval = 20; // ms
+ const int yOffset = 20;
+}
+
+PanningBenchmark::PanningBenchmark(DuiApplicationPage *applicationPage, Timedemo *timedemo)
+ : TimedemoBenchmark(applicationPage, timedemo)
+ , timingStarted(false)
+{
+ pannableViewport = 0;
+ QList<QGraphicsItem *> childItems = applicationPage->childItems();
+ foreach(QGraphicsItem * childItem, childItems) {
+ if (DuiPannableViewport * viewport = dynamic_cast<DuiPannableViewport*>(childItem)) {
+ pannableViewport = viewport;
+ break;
+ }
+ }
+
+ if (!pannableViewport) {
+ qFatal("Did not find matching viewport of DuiApplicationWindow");
+ }
+}
+
+QString PanningBenchmark::name() {
+ return "PanningBenchmark";
+}
+
+void PanningBenchmark::start()
+{
+ if (!applicationPage->isActiveWindow()) {
+ connect(applicationPage, SIGNAL(windowShown()), this, SLOT(waitBeforePanning()));
+ applicationPage->appear();
+ } else {
+ QTimer::singleShot(0, this, SLOT(panDown()));
+ }
+}
+
+//HACK! if we do not wait pannableViewport->physics()->range() is (0, 0, 0, 0) because
+// the widgets are not completely set up yet
+void PanningBenchmark::waitBeforePanning()
+{
+ QTimer::singleShot(500, this, SLOT(panDown()));
+}
+
+void PanningBenchmark::panDown()
+{
+ if (!timingStarted) {
+ timedemo->startTiming();
+ timingStarted = true;
+ formerPosition = pannableViewport->physics()->position();
+ }
+
+ QPointF currentPosition = pannableViewport->physics()->position();
+ QRectF range = pannableViewport->physics()->range();
+
+ if (currentPosition.y() < range.height()) {
+ pannableViewport->physics()->setPosition(currentPosition + QPointF(0., yOffset));
+ QTimer::singleShot(20, this, SLOT(panDown()));
+ } else {
+ terminateBenchmark();
+ }
+
+}
+
+void PanningBenchmark::terminateBenchmark()
+{
+ timedemo->stopTiming();
+ pannableViewport->physics()->setPosition(formerPosition);
+
+ qDebug() << "end" << pannableViewport->widget()->pos() << pannableViewport->physics()->range();
+
+ emit finished();
+}