Plasma
rotation.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br> 00003 Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <QGraphicsRotation> 00020 #include <QEasingCurve> 00021 #include <QVector3D> 00022 00023 #include "kdebug.h" 00024 00025 #include "rotation_p.h" 00026 00027 namespace Plasma 00028 { 00029 00030 RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle) 00031 : EasingAnimation(parent), 00032 m_rotation(new QGraphicsRotation(this)), 00033 m_angle(angle), 00034 m_axis(axis), 00035 m_reference(reference) 00036 { 00037 } 00038 00039 RotationAnimation::~RotationAnimation() 00040 { 00041 } 00042 00043 Qt::Axis RotationAnimation::axis() const 00044 { 00045 return m_axis; 00046 } 00047 00048 void RotationAnimation::setAxis(const Qt::Axis &axis) 00049 { 00050 m_axis = axis; 00051 } 00052 00053 qint8 RotationAnimation::reference() const 00054 { 00055 return m_reference; 00056 } 00057 00058 void RotationAnimation::setReference(const qint8 &reference) 00059 { 00060 m_reference = reference; 00061 } 00062 00063 qreal RotationAnimation::angle() const 00064 { 00065 return m_angle; 00066 } 00067 00068 void RotationAnimation::setAngle(const qreal &angle) 00069 { 00070 m_angle = angle; 00071 } 00072 00073 void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) 00074 { 00075 QGraphicsWidget *m_object = targetWidget(); 00076 00077 if (!m_object) { 00078 return; 00079 } 00080 00081 QVector3D vector(0, 0, 0); 00082 00083 const qreal widgetWidth = m_object->size().width(); 00084 const qreal widgetHeight = m_object->size().height(); 00085 00086 if (axis() == Qt::XAxis) { 00087 switch (reference()) { 00088 case Center: 00089 vector.setX(widgetWidth/2); 00090 vector.setY(widgetHeight/2); 00091 break; 00092 case Up: 00093 vector.setX(widgetWidth/2); 00094 vector.setY(0); 00095 break; 00096 case Down: 00097 vector.setX(widgetWidth/2); 00098 vector.setY(widgetHeight); 00099 break; 00100 } 00101 00102 } else if(axis() == Qt::YAxis) { 00103 switch (reference()) { 00104 case Center: 00105 vector.setX(widgetWidth/2); 00106 vector.setY(widgetHeight/2); 00107 break; 00108 case Left: 00109 vector.setX(0); 00110 vector.setY(widgetHeight/2); 00111 break; 00112 case Right: 00113 vector.setX(widgetWidth); 00114 vector.setY(widgetHeight/2); 00115 break; 00116 } 00117 00118 } else if (axis() == Qt::ZAxis) { 00119 switch (reference()) { 00120 case Center: 00121 vector.setX(widgetWidth/2); 00122 vector.setY(widgetHeight/2); 00123 break; 00124 00125 case Center|Up: 00126 vector.setX(widgetWidth/2); 00127 vector.setY(0); 00128 break; 00129 00130 case Center|Down: 00131 vector.setX(widgetWidth/2); 00132 vector.setY(widgetHeight); 00133 break; 00134 00135 case Center|Left: 00136 vector.setX(0); 00137 vector.setY(widgetHeight/2); 00138 break; 00139 00140 case Center|Right: 00141 vector.setX(widgetWidth); 00142 vector.setY(widgetHeight/2); 00143 break; 00144 } 00145 } 00146 00147 m_rotation->setOrigin(vector); 00148 m_rotation->setAxis(axis()); 00149 00150 QList<QGraphicsTransform *> transformation; 00151 transformation.append(m_rotation); 00152 m_object->setTransformations(transformation); 00153 } 00154 00155 void RotationAnimation::updateEffectiveTime(int currentTime) 00156 { 00157 if (targetWidget()) { 00158 qreal delta = currentTime * angle() / qreal(duration()); 00159 m_rotation->setAngle(delta); 00160 } 00161 } 00162 00163 } 00164 00165 #include "rotation_p.moc"
KDE 4.6 API Reference