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

Plasma

  • 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
27namespace Plasma
28{
29
30const int RotationStackedAnimation::s_sideAngle = 90;
31
32RotationStackedAnimation::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
40RotationStackedAnimation::~RotationStackedAnimation()
41{
42 delete m_wLayout.data();
43}
44
45void 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
69Animation::MovementDirection RotationStackedAnimation::movementDirection() const
70{
71 return m_animDirection;
72}
73
74void 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
109Animation::Reference RotationStackedAnimation::reference() const
110{
111 return m_animReference;
112}
113
114QGraphicsWidget *RotationStackedAnimation::backWidget()
115{
116 return m_backWidget.data();
117}
118
119void 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
131QGraphicsLayoutItem *RotationStackedAnimation::layout()
132{
133 return m_wLayout.data();
134}
135
136void RotationStackedAnimation::updateState(QAbstractAnimation::State newState,
137 QAbstractAnimation::State oldState)
138{
139 if (oldState == Stopped && newState == Running) {
140 setReference(reference());
141 }
142}
143
144void 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
170void 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"
QGraphicsWidget
QObject
StackedLayout
Definition: stackedlayout.h:28
StackedLayout::addWidget
void addWidget(QGraphicsLayoutItem *item)
Definition: stackedlayout.cpp:84
StackedLayout::setCurrentWidgetIndex
void setCurrentWidgetIndex(qint32 index)
Definition: stackedlayout.cpp:94
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
plasma.h
stackedlayout.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

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