Skip to content

Commit

Permalink
feat(DTickEffect): change scroll speed
Browse files Browse the repository at this point in the history
Change-Id: I572cd0def6a532467d57c835f31354d0f76a9a1e
  • Loading branch information
haruyukilxz authored and justforlxz committed Nov 9, 2018
1 parent 1539439 commit 2bf9c93
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/widgets/dtickeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -223,6 +225,7 @@ void DTickEffectPrivate::init()
{
runAnimation = new QVariantAnimation;
runAnimation->setLoopCount(-1);
fixPixel = 30;
}

void DTickEffectPrivate::initDirection()
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/dtickeffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/widgets/private/dtickeffect_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DTickEffectPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
public:
DTickEffect::Direction direction;
int duration;
int fixPixel;
QVariantAnimation *runAnimation;
QWidget *content;

Expand Down

0 comments on commit 2bf9c93

Please sign in to comment.