1. flupp
  2. Smooth Tasks Fork

Commits

flupp  committed e2d40e1

using QPropertyAnimation for light animation now: fixes Plasma::Animator-related deprecation warning; attention animation limited to 3 animation cycles to save cpu cycles

  • Participants
  • Parent commits 4ff0562
  • Branches kde-4.8

Comments (0)

Files changed (3)

File applet/SmoothTasks/Light.cpp

View file
  • Ignore whitespace
 * Smooth Tasks
 * Copyright (C) 2009 Marcin Baszczewski <marcin.baszczewski@gmail.com>
 *                    Mathias panzenböck <grosser.meister.morti@gmx.net>
-* Copyright (C) 2009-2010 Toni Dietze <smooth-tasks@derflupp.e4ward.com>
+* Copyright (C) 2009-2012 Toni Dietze <smooth-tasks@derflupp.e4ward.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 #include "SmoothTasks/TaskIcon.h"
 
 // Qt
-#include <QTimer>
 #include <QPainter>
+#include <QPropertyAnimation>>
+#include <QSequentialAnimationGroup>
 #include <QStyleOptionGraphicsItem>
 
 // Plasma
 
 namespace SmoothTasks {
 
-Light::Light(TaskItem *item) : QObject(item),
-	m_item(item),
-	m_count(0),
-	m_currentAnimationDuration(0),
-	m_animation(0),
-	m_progress(0.0),
-	m_move(true),
-	m_currentAnimation(NoAnimation),
-	m_animationRepeater(new QTimer()),
-	m_repeater(true) {
-}
-
-Light::~Light() {
-	if (m_animation) {
-		Plasma::Animator::self()->stopCustomAnimation(m_animation);
-	}
-	m_animationRepeater->deleteLater();
-}
+Light::Light(TaskItem *item)
+	: QObject(item)
+	, m_item(item)
+	, m_size(1.0)
+	, m_animation(0)
+	, m_currentAnimation(NoAnimation)
+{}
 
 void Light::paint(QPainter *p, const QRectF& boundingRect, const QPointF& mousePos, bool mouseIn, const bool isRotated) {
-	if (!mouseIn && !m_animation) {
+	if (!mouseIn && m_currentAnimation == NoAnimation) {
 		return;
 	}
 
-	qreal  size = 1.0;
 	qreal  cx = 0.5;
 	qreal  cy = 0.5;
 	QColor lightColor(m_item->icon()->highlightColor());
 
-	switch (m_currentAnimation) {
-	case StartupAnimation:
-	case AttentionAnimation:
-		size *= m_progress < 0.5 ? (m_progress * 0.5 + 0.5) : (1 - m_progress / 2);
-		break;
-	case NoAnimation:
+	if (mouseIn) {
 		if (isRotated) {
 			cx = 1 - (mousePos.y() - boundingRect.left()) / boundingRect.width();
 			cy =     (mousePos.x() - boundingRect.top() ) / boundingRect.height();
 			cx = (mousePos.x() - boundingRect.left()) / boundingRect.width();
 			cy = (mousePos.y() - boundingRect.top() ) / boundingRect.height();
 		}
-		break;
-	default:
-		return;
 	}
 	
 	const LightAnchorConfig& anchorConfig = m_item->applet()->lightAnchorConfig();
 		cx = 0.01 * (qreal) anchorConfig.anchorHorizontal();
 	if (anchorConfig.isAnchoredVertically())
 		cy = 0.01 * (qreal) (100 - anchorConfig.anchorVertical());
-	
-	QRadialGradient gradient(cx, cy, size);
+
+	QRadialGradient gradient(cx, cy, m_size);
 	gradient.setCoordinateMode(QRadialGradient::ObjectBoundingMode);
 	
 	lightColor.setAlpha(200);
 	p->fillRect(boundingRect, gradient);
 }
 
-void Light::startAnimation(AnimationType animation, int duration, bool repeater) {
-	m_count = 0;
-	m_currentAnimationDuration = duration;
+void Light::startAnimation(AnimationType animation, int duration, int loopCout) {
+	delete m_animation;
+
+	QPropertyAnimation* start = new QPropertyAnimation(this, "size", this);
+	start->setEasingCurve(QEasingCurve::InOutSine);
+	start->setDuration(0.5 * duration);
+	start->setStartValue(0.00001);  // QRadialGradient does not like a radius of 0
+	start->setEndValue(1.0);
+
+	QPropertyAnimation* down = new QPropertyAnimation(this, "size", this);
+	down->setEasingCurve(QEasingCurve::InOutSine);
+	down->setDuration(0.5 * duration);
+	down->setStartValue(1.0);
+	down->setEndValue(0.5);
+
+	QPropertyAnimation* up = new QPropertyAnimation(this, "size", this);
+	up->setEasingCurve(QEasingCurve::InOutSine);
+	up->setDuration(0.5 * duration);
+	up->setStartValue(0.5);
+	up->setEndValue(1.0);
+
+	QSequentialAnimationGroup* loop = new QSequentialAnimationGroup(this);
+	loop->addAnimation(down);
+	loop->addAnimation(up);
+	loop->setLoopCount(loopCout);
+
+	QSequentialAnimationGroup* all = new QSequentialAnimationGroup(this);
+	all->addAnimation(start);
+	all->addAnimation(loop);
+
+	m_animation = all;
+	m_animation->start(QAbstractAnimation::DeleteWhenStopped);
 	m_currentAnimation = animation;
-
-	m_animationRepeater->setInterval(duration);
-	m_animationRepeater->start();
-
-	repeatAnimation();
-
-	m_repeater = repeater;
-	connect(m_animationRepeater, SIGNAL(timeout()), this, SLOT(repeatAnimation()));
 }
 
 void Light::stopAnimation() {
-	m_animationRepeater->stop();
+	delete m_animation;
+	m_animation = 0;
 	m_currentAnimation = NoAnimation;
-	Plasma::Animator::self()->stopCustomAnimation(m_animation);
-	m_animation = 0;
+	setSize(1.0);
 }
 
-void Light::repeatAnimation() {
-	if (!m_repeater && m_count != 0) {
-		return;
-	}
-
-	if (m_animation) {
-		Plasma::Animator::self()->stopCustomAnimation(m_animation);
-		m_animation = 0;
-	}
-	int frames = m_item->applet()->fps() * m_currentAnimationDuration / 1000;
-
-	if (frames <= 0) {
-		animation(1.0);
-	}
-	else {
-		m_animation = Plasma::Animator::self()->customAnimation(
-			frames, m_currentAnimationDuration,
-			Plasma::Animator::LinearCurve,
-			this, "animation");
-	}
-	++ m_count;
+qreal Light::size() {
+	return m_size;
 }
 
-void Light::animation(qreal progress) {
-	m_progress = progress;
+void Light::setSize(qreal size) {
+	m_size = size;
 	emit update();
 }
 

File applet/SmoothTasks/Light.h

View file
  • Ignore whitespace
 /***********************************************************************************
 * Smooth Tasks
 * Copyright (C) 2009 Marcin Baszczewski <marcin.baszczewski@gmail.com>
+* Copyright (C) 2009-2012 Toni Dietze <smooth-tasks@derflupp.e4ward.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 #include <QObject>
 #include <QPixmap>
 #include <QIcon>
+#include <QPointer>
 
+class QAbstractAnimation;
 class QRadialGradient;
-class QTimer;
 class QStyleOptionGraphicsItem;
 
 namespace SmoothTasks {
 
 class Light : public QObject {
 	Q_OBJECT
+	Q_PROPERTY(qreal size READ size WRITE setSize)
 
 public:
 	enum AnimationType {
 	};
 
 	Light(TaskItem *item);
-	~Light();
 
 	void paint(QPainter *p, const QRectF& geometry, const QPointF& mousePos, bool mouseIn, const bool isRotated);
 
 public slots:
-	void startAnimation(AnimationType animation, int duration = 300, bool repeater = true);
+	void startAnimation(AnimationType animation, int duration = 300, int loopCout = -1);
 	void stopAnimation();
-	void repeatAnimation();
-
-private slots:
-	void animation(qreal progress);
 
 private:
+	qreal size();
+	void setSize(qreal size);
+
 	TaskItem     *m_item;
-	int           m_count;
-	int           m_currentAnimationDuration;
-	int           m_animation;
-	qreal         m_progress;
-	bool          m_move;
+	qreal         m_size;
+	QPointer<QAbstractAnimation> m_animation;
 	AnimationType m_currentAnimation;
-	QTimer       *m_animationRepeater;
-	bool          m_repeater;
 
 signals:
 	void update();

File applet/SmoothTasks/TaskItem.cpp

View file
  • Ignore whitespace
 	
 	if (m_task->type() == Task::StartupItem) {
 		m_icon->startStartupAnimation(500);
-		m_light->startAnimation(Light::StartupAnimation, 500, true);
+		m_light->startAnimation(Light::StartupAnimation, 500, -1);
 	}
 		
 	if (abstractItem->itemType() == TaskManager::GroupItemType) {
 
 	if (m_task->demandsAttention()) {
 		newState |= TaskStateAnimation::Attention;
-		m_light->startAnimation(Light::AttentionAnimation, 900, true);
+		m_light->startAnimation(Light::AttentionAnimation, 900, 3);
 	} 
 	else if (m_task->type() == Task::LauncherItem) {
 		newState |= TaskStateAnimation::Launcher;