18 #include "rotationstacked_p.h"
19 #include <QGraphicsRotation>
20 #include <QSequentialAnimationGroup>
21 #include <QWeakPointer>
30 const int RotationStackedAnimation::s_sideAngle = 90;
32 RotationStackedAnimation::RotationStackedAnimation(
QObject *parent)
33 : EasingAnimation(parent)
40 RotationStackedAnimation::~RotationStackedAnimation()
42 delete m_wLayout.data();
45 void RotationStackedAnimation::setMovementDirection(
const Animation::MovementDirection &direction)
47 m_animDirection = direction;
51 if (m_animDirection.testFlag(MoveUp)) {
52 animDirection.setX(1);
53 }
else if (m_animDirection.testFlag(MoveDown)) {
54 animDirection.setX(-1);
57 if (m_animDirection.testFlag(MoveLeft)) {
58 animDirection.setY(-1);
59 }
else if (m_animDirection.testFlag(MoveRight)) {
60 animDirection.setY(1);
63 m_frontRotation->setAxis(animDirection);
64 m_backRotation->setAxis(animDirection);
66 updateTransformations();
69 Animation::MovementDirection RotationStackedAnimation::movementDirection()
const
71 return m_animDirection;
74 void RotationStackedAnimation::setReference(
const Animation::Reference &reference)
76 m_animReference = reference;
78 if (!targetWidget() || !backWidget()) {
82 const QSizeF transformArea = targetWidget()->size().
expandedTo(backWidget()->size());
87 if (m_animReference.testFlag(
Up)) {
88 frontTransformOrigin.
setY(0);
89 backTransformOrigin.setY(0);
90 }
else if (m_animReference.testFlag(
Down)) {
91 frontTransformOrigin.setY(transformArea.
height());
92 backTransformOrigin.setY(transformArea.
height());
95 if (m_animReference.testFlag(
Left)) {
96 frontTransformOrigin.setX(0);
97 backTransformOrigin.setX(0);
98 }
else if (m_animReference.testFlag(
Right)) {
99 frontTransformOrigin.setX(transformArea.
width());
100 backTransformOrigin.setX(transformArea.
width());
103 m_frontRotation->setOrigin(frontTransformOrigin);
104 m_backRotation->setOrigin(backTransformOrigin);
106 updateTransformations();
109 Animation::Reference RotationStackedAnimation::reference()
const
111 return m_animReference;
116 return m_backWidget.
data();
119 void RotationStackedAnimation::setBackWidget(
QGraphicsWidget *backWidget)
121 m_backWidget = backWidget;
125 if(targetWidget() && backWidget && layout) {
133 return m_wLayout.data();
136 void RotationStackedAnimation::updateState(QAbstractAnimation::State newState,
137 QAbstractAnimation::State oldState)
139 if (oldState == Stopped && newState == Running) {
140 setReference(reference());
144 void RotationStackedAnimation::updateEffectiveTime(
int currentTime)
146 if (!targetWidget() || !backWidget()) {
156 if (currentTime <= duration()/2) {
158 delta = (currentTime*2) / qreal(duration());
159 delta *= s_sideAngle;
160 m_frontRotation->setAngle(delta);
163 delta = 1 - (((currentTime*2) - duration()) / qreal(duration()));
165 delta *= s_sideAngle;
166 m_backRotation->setAngle(delta);
170 void RotationStackedAnimation::updateTransformations()
172 if (!targetWidget() || !backWidget()) {
179 frontTransformation.
append(m_frontRotation);
180 backTransformation.
append(m_backRotation);
182 targetWidget()->setTransformations(frontTransformation);
188 #include "rotationstacked_p.moc"
void addWidget(QGraphicsLayoutItem *item)
QSizeF expandedTo(const QSizeF &otherSize) const
void append(const T &value)
void setCurrentWidgetIndex(qint32 index)
QVariant data(int key) const