From 6aa99a265167cc8005afaae5958e87f1a494163e Mon Sep 17 00:00:00 2001 From: Armin Berres Date: Mon, 19 Apr 2010 18:02:48 +0200 Subject: Changes: panning in portrait mode for the timedemo RevBy: TrustMe Detail: This patch is based on work by Hans Sandvall. So credits go to him. --- demos/widgetsgallery/panningbenchmark.cpp | 35 +++++++++++++++++++++++++------ demos/widgetsgallery/panningbenchmark.h | 11 +++++++++- demos/widgetsgallery/timedemopage.cpp | 3 +++ 3 files changed, 42 insertions(+), 7 deletions(-) (limited to 'demos') diff --git a/demos/widgetsgallery/panningbenchmark.cpp b/demos/widgetsgallery/panningbenchmark.cpp index aaf5ea89..cf3594f4 100644 --- a/demos/widgetsgallery/panningbenchmark.cpp +++ b/demos/widgetsgallery/panningbenchmark.cpp @@ -1,6 +1,7 @@ #include "panningbenchmark.h" #include "timedemo.h" +#include #include #include #include @@ -8,14 +9,18 @@ #include #include + namespace { const int updateInterval = 20; // ms const qreal ySpeed = .5; // pixel/ms } -PanningBenchmark::PanningBenchmark(MApplicationPage *applicationPage, Timedemo *timedemo) - : TimedemoBenchmark(applicationPage, timedemo) - , timingStarted(false) +PanningBenchmark::PanningBenchmark( + MApplicationPage * applicationPage, Timedemo * timedemo, M::OrientationAngle targetOrientationAngle) : + TimedemoBenchmark(applicationPage, timedemo), + timingStarted(false), + targetOrientationAngle(targetOrientationAngle) + { pannableViewport = 0; QList childItems = applicationPage->childItems(); @@ -32,7 +37,7 @@ PanningBenchmark::PanningBenchmark(MApplicationPage *applicationPage, Timedemo * } QString PanningBenchmark::name() { - return "PanningBenchmark"; + return QString("PanningBenchmark (%1)").arg(QString::number(targetOrientationAngle)); } void PanningBenchmark::start() @@ -41,7 +46,7 @@ void PanningBenchmark::start() connect(applicationPage, SIGNAL(appeared()), this, SLOT(waitBeforePanning())); applicationPage->appear(); } else { - QTimer::singleShot(0, this, SLOT(panDown())); + waitBeforePanning(); } } @@ -49,7 +54,8 @@ void PanningBenchmark::start() // the widgets are not completely set up yet void PanningBenchmark::waitBeforePanning() { - QTimer::singleShot(500, this, SLOT(panDown())); + setAngle(); + QTimer::singleShot(2500, this, SLOT(panDown())); } void PanningBenchmark::panDown() @@ -77,8 +83,25 @@ void PanningBenchmark::terminateBenchmark() { timedemo->stopTiming(); pannableViewport->physics()->setPosition(formerPosition); + resetAngle(); qDebug() << "end" << pannableViewport->widget()->pos() << pannableViewport->physics()->range(); emit finished(); } + +void PanningBenchmark::setAngle() +{ + formerOrientationAngle = MApplication::activeWindow()->orientationAngle(); + MApplication::activeWindow()->setOrientationAngleLocked(false); + MApplication::activeWindow()->setOrientationAngle(targetOrientationAngle); + MApplication::activeWindow()->setOrientationAngleLocked(true); +} + +void PanningBenchmark::resetAngle() +{ + MApplication::activeWindow()->setOrientationAngleLocked(false); + MApplication::activeWindow()->setOrientationAngle(formerOrientationAngle); + MApplication::activeWindow()->setOrientationAngleLocked(true); +} + diff --git a/demos/widgetsgallery/panningbenchmark.h b/demos/widgetsgallery/panningbenchmark.h index c2ecdefb..f94517f5 100644 --- a/demos/widgetsgallery/panningbenchmark.h +++ b/demos/widgetsgallery/panningbenchmark.h @@ -4,6 +4,8 @@ #include "timedemobenchmark.h" #include +#include + #include /** @@ -14,7 +16,7 @@ class PanningBenchmark : public TimedemoBenchmark { Q_OBJECT public: - PanningBenchmark(MApplicationPage *applicationPage, Timedemo *timedemo); + PanningBenchmark(MApplicationPage *applicationPage, Timedemo *timedemo, M::OrientationAngle targetOrientationAngle = M::Angle0); QString name(); void start(); @@ -24,6 +26,9 @@ private slots: void panDown(); void terminateBenchmark(); + void setAngle(); + void resetAngle(); + private: MPannableViewport *pannableViewport; @@ -33,6 +38,10 @@ private: QTime timer; +private: + M::OrientationAngle targetOrientationAngle; + M::OrientationAngle formerOrientationAngle; + }; #endif // PANNINGBENCHMARK_H diff --git a/demos/widgetsgallery/timedemopage.cpp b/demos/widgetsgallery/timedemopage.cpp index defe5424..22b9fc3e 100644 --- a/demos/widgetsgallery/timedemopage.cpp +++ b/demos/widgetsgallery/timedemopage.cpp @@ -21,6 +21,9 @@ void TimedemoPage::createBenchmarks(Timedemo *timedemo) benchmark = QSharedPointer(new StaticPageBenchmark(this, timedemo, M::Angle90)); m_benchmarks.append(benchmark); + + benchmark = QSharedPointer(new PanningBenchmark(this, timedemo, M::Angle90)); + m_benchmarks.append(benchmark); } QVector > TimedemoPage::benchmarks() -- cgit v1.2.3