1 #include "orientation.h"
2 #include <qmorientation.h>
5 Orientation::Orientation(QObject *parent) :
7 m_orientation(new MeeGo::QmOrientation(this)),
10 QObject::connect(m_orientation, SIGNAL(orientationChanged(const MeeGo::QmOrientationReading&)),
11 this, SLOT(orientationChanged(const MeeGo::QmOrientationReading&)));
13 if (m_orientation->requestSession(MeeGo::QmSensor::SessionTypeListen)
14 == MeeGo::QmSensor::SessionTypeNone) {
15 qDebug() << "Failed to get listen session:" << m_orientation->lastError();
19 Orientation::~Orientation() {
20 m_orientation->stop();
23 bool Orientation::isActive() const {
24 return m_orientation->isRunning();
27 void Orientation::setActive(bool active) {
28 if (active == isActive()) {
33 m_orientation->start();
34 orientationChanged(m_orientation->orientation());
37 m_orientation->stop();
38 m_direction = Unknown;
40 emit orientationChanged();
46 Orientation::OrientationDirection Orientation::orientation() const {
50 void Orientation::orientationChanged(const MeeGo::QmOrientationReading& value) {
51 OrientationDirection direction = Unknown;
53 switch (value.value) {
54 case MeeGo::QmOrientation::BottomUp:
55 direction = InvertedLandscape;
58 case MeeGo::QmOrientation::BottomDown:
59 direction = Landscape;
62 case MeeGo::QmOrientation::LeftUp:
66 case MeeGo::QmOrientation::RightUp:
67 direction = InvertedPortrait;
75 if (direction != m_direction) {
76 m_direction = direction;
77 emit orientationChanged();