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

Plasma

  • sources
  • kde-4.12
  • kdelibs
  • plasma
  • animations
rotation.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
3  Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include <QGraphicsRotation>
20 #include <QEasingCurve>
21 #include <QVector3D>
22 
23 #include "kdebug.h"
24 
25 #include "rotation_p.h"
26 
27 namespace Plasma
28 {
29 
30 RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle)
31  : EasingAnimation(parent),
32  m_rotation(new QGraphicsRotation(this)),
33  m_angle(angle),
34  m_axis(axis),
35  m_reference(reference)
36 {
37 }
38 
39 RotationAnimation::~RotationAnimation()
40 {
41 }
42 
43 Qt::Axis RotationAnimation::axis() const
44 {
45  return m_axis;
46 }
47 
48 void RotationAnimation::setAxis(const Qt::Axis &axis)
49 {
50  m_axis = axis;
51 }
52 
53 qint8 RotationAnimation::reference() const
54 {
55  return m_reference;
56 }
57 
58 void RotationAnimation::setReference(const qint8 &reference)
59 {
60  m_reference = reference;
61 }
62 
63 qreal RotationAnimation::angle() const
64 {
65  return m_angle;
66 }
67 
68 void RotationAnimation::setAngle(const qreal &angle)
69 {
70  m_angle = angle;
71 }
72 
73 void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
74 {
75  Q_UNUSED(newState)
76  Q_UNUSED(oldState)
77 
78  QGraphicsWidget *m_object = targetWidget();
79 
80  if (!m_object) {
81  return;
82  }
83 
84  QVector3D vector(0, 0, 0);
85 
86  const qreal widgetWidth = m_object->size().width();
87  const qreal widgetHeight = m_object->size().height();
88 
89  if (axis() == Qt::XAxis) {
90  switch (reference()) {
91  case Center:
92  vector.setX(widgetWidth/2);
93  vector.setY(widgetHeight/2);
94  break;
95  case Up:
96  vector.setX(widgetWidth/2);
97  vector.setY(0);
98  break;
99  case Down:
100  vector.setX(widgetWidth/2);
101  vector.setY(widgetHeight);
102  break;
103  }
104 
105  } else if(axis() == Qt::YAxis) {
106  switch (reference()) {
107  case Center:
108  vector.setX(widgetWidth/2);
109  vector.setY(widgetHeight/2);
110  break;
111  case Left:
112  vector.setX(0);
113  vector.setY(widgetHeight/2);
114  break;
115  case Right:
116  vector.setX(widgetWidth);
117  vector.setY(widgetHeight/2);
118  break;
119  }
120 
121  } else if (axis() == Qt::ZAxis) {
122  switch (reference()) {
123  case Center:
124  vector.setX(widgetWidth/2);
125  vector.setY(widgetHeight/2);
126  break;
127 
128  case Center|Up:
129  vector.setX(widgetWidth/2);
130  vector.setY(0);
131  break;
132 
133  case Center|Down:
134  vector.setX(widgetWidth/2);
135  vector.setY(widgetHeight);
136  break;
137 
138  case Center|Left:
139  vector.setX(0);
140  vector.setY(widgetHeight/2);
141  break;
142 
143  case Center|Right:
144  vector.setX(widgetWidth);
145  vector.setY(widgetHeight/2);
146  break;
147  }
148  }
149 
150  m_rotation->setOrigin(vector);
151  m_rotation->setAxis(axis());
152 
153  QList<QGraphicsTransform *> transformation;
154  transformation.append(m_rotation);
155  m_object->setTransformations(transformation);
156 }
157 
158 void RotationAnimation::updateEffectiveTime(int currentTime)
159 {
160  if (targetWidget()) {
161  qreal delta = currentTime * angle() / qreal(duration());
162  m_rotation->setAngle(delta);
163  }
164 }
165 
166 }
167 
168 #include "rotation_p.moc"
Plasma::Up
Display upwards.
Definition: plasma.h:91
QObject
Plasma::Down
Display downards.
Definition: plasma.h:90
Plasma::Right
Display to the right.
Definition: plasma.h:93
Plasma::Left
Display to the left.
Definition: plasma.h:92
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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 API Reference

Skip menu "kdelibs API Reference"
  • 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal