• 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
pulser.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2009 Adenilson Cavalcanti <cavalcantii@gmail.com>
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Library General Public License as
5  * published by the Free Software Foundation; either version 2, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 #include "widgetsnapshot_p.h"
19 #include "pulser_p.h"
20 
21 #include <QEvent>
22 #include <QGraphicsWidget>
23 #include <QParallelAnimationGroup>
24 #include <QPropertyAnimation>
25 #include <QWeakPointer>
26 
27 #include <kdebug.h>
28 
29 namespace Plasma
30 {
31 
32 PulseAnimation::PulseAnimation(QObject *parent)
33  : EasingAnimation(parent),
34  m_zvalue(0),
35  m_scale(0),
36  m_opacity(0),
37  m_endScale(1.5)
38 {
39 }
40 
41 PulseAnimation::~PulseAnimation()
42 {
43  delete m_under.data();
44 }
45 
46 void PulseAnimation::setTargetScale(qreal scale)
47 {
48  m_endScale = scale;
49 }
50 
51 qreal PulseAnimation::targetScale() const
52 {
53  return m_endScale;
54 }
55 
56 void PulseAnimation::setCopy()
57 {
58  QGraphicsWidget *target = targetWidget();
59 
60  if (!target) {
61  m_under.clear();
62  return;
63  }
64 
65  if (!m_under.data()) {
66  m_under = new WidgetSnapShot;
67  }
68 
69  m_under.data()->setTarget(target);
70 
71  m_zvalue = target->zValue() - 1;
72  m_scale = target->scale();
73 
74  m_under.data()->setOpacity(m_opacity);
75  m_under.data()->setScale(m_scale);
76  m_under.data()->setZValue(m_zvalue);
77 }
78 
79 void PulseAnimation::resetPulser()
80 {
81  if (m_under.data()) {
82  m_under.data()->setOpacity(m_opacity);
83  m_under.data()->setScale(m_scale);
84  m_under.data()->setZValue(m_zvalue);
85  m_under.data()->hide();
86  }
87 }
88 
89 void PulseAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
90 {
91  if (!targetWidget()) {
92  return;
93  }
94 
95  if (oldState == Stopped && newState == Running) {
96  if (!m_under.data() || m_under.data()->target() != targetWidget() || m_under.data()->size() != targetWidget()->size()) {
97  setCopy();
98  }
99 
100  if (m_under.data()->isIconBigger()) {
101  m_under.data()->setScale(0);
102  m_endScale = 1.0;
103 
104  } else {
105  m_scale = 0;
106  m_endScale = 1.5;
107  }
108 
109  if (m_under.data()->isVisible() == false) {
110  m_under.data()->setVisible(true);
111  }
112 
113  m_under.data()->setOpacity(direction() == Forward ? 1 : 0);
114  m_under.data()->setScale(direction() == Forward ? m_scale : m_endScale);
115  } else if (newState == Stopped) {
116  resetPulser();
117  }
118 }
119 
120 void PulseAnimation::updateEffectiveTime(int currentTime)
121 {
122  if (m_under.data()) {
123  qreal delta = currentTime / qreal(duration());
124 
125  if (m_under.data()->isIconBigger()) {
126  m_under.data()->setScale(delta);
127  } else {
128  m_under.data()->setScale(delta);
129  delta = (1 - m_endScale) * delta;
130  m_under.data()->setScale(1 - delta);
131  }
132 
133  delta = currentTime / qreal(duration());
134  if (direction() == Forward) {
135  m_under.data()->setOpacity(1.0 - delta);
136  } else if (direction() == Backward) {
137  m_under.data()->setOpacity(delta);
138  }
139  }
140 }
141 
142 } //namespace Plasma
143 
144 #include "pulser_p.moc"
QObject
QGraphicsWidget
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:33 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