qtmobility/examples/sensors/panorama/orientationcontroller.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 11 Jun 2010 14:26:25 +0300
changeset 11 06b8e2af4411
child 14 6fbed849b4f4
permissions -rw-r--r--
Revision: 201021 Kit: 2010123



#include "keycontroller.h"
#include "orientationcontroller.h"
#include "view.h"


OrientationController::OrientationController( ): KeyController(){
    m_delay=20;
    m_step=7;
}


void OrientationController::startSensor()
{
    m_orientationSensor.connectToBackend();
    m_orientationSensor.start();
    connect(&m_orientationSensor, SIGNAL(readingChanged()), this, SLOT(update()));
}

void OrientationController::stopSensor(){ m_orientationSensor.stop();}


void OrientationController::updateCoordinates(){
    handleKeyPress(m_exCode);
    m_step = m_exCode!=0? m_step+2 : 5;
}


void OrientationController::update()
{
    switch (m_orientationSensor.reading()->orientation()){
    case QTM_NAMESPACE::QOrientationReading::TopUp:
        m_exCode = Qt::Key_Up;
        break;
    case QTM_NAMESPACE::QOrientationReading::TopDown:
        m_exCode = Qt::Key_Down;
        break;
    case QTM_NAMESPACE::QOrientationReading::LeftUp:
        m_exCode = Qt::Key_Left;
        break;
    case QTM_NAMESPACE::QOrientationReading::RightUp:
        m_exCode = Qt::Key_Right;
        break;
    default:
        m_exCode = 0;
        return;
    }
    handleKeyPress(m_exCode);
}