/* Copyright (C) 2009 Igor Trindade Oliveira This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "rotationstacked_p.h" #include #include #include #include #include "stackedlayout.h" #include "plasma.h" namespace Plasma { RotationStackedAnimation::RotationStackedAnimation(QObject *parent) : Animation(parent) { m_backRotation = new QGraphicsRotation(this); m_frontRotation = new QGraphicsRotation(this); m_sLayout = new StackedLayout; } RotationStackedAnimation::~RotationStackedAnimation() { delete m_sLayout; } void RotationStackedAnimation::setMovementDirection(const qint8 &direction) { m_animDirection = static_cast(direction); } qint8 RotationStackedAnimation::movementDirection() const { return static_cast(m_animDirection); } void RotationStackedAnimation::setReference(const qint8 &reference) { m_reference = reference; } qint8 RotationStackedAnimation::reference() const { return m_reference; } QGraphicsWidget *RotationStackedAnimation::backWidget() { return m_backWidget.data(); } void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget) { m_backWidget = backWidget; if(targetWidget()) { m_sLayout->addWidget(targetWidget()); m_sLayout->addWidget(m_backWidget.data()); } } QGraphicsLayoutItem *RotationStackedAnimation::layout() { return m_sLayout; } void RotationStackedAnimation::updateState( QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { if (!backWidget()) { return; } QPair widgets = qMakePair(targetWidget(), backWidget()); const qreal widgetFrontWidth = widgets.first->size().width(); const qreal widgetFrontHeight = widgets.first->size().height(); const qreal widgetBackWidth = widgets.second->size().width(); const qreal widgetBackHeight = widgets.second->size().height(); QPair vector; if (reference() == Center) { vector.first = QVector3D(widgetFrontWidth/2, widgetFrontHeight/2, 0); vector.second = QVector3D(widgetBackWidth/2, widgetBackHeight/2, 0); if (m_animDirection == MoveLeft || m_animDirection == MoveRight) { m_frontRotation->setAxis(Qt::YAxis); m_backRotation->setAxis(Qt::YAxis); if (m_animDirection == MoveLeft) { /* TODO: the order way */ } else { m_frontStartAngle = 0; m_frontEndAngle = 90; m_backStartAngle = 265; //hack m_backEndAngle = 360; } } } m_frontRotation->setOrigin(vector.first); m_backRotation->setOrigin(vector.second); QList backTransformation; QList frontTransformation; frontTransformation.append(m_frontRotation); backTransformation.append(m_backRotation); widgets.first->setTransformations(frontTransformation); widgets.second->setTransformations(backTransformation); if (oldState == Stopped && newState == Running) { m_frontRotation->setAngle(direction() == Forward ? m_frontStartAngle : m_frontEndAngle); m_backRotation->setAngle(direction() == Forward ? m_backStartAngle : m_backEndAngle); } else if(newState == Stopped) { m_frontRotation->setAngle(direction() == Forward ? m_frontEndAngle : m_frontStartAngle); m_backRotation->setAngle(direction() == Forward ? m_backEndAngle : m_backStartAngle); } } void RotationStackedAnimation::updateCurrentTime(int currentTime) { QGraphicsWidget *w = targetWidget(); if(w) { qreal delta; if (currentTime <= duration()/2) { delta = Animation::easingCurve().valueForProgress( (currentTime * 2) / qreal(duration())); m_sLayout->setCurrentWidgetIndex(0); delta = m_frontEndAngle * delta; m_frontRotation->setAngle(delta); } else { delta = Animation::easingCurve().valueForProgress( (currentTime/2) / qreal(duration())); m_sLayout->setCurrentWidgetIndex(1); delta = m_backEndAngle * delta; m_backRotation->setAngle(delta); } } } }