Guest User

orientation.cpp

a guest
Dec 24th, 2010
638
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QOrientationSensor>
  2.  
  3. #include "orientation.h"
  4.  
  5. QTM_USE_NAMESPACE
  6.  
  7.     Orientation::Orientation(QObject *parent) :
  8.     QObject(parent), m_state("Portrait")
  9. {
  10.   m_sensor = new QOrientationSensor(this);
  11.   connect(m_sensor, SIGNAL(readingChanged()), SLOT(onReadingChanged()));
  12.   m_sensor->start();
  13. }
  14.  
  15. Orientation::~Orientation() {
  16.   delete m_sensor;
  17. }
  18.  
  19. void Orientation::onReadingChanged()
  20. {
  21.   QOrientationReading* reading = m_sensor->reading();
  22.   switch(reading->orientation())
  23.   {
  24.   case QOrientationReading::TopUp:
  25.     m_state = "Landscape";
  26.     emit orientationChanged();
  27.     break;
  28.   case QOrientationReading::TopDown:
  29.     m_state = "LandscapeInverted";
  30.     emit orientationChanged();
  31.     break;
  32.   case QOrientationReading::LeftUp:
  33.     m_state = "Portrait";
  34.     emit orientationChanged();
  35.     break;
  36.   case QOrientationReading::RightUp:
  37.     m_state = "PortraitInverted";
  38.     emit orientationChanged();
  39.   default:
  40.     break;
  41.   }
  42. }
RAW Paste Data