28 void SlideAnimation::setDistance(qreal distance)
30 m_animDistance = QPointF(distance, 0.0);
33 qreal SlideAnimation::distance()
const
35 return m_animDistance.x();
38 void SlideAnimation::setDistancePointF(
const QPointF &distance)
40 m_animDistance = distance;
43 QPointF SlideAnimation::distancePointF()
const
45 return m_animDistance;
48 SlideAnimation::~SlideAnimation()
52 SlideAnimation::SlideAnimation(
QObject *parent,
53 MovementDirection direction,
54 qreal distance) : EasingAnimation(parent)
56 setMovementDirection(direction);
57 setDistance(distance);
58 setEasingCurve(QEasingCurve::OutCirc);
61 void SlideAnimation::setMovementDirection(
const Animation::MovementDirection &direction)
63 m_animDirection = direction;
66 Animation::MovementDirection SlideAnimation::movementDirection()
const
68 return m_animDirection;
71 void SlideAnimation::updateEffectiveTime(
int currentTime)
74 if (w && state() == QAbstractAnimation::Running) {
75 const qreal delta = currentTime / qreal(duration());
76 w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
80 void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
82 if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
83 if (!targetWidget()) {
86 m_startPos = targetWidget()->pos();
88 qreal newX = m_startPos.x();
89 qreal newY = m_startPos.y();
91 QPointF actualDistance = (direction() == \
92 QAbstractAnimation::Forward ? \
93 distancePointF():-distancePointF());
95 bool moveAnyOnly =
true;
97 if (m_animDirection.testFlag(MoveUp)) {
98 newY -= actualDistance.x();
100 }
else if (m_animDirection.testFlag(MoveDown)) {
101 newY += actualDistance.x();
105 if (m_animDirection.testFlag(MoveRight)) {
106 newX += actualDistance.x();
108 }
else if (m_animDirection.testFlag(MoveLeft)) {
109 newX -= actualDistance.x();
113 if (moveAnyOnly && m_animDirection.testFlag(MoveAny)) {
114 newX += actualDistance.x();
115 newY += actualDistance.y();
118 if (direction() == QAbstractAnimation::Forward) {
119 m_targetPos = QPointF(newX, newY);
121 m_targetPos = m_startPos;
122 m_startPos = QPointF(newX, newY);
129 #include "slide_p.moc"