-#include "rotation.h"
-#include <QOrientationReading>
-#include <QOrientationSensor>
-#include <QTimer>
-
-QTM_USE_NAMESPACE
-
-Rotation::Rotation(QObject *parent) :
- QObject(parent)
-{
- startReading();
-}
-
-void Rotation::onReadingChanged()
-{
- if (m_sensor) {
- switch (m_sensor->reading()->orientation()) {
- case QOrientationReading::TopUp:
- case QOrientationReading::TopDown:
- if( m_orientation == "potrait") {
- m_orientation = "";
- emit orientationChanged();
- }
- break;
- case QOrientationReading::LeftUp:
- case QOrientationReading::RightUp:
- if (m_orientation == "") {
- m_orientation = "potrait";
- emit orientationChanged();
- }
- break;
- default:
- break;
- }
-
- delete m_sensor;
- m_sensor = 0;
-
- QTimer::singleShot(1000, this, SLOT(startReading()));
- }
-}
-
-const QString& Rotation::orientation() const
-{
- return m_orientation;
-}
-
-void Rotation::startReading()
-{
- m_sensor = new QOrientationSensor(this);
- connect(m_sensor, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
- m_sensor->start();
-}