#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()));
}
orientations_ = orientations;
}
+void Orientation::setOrientationType(OrientationType type)
+{
+ type_ = type;
+
+ handleManualOrientation();
+}
+
void Orientation::update()
{
+ if(type_ != TYPE_AUTO)
+ {
+ handleManualOrientation();
+ return;
+ }
+
using QtMobility::QOrientationReading;
OrientationName orientation = LANDSCAPE;
void Orientation::onReadingChanged()
{
+ if(type_ != TYPE_AUTO)
+ {
+ return;
+ }
+
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;
+ }
+}