diff --git a/src/widgets/dtickeffect.cpp b/src/widgets/dtickeffect.cpp index b44822a2f..e2b1ee14a 100644 --- a/src/widgets/dtickeffect.cpp +++ b/src/widgets/dtickeffect.cpp @@ -66,8 +66,6 @@ DTickEffect::DTickEffect(QWidget *widget, QWidget *parent) d->init(); setDirection(DTickEffect::LeftToRight); - setDuration(1000); - connect(d->runAnimation, &QVariantAnimation::valueChanged, this, &DTickEffect::update); connect(d->runAnimation, &QVariantAnimation::finished, this, &DTickEffect::finished); } @@ -198,15 +196,19 @@ void DTickEffect::setDirection(DTickEffect::Direction direction) * @param duration */ void DTickEffect::setDuration(const int duration) +{ + Q_UNUSED(duration); +} + +void DTickEffect::setFixedPixelMove(const int pixel) { D_D(DTickEffect); - if (d->duration == duration) - return; + if (d->fixPixel == pixel) return; - d->duration = duration; + d->fixPixel = pixel; - d->runAnimation->setDuration(duration); + d->initDirection(); } DTickEffectPrivate::DTickEffectPrivate(DTickEffect *qq) @@ -223,6 +225,7 @@ void DTickEffectPrivate::init() { runAnimation = new QVariantAnimation; runAnimation->setLoopCount(-1); + fixPixel = 30; } void DTickEffectPrivate::initDirection() @@ -231,18 +234,22 @@ void DTickEffectPrivate::initDirection() case DTickEffect::LeftToRight: runAnimation->setStartValue(QPoint(content->x(), content->y())); runAnimation->setEndValue(QPoint(content->width(), content->y())); + runAnimation->setDuration((content->width() / fixPixel) * 1000); break; case DTickEffect::RightToLeft: runAnimation->setStartValue(QPoint(content->x(), content->y())); runAnimation->setEndValue(QPoint(-content->width(), content->y())); + runAnimation->setDuration((content->width() / fixPixel) * 1000); break; case DTickEffect::TopToBottom: runAnimation->setStartValue(QPoint(content->x(), content->y())); runAnimation->setEndValue(QPoint(content->x(), content->height())); + runAnimation->setDuration((content->height() / fixPixel) * 1000); break; case DTickEffect::BottomToTop: runAnimation->setStartValue(QPoint(content->x(), content->y())); runAnimation->setEndValue(QPoint(content->x(), -content->height())); + runAnimation->setDuration((content->height() / fixPixel) * 1000); break; default: break; diff --git a/src/widgets/dtickeffect.h b/src/widgets/dtickeffect.h index 5385972ab..13ac917d9 100644 --- a/src/widgets/dtickeffect.h +++ b/src/widgets/dtickeffect.h @@ -45,7 +45,8 @@ class LIBDTKWIDGETSHARED_EXPORT DTickEffect : public QGraphicsEffect, public DTK void resume(); void setDirection(Direction direction); - void setDuration(const int duration); + void setDuration(const int duration) D_DECL_DEPRECATED; + void setFixedPixelMove(const int pixel); Q_SIGNALS: void finished(); diff --git a/src/widgets/private/dtickeffect_p.h b/src/widgets/private/dtickeffect_p.h index 88253b077..7508c0f69 100644 --- a/src/widgets/private/dtickeffect_p.h +++ b/src/widgets/private/dtickeffect_p.h @@ -37,6 +37,7 @@ class DTickEffectPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate public: DTickEffect::Direction direction; int duration; + int fixPixel; QVariantAnimation *runAnimation; QWidget *content;