/**************************************************************************
- Ghosts Overboard - a game for Maemo 5
+ Ghosts Overboard - a game 'Meego 1.2 Harmattan'
Copyright (C) 2011 Heli Hyvättinen
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()
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 newy = y() + deltay/15;
//this is for Harmattan
- int newx = x() + deltax/2;
- int newy = y() + deltay/2;
+ int newx = x() + deltax/12;
+ int newy = y() + deltay/12;
// qDebug() << sceneRectangle.left() << sceneRectangle.right();
int finalY = qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height());
+ setPos(QPointF(finalX,finalY));
- QPropertyAnimation * animation = new QPropertyAnimation(this,"pos",this);
- animation->setDuration(100); //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
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();
+ }
+}