X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=orientationcontrolledgraphicspixmapobject.cpp;h=3b41ab217f4d35da9b2a9abcbcf97eed3c243138;hb=refs%2Fheads%2Fharmattan;hp=391389918c02a94364d5cde54348440ffef10fdd;hpb=02d1e84fa7f57e2b1e6f89a9c9bfa5f9a5e835e2;p=ghostsoverboard diff --git a/orientationcontrolledgraphicspixmapobject.cpp b/orientationcontrolledgraphicspixmapobject.cpp index 3913899..3b41ab2 100644 --- a/orientationcontrolledgraphicspixmapobject.cpp +++ b/orientationcontrolledgraphicspixmapobject.cpp @@ -1,5 +1,5 @@ /************************************************************************** - Ghosts Overboard - a game for Maemo 5 + Ghosts Overboard - a game 'Meego 1.2 Harmattan' Copyright (C) 2011 Heli Hyvättinen @@ -36,15 +36,13 @@ OrientationControlledGraphicsPixmapObject::OrientationControlledGraphicsPixmapOb QObject(), QGraphicsPixmapItem (pixmap, parent) { - connect(&rotationSensor_,SIGNAL(readingChanged()),this,SLOT(readRotationSensor())); + rotationReadingInitialized_ = false; + rotationReadingTimer_.setInterval(15); + connect(&rotationReadingTimer_,SIGNAL(timeout()),this,SLOT(readRotationSensor())); + connect(&rotationSensor_,SIGNAL(readingChanged()),this,SLOT(rotationSensorReady())); + - qrangelist rangelist = rotationSensor_.availableDataRates(); - qDebug() << rangelist.length() << "ranges found"; - foreach (qrange range, rangelist) - { - qDebug() << "Rotation sensor: " << range.first <<", " << "range.second"; - } } void OrientationControlledGraphicsPixmapObject::startMoving() @@ -58,6 +56,8 @@ void OrientationControlledGraphicsPixmapObject::startMoving() void OrientationControlledGraphicsPixmapObject::stopMoving() { rotationSensor_.stop(); + rotationReadingInitialized_ = false; + rotationReadingTimer_.stop(); // qDebug () << "trying to stop the sensor"; } @@ -66,6 +66,17 @@ void OrientationControlledGraphicsPixmapObject::readRotationSensor() if (!scene()) //no movement if this item does not belong to a scene return; + +//Test reading sensor information. Since qDebug has ceased to work, uses qCritical instead... +// qrangelist rangelist = rotationSensor_.availableDataRates(); + +// qCritical() << rangelist.length() << "ranges found"; +// foreach (qrange range, rangelist) +// { +// qCritical() << "Rotation sensor: " << range.first <<", " << "range.second"; +// } +// qCritical() << "Current data date is " << rotationSensor_.dataRate(); + QRect sceneRectangle = scene()->sceneRect().toRect(); @@ -88,8 +99,8 @@ void OrientationControlledGraphicsPixmapObject::readRotationSensor() // int newy = y() + deltay/15; //this is for Harmattan - int newx = x() + deltax/3; - int newy = y() + deltay/3; + int newx = x() + deltax/12; + int newy = y() + deltay/12; // qDebug() << sceneRectangle.left() << sceneRectangle.right(); @@ -100,12 +111,13 @@ void OrientationControlledGraphicsPixmapObject::readRotationSensor() int finalY = qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height()); + setPos(QPointF(finalX,finalY)); - QPropertyAnimation * animation = new QPropertyAnimation(this,"pos",this); - animation->setDuration(60); //milliseconds - animation->setStartValue(pos()); - animation->setEndValue( QPointF(finalX,finalY)); - animation->start(QAbstractAnimation::DeleteWhenStopped); +// QPropertyAnimation * animation = new QPropertyAnimation(this,"pos",this); +// animation->setDuration(60); //milliseconds +// animation->setStartValue(pos()); +// animation->setEndValue( QPointF(finalX,finalY)); +// animation->start(QAbstractAnimation::DeleteWhenStopped); //handle collisions and move back to the original position if false returned @@ -123,3 +135,27 @@ bool OrientationControlledGraphicsPixmapObject::handleCollisions() return true; } + +void OrientationControlledGraphicsPixmapObject::setPos(const QPointF &pos) +{ + QPointF oldPos = OrientationControlledGraphicsPixmapObject::pos(); + + QGraphicsPixmapItem::setPos(pos); + + if (!handleCollisions()) + { + QGraphicsPixmapItem::setPos(oldPos); + } + +} + + +void OrientationControlledGraphicsPixmapObject::rotationSensorReady() +{ + + if (!rotationReadingInitialized_) + { + rotationReadingInitialized_ = true; + rotationReadingTimer_.start(); + } +}