Plasma
geometry.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br> 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 "geometry_p.h" 00021 00022 #include <QRect> 00023 00024 #include <kdebug.h> 00025 00026 namespace Plasma 00027 { 00028 00029 GeometryAnimation::GeometryAnimation(QObject *parent) 00030 : EasingAnimation(parent), 00031 m_startGeometry(-1, -1, -1, -1) 00032 { 00033 } 00034 00035 GeometryAnimation::~GeometryAnimation() 00036 { 00037 } 00038 00039 void GeometryAnimation::setStartGeometry(const QRectF &geometry) 00040 { 00041 m_startGeometry = geometry; 00042 } 00043 00044 QRectF GeometryAnimation::startGeometry() const 00045 { 00046 return m_startGeometry; 00047 } 00048 00049 void GeometryAnimation::setTargetGeometry(const QRectF &geometry) 00050 { 00051 m_targetGeometry = geometry; 00052 } 00053 00054 QRectF GeometryAnimation::targetGeometry() const 00055 { 00056 return m_targetGeometry; 00057 } 00058 00059 void GeometryAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) 00060 { 00061 QGraphicsWidget *w = targetWidget(); 00062 if (!w) { 00063 return; 00064 } 00065 00066 if (m_startGeometry == QRectF(-1, -1, -1, -1)) { 00067 m_startGeometry = w->geometry(); 00068 } 00069 00070 if (oldState == Stopped && newState == Running) { 00071 w->setGeometry(direction() == Forward ? m_startGeometry : m_targetGeometry); 00072 } else if (newState == Stopped) { 00073 w->setGeometry(direction() == Forward ? m_targetGeometry : m_startGeometry); 00074 } 00075 } 00076 00077 void GeometryAnimation::updateEffectiveTime(int currentTime) 00078 { 00079 QGraphicsWidget *w = targetWidget(); 00080 if (w) { 00081 const qreal delta = currentTime / qreal(duration()); 00082 00083 QRectF newGeo; 00084 00085 newGeo.moveTopLeft(QPointF(m_startGeometry.left()*(1-delta) + m_targetGeometry.left()*(delta), 00086 m_startGeometry.top()*(1-delta) + m_targetGeometry.top()*(delta))); 00087 if (m_startGeometry.size() != m_targetGeometry.size()) { 00088 newGeo.setSize(QSizeF(m_startGeometry.width()*(1-delta) + m_targetGeometry.width()*(delta), 00089 m_startGeometry.height()*(1-delta) + m_targetGeometry.height()*(delta))); 00090 } else { 00091 newGeo.setSize(m_targetGeometry.size()); 00092 } 00093 w->setGeometry(newGeo); 00094 } 00095 } 00096 00097 } //namespace Plasma 00098 00099 #include "geometry_p.moc"
KDE 4.6 API Reference