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

Plasma

  • plasma
  • animations
slide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "slide_p.h"
21
22#include <QPointF>
23#include <kdebug.h>
24
25namespace Plasma
26{
27
28void SlideAnimation::setDistance(qreal distance)
29{
30 m_animDistance = QPointF(distance, 0.0);
31}
32
33qreal SlideAnimation::distance() const
34{
35 return m_animDistance.x();
36}
37
38void SlideAnimation::setDistancePointF(const QPointF &distance)
39{
40 m_animDistance = distance;
41}
42
43QPointF SlideAnimation::distancePointF() const
44{
45 return m_animDistance;
46}
47
48SlideAnimation::~SlideAnimation()
49{
50}
51
52SlideAnimation::SlideAnimation(QObject *parent,
53 MovementDirection direction,
54 qreal distance) : EasingAnimation(parent)
55{
56 setMovementDirection(direction);
57 setDistance(distance);
58 setEasingCurve(QEasingCurve::OutCirc);
59}
60
61void SlideAnimation::setMovementDirection(const Animation::MovementDirection &direction)
62{
63 m_animDirection = direction;
64}
65
66Animation::MovementDirection SlideAnimation::movementDirection() const
67{
68 return m_animDirection;
69}
70
71void SlideAnimation::updateEffectiveTime(int currentTime)
72{
73 QGraphicsWidget *w = targetWidget();
74 if (w && state() == QAbstractAnimation::Running) {
75 const qreal delta = currentTime / qreal(duration());
76 w->setPos(m_startPos * (1-delta) + (m_targetPos * delta));
77 }
78}
79
80void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
81{
82 if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
83 if (!targetWidget()) {
84 return;
85 }
86 m_startPos = targetWidget()->pos();
87
88 qreal newX = m_startPos.x();
89 qreal newY = m_startPos.y();
90
91 QPointF actualDistance = (direction() == \
92 QAbstractAnimation::Forward ? \
93 distancePointF():-distancePointF());
94
95 bool moveAnyOnly = true;
96
97 if (m_animDirection.testFlag(MoveUp)) {
98 newY -= actualDistance.x();
99 moveAnyOnly = false;
100 } else if (m_animDirection.testFlag(MoveDown)) {
101 newY += actualDistance.x();
102 moveAnyOnly = false;
103 }
104
105 if (m_animDirection.testFlag(MoveRight)) {
106 newX += actualDistance.x();
107 moveAnyOnly = false;
108 } else if (m_animDirection.testFlag(MoveLeft)) {
109 newX -= actualDistance.x();
110 moveAnyOnly = false;
111 }
112
113 if (moveAnyOnly && m_animDirection.testFlag(MoveAny)) {
114 newX += actualDistance.x();
115 newY += actualDistance.y();
116 }
117
118 if (direction() == QAbstractAnimation::Forward) {
119 m_targetPos = QPointF(newX, newY);
120 } else {
121 m_targetPos = m_startPos;
122 m_startPos = QPointF(newX, newY);
123 }
124 }
125}
126
127} //namespace Plasma
128
129#include "slide_p.moc"
QGraphicsWidget
QObject
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
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