Plasma
slide.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Library General Public License as 00006 * published by the Free Software Foundation; either version 2, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details 00013 * 00014 * You should have received a copy of the GNU Library General Public 00015 * License along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "slide_p.h" 00021 00022 #include <QPointF> 00023 #include <kdebug.h> 00024 00025 namespace Plasma 00026 { 00027 00028 void SlideAnimation::setDistance(qreal distance) 00029 { 00030 m_animDistance = QPointF(distance, 0.0); 00031 } 00032 00033 qreal SlideAnimation::distance() const 00034 { 00035 return m_animDistance.x(); 00036 } 00037 00038 void SlideAnimation::setDistancePointF(const QPointF &distance) 00039 { 00040 m_animDistance = distance; 00041 } 00042 00043 QPointF SlideAnimation::distancePointF() const 00044 { 00045 return m_animDistance; 00046 } 00047 00048 SlideAnimation::~SlideAnimation() 00049 { 00050 } 00051 00052 SlideAnimation::SlideAnimation(QObject *parent, 00053 MovementDirection direction, 00054 qreal distance) : EasingAnimation(parent) 00055 { 00056 setMovementDirection(direction); 00057 setDistance(distance); 00058 setEasingCurve(QEasingCurve::OutCirc); 00059 } 00060 00061 void SlideAnimation::setMovementDirection(const Animation::MovementDirection &direction) 00062 { 00063 m_animDirection = direction; 00064 } 00065 00066 Animation::MovementDirection SlideAnimation::movementDirection() const 00067 { 00068 return m_animDirection; 00069 } 00070 00071 void SlideAnimation::updateEffectiveTime(int currentTime) 00072 { 00073 QGraphicsWidget *w = targetWidget(); 00074 if (w && state() == QAbstractAnimation::Running) { 00075 const qreal delta = currentTime / qreal(duration()); 00076 w->setPos(m_startPos * (1-delta) + (m_targetPos * delta)); 00077 } 00078 } 00079 00080 void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) 00081 { 00082 if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) { 00083 if (!targetWidget()) { 00084 return; 00085 } 00086 m_startPos = targetWidget()->pos(); 00087 00088 qreal newX = m_startPos.x(); 00089 qreal newY = m_startPos.y(); 00090 00091 QPointF actualDistance = (direction() == \ 00092 QAbstractAnimation::Forward ? \ 00093 distancePointF():-distancePointF()); 00094 00095 bool moveAnyOnly = true; 00096 00097 if (m_animDirection.testFlag(MoveUp)) { 00098 newY -= actualDistance.x(); 00099 moveAnyOnly = false; 00100 } else if (m_animDirection.testFlag(MoveDown)) { 00101 newY += actualDistance.x(); 00102 moveAnyOnly = false; 00103 } 00104 00105 if (m_animDirection.testFlag(MoveRight)) { 00106 newX += actualDistance.x(); 00107 moveAnyOnly = false; 00108 } else if (m_animDirection.testFlag(MoveLeft)) { 00109 newX -= actualDistance.x(); 00110 moveAnyOnly = false; 00111 } 00112 00113 if (moveAnyOnly && m_animDirection.testFlag(MoveAny)) { 00114 newX += actualDistance.x(); 00115 newY += actualDistance.y(); 00116 } 00117 00118 if (direction() == QAbstractAnimation::Forward) { 00119 m_targetPos = QPointF(newX, newY); 00120 } else { 00121 m_targetPos = m_startPos; 00122 m_startPos = QPointF(newX, newY); 00123 } 00124 } 00125 } 00126 00127 } //namespace Plasma 00128 00129 #include "slide_p.moc"
KDE 4.6 API Reference