Use QElapsedTimer instead of QTime

This commit is contained in:
Luis Ángel San Martín 2021-10-01 19:56:49 +02:00
parent bdb23de74a
commit b83d7150d7
3 changed files with 8 additions and 6 deletions

View File

@ -26,6 +26,8 @@
#include "pictureflow.h" #include "pictureflow.h"
#include <QElapsedTimer>
// detect Qt version // detect Qt version
#if QT_VERSION >= 0x040000 #if QT_VERSION >= 0x040000
#define PICTUREFLOW_QT4 #define PICTUREFLOW_QT4
@ -1281,8 +1283,8 @@ void PictureFlow::resizeEvent(QResizeEvent *event)
#include <QTime> #include <QTime>
void PictureFlow::updateAnimation() // bucle principal void PictureFlow::updateAnimation() // bucle principal
{ {
QTime now; QElapsedTimer timer;
now.start(); timer.start();
bool frameSkiped = false; bool frameSkiped = false;
int old_center = d->state->centerIndex; int old_center = d->state->centerIndex;
@ -1297,7 +1299,7 @@ void PictureFlow::updateAnimation() // bucle principal
if (d->state->centerIndex != old_center) if (d->state->centerIndex != old_center)
emit centerIndexChangedSilent(d->state->centerIndex); emit centerIndexChangedSilent(d->state->centerIndex);
if (d->animator->animating == true) { if (d->animator->animating == true) {
int difference = 10 - now.elapsed(); int difference = 10 - timer.elapsed();
if (difference >= 0 && !frameSkiped) if (difference >= 0 && !frameSkiped)
QTimer::singleShot(difference, this, &PictureFlow::updateAnimation); QTimer::singleShot(difference, this, &PictureFlow::updateAnimation);
else { else {

View File

@ -2,7 +2,7 @@
ScrollManagement::ScrollManagement() ScrollManagement::ScrollManagement()
{ {
wheelTimer = new QTime(); wheelTimer = new QElapsedTimer();
wheelTimer->start(); wheelTimer->start();
wheelAccumulator = 0; wheelAccumulator = 0;
} }

View File

@ -1,7 +1,7 @@
#ifndef SCROLLMANAGAMENT_H #ifndef SCROLLMANAGAMENT_H
#define SCROLLMANAGAMENT_H #define SCROLLMANAGAMENT_H
#include <QTime> #include <QElapsedTimer>
#include <QWheelEvent> #include <QWheelEvent>
class ScrollManagement class ScrollManagement
@ -18,7 +18,7 @@ public:
~ScrollManagement(); ~ScrollManagement();
private: private:
QTime *wheelTimer; QElapsedTimer *wheelTimer;
int wheelAccumulator; int wheelAccumulator;
}; };