• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

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     Q_UNUSED(newState)
00076     Q_UNUSED(oldState)
00077 
00078     QGraphicsWidget *m_object = targetWidget();
00079 
00080     if (!m_object) {
00081         return;
00082     }
00083 
00084     QVector3D vector(0, 0, 0);
00085 
00086     const qreal widgetWidth = m_object->size().width();
00087     const qreal widgetHeight = m_object->size().height();
00088 
00089     if (axis() == Qt::XAxis) {
00090         switch (reference()) {
00091             case Center:
00092                 vector.setX(widgetWidth/2);
00093                 vector.setY(widgetHeight/2);
00094                 break;
00095             case Up:
00096                 vector.setX(widgetWidth/2);
00097                 vector.setY(0);
00098                 break;
00099             case Down:
00100                 vector.setX(widgetWidth/2);
00101                 vector.setY(widgetHeight);
00102                 break;
00103         }
00104 
00105     } else if(axis() == Qt::YAxis) {
00106         switch (reference()) {
00107             case Center:
00108                 vector.setX(widgetWidth/2);
00109                 vector.setY(widgetHeight/2);
00110                 break;
00111             case Left:
00112                 vector.setX(0);
00113                 vector.setY(widgetHeight/2);
00114                 break;
00115             case Right:
00116                 vector.setX(widgetWidth);
00117                 vector.setY(widgetHeight/2);
00118                 break;
00119         }
00120 
00121     } else if (axis() == Qt::ZAxis) {
00122         switch (reference()) {
00123             case Center:
00124                 vector.setX(widgetWidth/2);
00125                 vector.setY(widgetHeight/2);
00126                 break;
00127 
00128             case Center|Up:
00129                 vector.setX(widgetWidth/2);
00130                 vector.setY(0);
00131                 break;
00132 
00133             case Center|Down:
00134                 vector.setX(widgetWidth/2);
00135                 vector.setY(widgetHeight);
00136                 break;
00137 
00138             case Center|Left:
00139                 vector.setX(0);
00140                 vector.setY(widgetHeight/2);
00141                 break;
00142 
00143             case Center|Right:
00144                 vector.setX(widgetWidth);
00145                 vector.setY(widgetHeight/2);
00146                 break;
00147         }
00148     }
00149 
00150     m_rotation->setOrigin(vector);
00151     m_rotation->setAxis(axis());
00152 
00153     QList<QGraphicsTransform *> transformation;
00154     transformation.append(m_rotation);
00155     m_object->setTransformations(transformation);
00156 }
00157 
00158 void RotationAnimation::updateEffectiveTime(int currentTime)
00159 {
00160     if (targetWidget()) {
00161         qreal delta = currentTime * angle() / qreal(duration());
00162         m_rotation->setAngle(delta);
00163     }
00164 }
00165 
00166 }
00167 
00168 #include "rotation_p.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal