• 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
grow.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 "grow_p.h"
21 
22 #include <QRect>
23 #include <kdebug.h>
24 
25 namespace Plasma
26 {
27 
28 GrowAnimation::GrowAnimation(QObject *parent, qreal factor)
29  : EasingAnimation(parent), m_animFactor(factor)
30 {
31 }
32 
33 void GrowAnimation::setFactor(const qreal factor)
34 {
35  m_animFactor = qMax(qreal(0.0), factor);
36 }
37 
38 qreal GrowAnimation::factor() const
39 {
40  return m_animFactor;
41 }
42 
43 void GrowAnimation::updateEffectiveTime(int currentTime)
44 {
45  QGraphicsWidget *w = targetWidget();
46  if (w && state() == QAbstractAnimation::Running) {
47  const qreal delta = currentTime / qreal(duration());
48  QRectF geometry;
49  geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta));
50  geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta));
51  w->setGeometry(geometry);
52  }
53 }
54 
55 void GrowAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
56 {
57  if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) {
58  QGraphicsWidget *widget = targetWidget();
59  if (!widget) {
60  return;
61  }
62 
63  QSizeF minimum = widget->effectiveSizeHint(Qt::MinimumSize);
64  QSizeF maximum = widget->effectiveSizeHint(Qt::MaximumSize);
65  m_startGeometry = widget->geometry();
66  qreal w = m_startGeometry.width();
67  qreal h = m_startGeometry.height();
68  qreal factor = m_animFactor;
69 
70  //compute new geometry values
71  qreal newWidth;
72  qreal newHeight;
73  if (direction() == QAbstractAnimation::Forward) {
74  newWidth = qBound(minimum.width(), w * factor, maximum.width());
75  newHeight = qBound(minimum.height(), h * factor, maximum.height());
76  } else {
77  newWidth = qBound(minimum.width(), w / factor, maximum.width());
78  newHeight = qBound(minimum.height(), h / factor, maximum.height());
79  }
80 
81  qreal newX;
82  qreal newY;
83  newX = m_startGeometry.x() - (newWidth - w)/2;
84  newY = m_startGeometry.y() - (newHeight - h)/2;
85 
86  if (direction() == QAbstractAnimation::Forward) {
87  //the end geometry gets rounded to prevent things looking ugly
88  m_targetGeometry = QRect(newX, newY, newWidth, newHeight);
89  } else {
90  m_targetGeometry = m_startGeometry;
91  m_startGeometry = QRectF(newX, newY, newWidth, newHeight);
92  }
93  }
94 }
95 
96 } //namespace Plasma
97 
98 #include "grow_p.moc"
99 
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