QObject(), QGraphicsPixmapItem(pixmap, parent)
{
setSpeed(speed);
- direction_ = S;
+ changeDirection();
connect(&timer_,SIGNAL(timeout()),this,SLOT(move()));
}
void TimerControlledGraphicsPixmapObject::startMoving()
{
- timer_.start();
+ if (!stoppedBecauseInvalidTime_)
+ timer_.start();
}
void TimerControlledGraphicsPixmapObject::stopMoving()
void TimerControlledGraphicsPixmapObject::setSpeed(int speed)
{
- timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
+ if (speed >0)
+ {
+ timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
+ stoppedBecauseInvalidTime_ = false;
+ }
+ else
+ stoppedBecauseInvalidTime_ = true;
+ timer_.stop();
}
+
void TimerControlledGraphicsPixmapObject::move()
{