• 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
rotationstacked.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "rotationstacked_p.h"
19 #include <QGraphicsRotation>
20 #include <QSequentialAnimationGroup>
21 #include <QWeakPointer>
22 #include <kdebug.h>
23 
24 #include "stackedlayout.h"
25 #include "plasma.h"
26 
27 namespace Plasma
28 {
29 
30 const int RotationStackedAnimation::s_sideAngle = 90;
31 
32 RotationStackedAnimation::RotationStackedAnimation(QObject *parent)
33  : EasingAnimation(parent)
34 {
35  m_backRotation = new QGraphicsRotation(this);
36  m_frontRotation = new QGraphicsRotation(this);
37  m_wLayout = new StackedLayout;
38 }
39 
40 RotationStackedAnimation::~RotationStackedAnimation()
41 {
42  delete m_wLayout.data();
43 }
44 
45 void RotationStackedAnimation::setMovementDirection(const Animation::MovementDirection &direction)
46 {
47  m_animDirection = direction;
48 
49  QVector3D animDirection(0, 0, 0);
50 
51  if (m_animDirection.testFlag(MoveUp)) {
52  animDirection.setX(1);
53  } else if (m_animDirection.testFlag(MoveDown)) {
54  animDirection.setX(-1);
55  }
56 
57  if (m_animDirection.testFlag(MoveLeft)) {
58  animDirection.setY(-1);
59  } else if (m_animDirection.testFlag(MoveRight)) {
60  animDirection.setY(1);
61  }
62 
63  m_frontRotation->setAxis(animDirection);
64  m_backRotation->setAxis(animDirection);
65 
66  updateTransformations();
67 }
68 
69 Animation::MovementDirection RotationStackedAnimation::movementDirection() const
70 {
71  return m_animDirection;
72 }
73 
74 void RotationStackedAnimation::setReference(const Animation::Reference &reference)
75 {
76  m_animReference = reference;
77 
78  if (!targetWidget() || !backWidget()) {
79  return;
80  }
81 
82  const QSizeF transformArea = targetWidget()->size().expandedTo(backWidget()->size());
83 
84  QVector3D frontTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0);
85  QVector3D backTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0);
86 
87  if (m_animReference.testFlag(Up)) {
88  frontTransformOrigin.setY(0);
89  backTransformOrigin.setY(0);
90  } else if (m_animReference.testFlag(Down)) {
91  frontTransformOrigin.setY(transformArea.height());
92  backTransformOrigin.setY(transformArea.height());
93  }
94 
95  if (m_animReference.testFlag(Left)) {
96  frontTransformOrigin.setX(0);
97  backTransformOrigin.setX(0);
98  } else if (m_animReference.testFlag(Right)) {
99  frontTransformOrigin.setX(transformArea.width());
100  backTransformOrigin.setX(transformArea.width());
101  }
102 
103  m_frontRotation->setOrigin(frontTransformOrigin);
104  m_backRotation->setOrigin(backTransformOrigin);
105 
106  updateTransformations();
107 }
108 
109 Animation::Reference RotationStackedAnimation::reference() const
110 {
111  return m_animReference;
112 }
113 
114 QGraphicsWidget *RotationStackedAnimation::backWidget()
115 {
116  return m_backWidget.data();
117 }
118 
119 void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget)
120 {
121  m_backWidget = backWidget;
122 
123  StackedLayout *layout = m_wLayout.data();
124 
125  if(targetWidget() && backWidget && layout) {
126  layout->addWidget(targetWidget());
127  layout->addWidget(backWidget);
128  }
129 }
130 
131 QGraphicsLayoutItem *RotationStackedAnimation::layout()
132 {
133  return m_wLayout.data();
134 }
135 
136 void RotationStackedAnimation::updateState(QAbstractAnimation::State newState,
137  QAbstractAnimation::State oldState)
138 {
139  if (oldState == Stopped && newState == Running) {
140  setReference(reference());
141  }
142 }
143 
144 void RotationStackedAnimation::updateEffectiveTime(int currentTime)
145 {
146  if (!targetWidget() || !backWidget()) {
147  return;
148  }
149 
150  StackedLayout *layout = m_wLayout.data();
151  if (!layout) {
152  return;
153  }
154 
155  qreal delta;
156  if (currentTime <= duration()/2) {
157  layout->setCurrentWidgetIndex(0);
158  delta = (currentTime*2) / qreal(duration());
159  delta *= s_sideAngle;
160  m_frontRotation->setAngle(delta);
161  } else {
162  layout->setCurrentWidgetIndex(1);
163  delta = 1 - (((currentTime*2) - duration()) / qreal(duration()));
164  delta = -delta;
165  delta *= s_sideAngle;
166  m_backRotation->setAngle(delta);
167  }
168 }
169 
170 void RotationStackedAnimation::updateTransformations()
171 {
172  if (!targetWidget() || !backWidget()) {
173  return;
174  }
175 
176  QList<QGraphicsTransform *> frontTransformation;
177  QList<QGraphicsTransform *> backTransformation;
178 
179  frontTransformation.append(m_frontRotation);
180  backTransformation.append(m_backRotation);
181 
182  targetWidget()->setTransformations(frontTransformation);
183  backWidget()->setTransformations(backTransformation);
184 }
185 
186 } //namespace Plasma
187 
188 #include "rotationstacked_p.moc"
Plasma::Up
Display upwards.
Definition: plasma.h:91
StackedLayout::addWidget
void addWidget(QGraphicsLayoutItem *item)
Definition: stackedlayout.cpp:84
StackedLayout
Definition: stackedlayout.h:27
QObject
stackedlayout.h
plasma.h
StackedLayout::setCurrentWidgetIndex
void setCurrentWidgetIndex(qint32 index)
Definition: stackedlayout.cpp:94
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