SlideAnimation: add a new movement direction movement any, it is useful when the user just know where is the finish position of widget like tabbar slide animation

svn path=/trunk/KDE/kdelibs/; revision=1078733
This commit is contained in:
Igor Trindade Oliveira 2010-01-22 18:55:37 +00:00
parent 2d2dc8a37a
commit d42e7f8b7b
3 changed files with 38 additions and 16 deletions

View File

@ -82,7 +82,8 @@ public:
MoveDown, /**< Move down */ MoveDown, /**< Move down */
MoveDownLeft, /**< Move down and left */ MoveDownLeft, /**< Move down and left */
MoveLeft, /**< Move left */ MoveLeft, /**< Move left */
MoveUpLeft /**< Move up and left */ MoveUpLeft, /**< Move up and left */
MoveAny /**< Move in any direction*/
}; };

View File

@ -27,10 +27,20 @@ namespace Plasma
void SlideAnimation::setDistance(qreal distance) void SlideAnimation::setDistance(qreal distance)
{ {
m_animDistance = distance; m_animDistance = QPointF(distance, 0.0);
} }
qreal SlideAnimation::distance() const qreal SlideAnimation::distance() const
{
return m_animDistance.x();
}
void SlideAnimation::setDistancePointF(const QPointF &distance)
{
m_animDistance = distance;
}
QPointF SlideAnimation::distancePointF() const
{ {
return m_animDistance; return m_animDistance;
} }
@ -79,43 +89,50 @@ void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAn
qreal newX = m_startPos.x(); qreal newX = m_startPos.x();
qreal newY = m_startPos.y(); qreal newY = m_startPos.y();
int actualDistance = (direction() == QAbstractAnimation::Forward?distance():-distance()); QPointF actualDistance = (direction() == \
QAbstractAnimation::Forward ? \
distancePointF():-distancePointF());
switch (movementDirection()) { switch (movementDirection()) {
case MoveUp: case MoveUp:
newY -= actualDistance; newY -= actualDistance.x();
break; break;
case MoveRight: case MoveRight:
newX += actualDistance; newX += actualDistance.x();
break; break;
case MoveDown: case MoveDown:
newY += actualDistance; newY += actualDistance.x();
break; break;
case MoveLeft: case MoveLeft:
newX -= actualDistance; newX -= actualDistance.x();
break; break;
case MoveUpRight: case MoveUpRight:
newX += actualDistance; newX += actualDistance.x();
newY -= actualDistance; newY -= actualDistance.y();
break; break;
case MoveDownRight: case MoveDownRight:
newX += actualDistance; newX += actualDistance.x();
newY += actualDistance; newY += actualDistance.y();
break; break;
case MoveDownLeft: case MoveDownLeft:
newX -= actualDistance; newX -= actualDistance.x();
newY += actualDistance; newY += actualDistance.y();
break; break;
case MoveUpLeft: case MoveUpLeft:
newX -= actualDistance; newX -= actualDistance.x();
newY -= actualDistance; newY -= actualDistance.y();
break;
case MoveAny:
newX = actualDistance.x();
newY = actualDistance.y();
break; break;
default: default:

View File

@ -44,6 +44,7 @@ class SlideAnimation : public Animation
Q_OBJECT Q_OBJECT
Q_PROPERTY(qint8 movementDirection READ movementDirection WRITE setMovementDirection) Q_PROPERTY(qint8 movementDirection READ movementDirection WRITE setMovementDirection)
Q_PROPERTY(qreal distance READ distance WRITE setDistance) Q_PROPERTY(qreal distance READ distance WRITE setDistance)
Q_PROPERTY(QPointF distancePointF READ distancePointF WRITE setDistancePointF)
public: public:
explicit SlideAnimation(QObject *parent = 0, MovementDirection direction = MoveUp, qreal distance = 0); explicit SlideAnimation(QObject *parent = 0, MovementDirection direction = MoveUp, qreal distance = 0);
@ -60,6 +61,9 @@ public:
*/ */
qreal distance() const; qreal distance() const;
void setDistancePointF(const QPointF &distance);
QPointF distancePointF() const;
/** /**
* Set the animation direction * Set the animation direction
* @arg direction animation direction * @arg direction animation direction
@ -85,7 +89,7 @@ private:
* Animation distance: displacement factor for animations where * Animation distance: displacement factor for animations where
* there is change in the position of animated widget. * there is change in the position of animated widget.
*/ */
qreal m_animDistance; QPointF m_animDistance;
QPointF m_startPos; QPointF m_startPos;
QPointF m_targetPos; QPointF m_targetPos;
}; };