Port two examples from QTime to QElapsedTimer

Change-Id: I23d13bf1e909801797a8fc2785c46f341ef5ee77
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
This commit is contained in:
Albert Astals Cid 2019-09-27 16:11:50 +02:00
parent e24c387413
commit d12bf4eb83
2 changed files with 9 additions and 9 deletions

View File

@ -98,7 +98,7 @@ public:
QPoint delta;
QPoint speed;
FlickableTicker *ticker;
QTime timeStamp;
QElapsedTimer timeStamp;
QWidget *target;
QList<QEvent*> ignoreList;
};
@ -109,7 +109,7 @@ Flickable::Flickable()
d->state = FlickablePrivate::Steady;
d->threshold = 10;
d->ticker = new FlickableTicker(this);
d->timeStamp = QTime::currentTime();
d->timeStamp.start();
d->target = 0;
}
@ -208,7 +208,7 @@ void Flickable::handleMouseRelease(QMouseEvent *event)
event->accept();
delta = event->pos() - d->pressPos;
if (d->timeStamp.elapsed() > 100) {
d->timeStamp = QTime::currentTime();
d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}
@ -253,7 +253,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
if (delta.x() > d->threshold || delta.x() < -d->threshold ||
delta.y() > d->threshold || delta.y() < -d->threshold) {
d->timeStamp = QTime::currentTime();
d->timeStamp.start();
d->state = FlickablePrivate::ManualScroll;
d->delta = QPoint(0, 0);
d->pressPos = event->pos();
@ -266,7 +266,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
setScrollOffset(d->offset - delta);
if (d->timeStamp.elapsed() > 100) {
d->timeStamp = QTime::currentTime();
d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}

View File

@ -92,7 +92,7 @@ public:
}
void updatePlayer() {
int interval = qBound(20, watch.elapsed(), 250);
int interval = qBound(20ll, watch.elapsed(), 250ll);
watch.start();
angle += angleDelta * interval / 1000;
qreal step = moveDelta * interval / 1000;
@ -106,10 +106,10 @@ public:
}
void showFps() {
static QTime frameTick;
static QElapsedTimer frameTick;
static int totalFrame = 0;
if (!(totalFrame & 31)) {
int elapsed = frameTick.elapsed();
const qint64 elapsed = frameTick.elapsed();
frameTick.start();
int fps = 32 * 1000 / (1 + elapsed);
setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps));
@ -355,7 +355,7 @@ protected:
}
private:
QTime watch;
QElapsedTimer watch;
QBasicTimer ticker;
QImage buffer;
qreal angle;