--- /dev/null
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+#if defined(Q_WS_S60)
+ w.showMaximized();
+#else
+ w.show();
+#endif
+
+ return a.exec();
+}
--- /dev/null
+#include "mainwindow.h"
+#include <QPixmap>
+#include <QTimer>
+#include <QDebug>
+#include <QAction>
+#include <QMenuBar>
+
+
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ paused_ = false;
+
+ pScene_ = new QGraphicsScene ();
+ pView_ = new QGraphicsView ();
+
+ QPixmap waves (":/pix/meri.png");
+ pScene_->setBackgroundBrush(QBrush(waves));
+
+ pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/tursas.png"));
+ pScene_->addItem(pTursas_);
+
+ pView_->setScene(pScene_);
+ setCentralWidget(pView_);
+
+
+ //the boundaries of the scene are set to match the size of the view window, which is not
+ //available in the constructor --> timer needed
+ QTimer::singleShot(60,this,SLOT(initializeBoundaries()));
+
+
+ QAction * pPauseAction = new QAction(tr("Pause"),this);
+ pPauseAction->setCheckable(true);
+ addAction(pPauseAction);
+ connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
+ menuBar()->addAction(pPauseAction);
+
+}
+
+MainWindow::~MainWindow()
+{
+
+}
+
+void MainWindow::initializeBoundaries()
+{
+ //the boundaries of the scene are set to match the size of the view window, and
+ //the view is set to show exactly the whole scene area
+
+ QPoint topleft (0,0);
+ QSize windowsize = pView_->size();
+ QRectF rectangle (topleft,windowsize);
+
+
+ pScene_->setSceneRect(rectangle);
+ pView_->setSceneRect(rectangle);
+ pTursas_->setBoundaries(rectangle);
+ pTursas_->startMoving();
+
+ qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
+}
+
+void MainWindow::pause(bool paused)
+{
+// qDebug() << "pause pressed " << paused;
+ if (paused_ == paused)
+ return;
+
+ paused_ = paused;
+
+ if (paused == false)
+ {
+ // qDebug() << "starting to move again";
+ pTursas_->startMoving();
+ }
+
+ else
+ {
+ qDebug("about to stop movement");
+ pTursas_->stopMoving();
+ }
+}
--- /dev/null
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+#include <QGraphicsView>
+#include "orientationcontrolledgraphicspixmapobject.h"
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+public slots:
+ void initializeBoundaries();
+ void pause(bool paused);
+
+private:
+
+QGraphicsScene * pScene_;
+QGraphicsView * pView_;
+OrientationControlledGraphicsPixmapObject * pTursas_;
+bool paused_;
+
+
+
+
+};
+
+#endif // MAINWINDOW_H
--- /dev/null
+<RCC>
+ <qresource prefix="/pix">
+ <file>meri.png</file>
+ <file>tursas.png</file>
+ </qresource>
+</RCC>
--- /dev/null
+#include "orientationcontrolledgraphicspixmapobject.h"
+#include <QDebug>
+#include <QGraphicsScene>
+
+//OrientationControlledGraphicsPixmapObject::OrientationControlledGraphicsPixmapObject (QGraphicsItem *parent) :
+// QObject(), QGraphicsPixmapItem (parent)
+//{
+
+//}
+
+OrientationControlledGraphicsPixmapObject::OrientationControlledGraphicsPixmapObject(QPixmap pixmap, QGraphicsItem *parent) :
+ QObject(), QGraphicsPixmapItem (pixmap, parent)
+{
+
+ connect(&rotationSensor_,SIGNAL(readingChanged()),this,SLOT(readRotationSensor()));
+
+
+
+}
+
+void OrientationControlledGraphicsPixmapObject::startMoving()
+{
+ rotationSensor_.start();
+ qDebug() << "started the sensor";
+ qDebug() << rotationSensor_.isActive();
+}
+
+
+void OrientationControlledGraphicsPixmapObject::stopMoving()
+{
+ rotationSensor_.stop();
+ qDebug () << "trying to stop the sensor";
+}
+
+void OrientationControlledGraphicsPixmapObject::readRotationSensor()
+{
+ if (!scene()) //no movement if this item does not belong to a scene
+ return;
+
+ QRect sceneRectangle = scene()->sceneRect().toRect();
+
+
+ QRotationReading* pSensorData = rotationSensor_.reading();
+
+ int deltay = pSensorData->x(); //yes, you need the "x" value from the sensor for "y" direction in the scene...
+ int deltax = pSensorData->y(); //...and vice versa
+
+
+ // qDebug() << deltax << " " << deltay;
+
+ int newx = x() + deltax/15;
+ int newy = y() + deltay/15;
+
+
+// qDebug() << sceneRectangle.left() << sceneRectangle.right();
+
+
+ setX(qBound(sceneRectangle.left(),newx,sceneRectangle.right()-pixmap().width()));
+ setY(qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height()));
+
+}
+
+
+void OrientationControlledGraphicsPixmapObject::setBoundaries(QRectF boundaryrect)
+{
+ boundaryrect_ = boundaryrect;
+
+}
+
+
+
--- /dev/null
+#ifndef ORIENTATIONCONTROLLEDGRAPHICSPIXMAPOBJECT_H
+#define ORIENTATIONCONTROLLEDGRAPHICSPIXMAPOBJECT_H
+
+#include <QGraphicsPixmapItem>
+#include <QRotationSensor>
+
+QTM_USE_NAMESPACE
+
+
+class OrientationControlledGraphicsPixmapObject : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+public:
+// explicit OrientationControlledGraphicsPixmapObject(QGraphicsItem *parent = 0);
+ explicit OrientationControlledGraphicsPixmapObject(QPixmap pixmap = 0, QGraphicsItem *parent = 0);
+
+signals:
+
+public slots:
+ void startMoving();
+ void stopMoving();
+ void readRotationSensor();
+ void setBoundaries(QRectF boundaryrect);
+
+
+private:
+
+ QRotationSensor rotationSensor_;
+
+ QRectF boundaryrect_;
+
+};
+
+#endif // ORIENTATIONCONTROLLEDGRAPHICSPIXMAPOBJECT_H
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2011-05-03T17:35:02
+#
+#-------------------------------------------------
+
+QT += core gui
+
+TARGET = rotationcontrol2
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+ mainwindow.cpp \
+ orientationcontrolledgraphicspixmapobject.cpp
+
+HEADERS += mainwindow.h \
+ orientationcontrolledgraphicspixmapobject.h
+
+CONFIG += mobility
+MOBILITY = sensors
+
+symbian {
+ TARGET.UID3 = 0xe3f4bbc2
+ # TARGET.CAPABILITY +=
+ TARGET.EPOCSTACKSIZE = 0x14000
+ TARGET.EPOCHEAPSIZE = 0x020000 0x800000
+}
+
+unix:!symbian {
+ maemo5 {
+ target.path = /opt/usr/bin
+ } else {
+ target.path = /usr/local/bin
+ }
+ INSTALLS += target
+}
+
+RESOURCES += \
+ orientationcontrol2pix.qrc