/**************************************************************************
- Ghosts Overboard - a game for Maemo 5
+ Ghosts Overboard - a game 'Meego 1.2 Harmattan'
Copyright (C) 2011 Heli Hyvättinen
#include "orientationcontrolledgraphicspixmapobject.h"
#include <QDebug>
#include <QGraphicsScene>
+#include <QPropertyAnimation>
//OrientationControlledGraphicsPixmapObject::OrientationControlledGraphicsPixmapObject (QGraphicsItem *parent) :
// QObject(), QGraphicsPixmapItem (parent)
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()));
void OrientationControlledGraphicsPixmapObject::stopMoving()
{
rotationSensor_.stop();
+ rotationReadingInitialized_ = false;
+ rotationReadingTimer_.stop();
// qDebug () << "trying to stop the sensor";
}
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();
int oldx = x();
int oldy = y();
- int newx = x() + deltax/15;
- int newy = y() + deltay/15;
+ //this is how it works on maemo
+// int newx = x() + deltax/15;
+// int newy = y() + deltay/15;
+
+ //this is for Harmattan
+ int newx = x() + deltax/12;
+ int newy = y() + deltay/12;
// qDebug() << sceneRectangle.left() << sceneRectangle.right();
- setX(qBound(sceneRectangle.left(),newx,sceneRectangle.right()-pixmap().width()));
- setY(qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height()));
+ int finalX = qBound(sceneRectangle.left(),newx,sceneRectangle.right()-pixmap().width());
+ 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);
//handle collisions and move back to the original position if false returned
- if (handleCollisions() == false)
- {
- setX(oldx);
- setY(oldy);
- }
+// if (handleCollisions() == false)
+// {
+// setX(oldx);
+// setY(oldy);
+// }
}
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();
+ }
+}