Added altitude display to detail screen. Added option to disable auto rotation.
[jspeed] / src / orientation.cpp
index 0452cf1..fccb24a 100644 (file)
@@ -19,7 +19,8 @@
 #include "orientation.h"
 
 Orientation::Orientation(QMainWindow* window): QtMobility::QOrientationSensor(window),
 #include "orientation.h"
 
 Orientation::Orientation(QMainWindow* window): QtMobility::QOrientationSensor(window),
-current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window)
+current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window),
+type_(TYPE_AUTO)
 {
     connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
 }
 {
     connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
 }
@@ -29,8 +30,21 @@ void Orientation::setSupportedOrientations(int orientations)
     orientations_ = orientations;
 }
 
     orientations_ = orientations;
 }
 
+void Orientation::setOrientationType(OrientationType type)
+{
+    type_ = type;
+
+    handleManualOrientation();
+}
+
 void Orientation::update()
 {
 void Orientation::update()
 {
+    if(type_ != TYPE_AUTO)
+    {
+        handleManualOrientation();
+        return;
+    }
+
     using QtMobility::QOrientationReading;
 
     OrientationName orientation = LANDSCAPE;
     using QtMobility::QOrientationReading;
 
     OrientationName orientation = LANDSCAPE;
@@ -86,9 +100,43 @@ void Orientation::update()
 
 void Orientation::onReadingChanged()
 {
 
 void Orientation::onReadingChanged()
 {
+    if(type_ != TYPE_AUTO)
+    {
+        return;
+    }
+
     if(reading()->orientation() != current_)
     {
         update();
         emit changed();
     }
 }
     if(reading()->orientation() != current_)
     {
         update();
         emit changed();
     }
 }
+
+void Orientation::handleManualOrientation()
+{
+    switch(type_)
+    {
+    case TYPE_LANDSCAPE:
+        if(orientations_ & LANDSCAPE)
+        {
+            window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+        }
+        else if(orientations_ & PORTRAIT)
+        {
+            window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+        }
+        break;
+    case TYPE_PORTRAIT:
+        if(orientations_ & PORTRAIT)
+        {
+            window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+        }
+        else if(orientations_ & LANDSCAPE)
+        {
+            window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+        }
+        break;
+    default:
+        break;
+    }
+}