Commits

flupp  committed e8a97ed

using new class AnimationVariant in CloseIcon and WindowPreview now: replaces ToggleAnimation, and fixes Plasma::Animator-related deprecation warning

  • Participants
  • Parent commits b7346d6

Comments (0)

Files changed (9)

File applet/CMakeLists.txt

 set(smoothtasks_SRCS
 	SmoothTasks/Animation/AnimationThrowPoint.cpp
 	SmoothTasks/Animation/AnimationThrowRect.cpp
+	SmoothTasks/Animation/AnimationVariant.cpp
 	SmoothTasks/Applet.cpp
 	SmoothTasks/Task.cpp
 	SmoothTasks/TaskItem.cpp
 	SmoothTasks/FadedText.cpp
 	SmoothTasks/Global.cpp
 	SmoothTasks/CloseIcon.cpp
-	SmoothTasks/ToggleAnimation.cpp
 	SmoothTasks/TaskStateAnimation.cpp
 	SmoothTasks/TaskbarLayout.cpp
 	SmoothTasks/TaskbuttonFrameSvg.cpp

File applet/SmoothTasks/Animation/AnimationVariant.cpp

+/***********************************************************************************
+* Smooth Tasks
+* Copyright (C) 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+***********************************************************************************/
+
+#include "AnimationVariant.h"
+
+namespace SmoothTasks {
+
+AnimationVariant::AnimationVariant(QObject* parent)
+	: QVariantAnimation(parent)
+{}
+
+void AnimationVariant::updateCurrentValue(const QVariant& value) {
+	Q_UNUSED(value)
+}
+
+} // namespace SmoothTasks

File applet/SmoothTasks/Animation/AnimationVariant.h

+/***********************************************************************************
+* Smooth Tasks
+* Copyright (C) 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
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+***********************************************************************************/
+
+#ifndef ANIMATIONVARIANT_H
+#define ANIMATIONVARIANT_H
+
+#include <QVariantAnimation>
+
+namespace SmoothTasks {
+
+/** Actually, this class does not implement anything. Its only purpose is to
+ * make QVariantAnimation intantiable, if a QPropertyAnimation is not needed.
+ * To get informed about the ongoing animation, connect to the valueChanged
+ * slot.
+ */
+class AnimationVariant : public QVariantAnimation
+{
+	Q_OBJECT
+
+public:
+	AnimationVariant(QObject* parent = 0);
+
+protected:
+	/* implement */ virtual void updateCurrentValue(const QVariant& value);
+};
+
+} // namespace SmoothTasks
+
+#endif // ANIMATIONVARIANT_H

File applet/SmoothTasks/CloseIcon.cpp

 * Smooth Tasks
 * Copyright (C) 2009 Marcin Baszczewski <marcin.baszczewski@gmail.com>
 * Copyright (C) 2009 Mathias Panzenböck <grosser.meister.morti@gmx.net>
+* Copyright (C) 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/SmoothToolTip.h"
 #include "SmoothTasks/CloseIcon.h"
+#include "SmoothTasks/Animation/AnimationVariant.h"
 
 #include <Plasma/PaintUtils>
 
 namespace SmoothTasks {
 
 CloseIcon::CloseIcon(WindowPreview *preview)
-	: QWidget(preview),
-	  m_preview(preview),
-	  m_highlite() {
-	connect(
-		&m_highlite, SIGNAL(animate(qreal)),
-		this, SLOT(repaint()));
+	: QWidget(preview)
+	, m_preview(preview)
+	, m_highlight(new AnimationVariant(this))
+{
+	m_highlight->setStartValue(qreal(0.0));
+	m_highlight->setEndValue(qreal(1.0));
+	connect(m_highlight, SIGNAL(valueChanged(QVariant)), this, SLOT(update()));
 }
 
 void CloseIcon::mousePressEvent(QMouseEvent *event) {
 
 void CloseIcon::enterEvent(QEvent *event) {
 	Q_UNUSED(event);
-	Applet *applet = m_preview->toolTip()->applet();
-	m_highlite.startUp(applet->fps(), applet->animationDuration());
+	m_highlight->setDuration(m_preview->toolTip()->applet()->animationDuration());
+	m_highlight->setDirection(QAbstractAnimation::Forward);
+	m_highlight->start();
 }
 
 void CloseIcon::leaveEvent(QEvent *event) {
 	Q_UNUSED(event);
-	Applet *applet = m_preview->toolTip()->applet();
-	m_highlite.startDown(applet->fps(), applet->animationDuration());
+	m_highlight->setDuration(m_preview->toolTip()->applet()->animationDuration());
+	m_highlight->setDirection(QAbstractAnimation::Backward);
+	m_highlight->start();
 }
 
 void CloseIcon::paintEvent(QPaintEvent *event) {
 	Q_UNUSED(event);
 	
 	SmoothToolTip *toolTip = m_preview->toolTip();
-	const qreal opacity = m_preview->highlite();
+	const qreal currentHighlight = m_highlight->currentValue().toReal();
+	const qreal opacity = m_preview->highlight();
 
-	if (opacity > qreal(0.0)) {
+	if (opacity + qreal(1.0) > qreal(1.0)) {  // fuzzy compare
 		QPainter painter(this);
 		QPixmap  pixmap;
 		
-		if (m_highlite.atBottom()) {
+		if (qFuzzyCompare(currentHighlight, qreal(0.0))) {
 			pixmap = toolTip->closeIcon();
 		}
-		else if (m_highlite.atTop()) {
+		else if (qFuzzyCompare(currentHighlight, qreal(0.0))) {
 			pixmap = toolTip->hoverCloseIcon();
 		}
 		else {
 			pixmap = Plasma::PaintUtils::transition(
 				toolTip->closeIcon(),
 				toolTip->hoverCloseIcon(),
-				m_highlite.value());
+				currentHighlight);
 		}
 		
 		qreal x = qreal(width()  - pixmap.width())  * 0.5;
 	}
 }
 
-void CloseIcon::animate() {
-	repaint();
-}
-
 } // namespace SmoothTasks

File applet/SmoothTasks/CloseIcon.h

 * Smooth Tasks
 * Copyright (C) 2009 Marcin Baszczewski <marcin.baszczewski@gmail.com>
 * Copyright (C) 2009 Mathias Panzenböck <grosser.meister.morti@gmx.net>
+* Copyright (C) 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/Applet.h"
 #include "SmoothTasks/WindowPreview.h"
-#include "SmoothTasks/ToggleAnimation.h"
 
 namespace SmoothTasks {
 
+class AnimationVariant;
+
 class CloseIcon : public QWidget {
 	Q_OBJECT
 
 	~CloseIcon() {}
 
 private:
-	WindowPreview  *m_preview;
-	ToggleAnimation m_highlite;
-
-private slots:
-	void animate();
+	WindowPreview    *m_preview;
+	AnimationVariant *m_highlight;
 
 protected:
 	void paintEvent(QPaintEvent *event);

File applet/SmoothTasks/ToggleAnimation.cpp

-/***********************************************************************************
-* Smooth Tasks
-* Copyright (C) 2009 Mathias Panzenböck <grosser.meister.morti@gmx.net>
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*
-***********************************************************************************/
-
-#include "SmoothTasks/ToggleAnimation.h"
-
-#include <Plasma/Animator>
-
-namespace SmoothTasks {
-
-void ToggleAnimation::init() {
-	connect(
-		Plasma::Animator::self(), SIGNAL(customAnimationFinished(int)),
-		this, SLOT(finished(int)));
-}
-
-void ToggleAnimation::stop() {
-	if (m_animation) {
-		Plasma::Animator::self()->stopCustomAnimation(m_animation);
-		m_animation = 0;
-	}
-}
-
-void ToggleAnimation::start(Direction direction, int fps, int duration) {
-	if (direction == Up) {
-		startUp(fps, duration);
-	}
-	else {
-		startDown(fps, duration);
-	}
-}
-
-void ToggleAnimation::startUp(int fps, int duration) {
-	if (m_direction == Up && m_animation) {
-		return;
-	}
-	m_direction = Up;
-	start(fps, duration * (qreal(1.0) - m_value), "animateUp");
-}
-
-void ToggleAnimation::startDown(int fps, int duration) {
-	if (m_direction == Down && m_animation) {
-		return;
-	}
-	m_direction = Down;
-	start(fps, duration * m_value, "animateDown");
-}
-
-void ToggleAnimation::start(int fps, int duration, const char *animationSlot) {
-	int frames = fps * duration / 1000;
-	stop();
-
-	m_finished  = false;
-	m_oldValue  = m_value;
-
-	if (frames <= 0) {
-		m_animation = 0;
-		m_value     = m_direction == Up ? 1.0 : 0.0;
-		emit animate(m_value);
-		m_finished  = true;
-
-		emit finished(m_value);
-	}
-	else {
-		m_animation = Plasma::Animator::self()->customAnimation(
-			frames, duration,
-			Plasma::Animator::LinearCurve,
-			this, animationSlot);
-	}
-}
-
-void ToggleAnimation::animateUp(qreal progress) {
-	m_value = m_oldValue + (qreal(1.0) - m_oldValue) * progress;
-	emit animate(m_value);
-}
-
-void ToggleAnimation::animateDown(qreal progress) {
-	m_value = m_oldValue - m_oldValue * progress;
-	emit animate(m_value);
-}
-
-void ToggleAnimation::finished(int animation) {
-	if (m_animation == animation) {
-		m_animation = 0;
-		m_value     = m_direction == Up ? 1.0 : 0.0;
-		m_finished  = true;
-
-		emit finished(m_value);
-	}
-}
-
-} // namespace SmoothTasks

File applet/SmoothTasks/ToggleAnimation.h

-/***********************************************************************************
-* Smooth Tasks
-* Copyright (C) 2009 Mathias Panzenböck <grosser.meister.morti@gmx.net>
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-*
-***********************************************************************************/
-#ifndef SMOOTHTASKS_TOGGLEANIMATION_H
-#define SMOOTHTASKS_TOGGLEANIMATION_H
-
-#include <QObject>
-
-namespace SmoothTasks {
-
-class ToggleAnimation : public QObject {
-	Q_OBJECT
-
-public:
-	enum Direction {
-		Up,
-		Down
-	};
-
-	ToggleAnimation(QObject *parent)
-		: QObject(parent),
-		  m_animation(0),
-		  m_value(0.0),
-		  m_oldValue(0.0),
-		  m_direction(Down),
-		  m_finished(false) { init(); }
-
-	ToggleAnimation()
-		: QObject(),
-		  m_animation(0),
-		  m_value(0.0),
-		  m_oldValue(0.0),
-		  m_direction(Down),
-		  m_finished(false) { init(); }
-
-	~ToggleAnimation() { stop(); }
-
-	void      start(Direction direction, int fps, int duration);
-	void      startUp(int fps, int duration);
-	void      startDown(int fps, int duration);
-	void      stop();
-	qreal     value()      const { return m_value; }
-	bool      isActive()   const { return m_animation != 0; }
-	bool      isFinished() const { return m_finished; }
-	bool      atTop()      const { return m_finished && m_direction == Up; }
-	bool      atBottom()   const { return m_finished && m_direction == Down; }
-	Direction direction()  const { return m_direction; }
-
-signals:
-	void animate(qreal value);
-	void finished(qreal value);
-
-private slots:
-	void animateUp(qreal progress);
-	void animateDown(qreal progress);
-	void finished(int animation);
-
-private:
-	void init();
-	void start(int fps, int duration, const char *animationSlot);
-
-	int       m_animation;
-	qreal     m_value;
-	qreal     m_oldValue;
-	Direction m_direction;
-	bool      m_finished;
-};
-
-} // namespace SmoothTasks
-
-#endif

File applet/SmoothTasks/WindowPreview.cpp

 *
 ***********************************************************************************/
 
+#include "SmoothTasks/Animation/AnimationVariant.h"
 #include "SmoothTasks/WindowPreview.h"
 #include "SmoothTasks/SmoothToolTip.h"
 #include "SmoothTasks/CloseIcon.h"
 const QSize WindowPreview::BIG_ICON_SIZE(48, 48);
 const QSize WindowPreview::SMALL_ICON_SIZE(16, 16);
 
-WindowPreview::WindowPreview(
-		TaskManager::TaskItem *task,
-		int index,
-		SmoothToolTip *toolTip)
-	: QWidget(),
-	  m_background(new Plasma::FrameSvg(this)),
-	  m_iconSpace(NULL),
-	  m_previewSpace(NULL),
-	  m_highlite(),
-	  m_task(new Task(task, this)),
-	  m_toolTip(toolTip),
-	  m_previewSize(0, 0),
-	  m_hover(false),
-	  m_index(index),
-	  m_activateTimer(NULL),
-	  m_didPress(false),
-	  m_dragStartPosition() {
+WindowPreview::WindowPreview
+	( TaskManager::TaskItem *task
+	, int index
+	, SmoothToolTip *toolTip
+	)
+	: QWidget()
+	, m_background(new Plasma::FrameSvg(this))
+	, m_iconSpace(NULL)
+	, m_previewSpace(NULL)
+	, m_highlight(new AnimationVariant(this))
+	, m_task(new Task(task, this))
+	, m_toolTip(toolTip)
+	, m_previewSize(0, 0)
+	, m_hover(false)
+	, m_index(index)
+	, m_activateTimer(NULL)
+	, m_didPress(false)
+	, m_dragStartPosition()
+{
 	setMouseTracking(true);
 	setAcceptDrops(true);
 
 		task, SIGNAL(changed(::TaskManager::TaskChanges)),
 		this, SLOT(updateTask(::TaskManager::TaskChanges)));
 
-	connect(&m_highlite, SIGNAL(animate(qreal)), this, SLOT(repaint()));
+	m_highlight->setStartValue(qreal(0.0));
+	m_highlight->setEndValue(qreal(1.0));
+	connect(m_highlight, SIGNAL(valueChanged(QVariant)), this, SLOT(update()));
 }
 
 WindowPreview::~WindowPreview() {
 }
 
 void WindowPreview::setNewLayout() {
-	int fps = m_toolTip->applet()->fps();
 	QGridLayout *layout = new QGridLayout;
 	layout->setSpacing(3);
 	layout->setContentsMargins(8, 8, 8, 8);
 
 void WindowPreview::leftClickTask() {
 	if (m_toolTip->applet()->hideTooltipAfterClick() || !m_task->task()) {
-		m_highlite.stop();
+		m_highlight->stop();
+		m_highlight->setCurrentTime(0);
 		m_toolTip->hide();
 	}
 	
 	Q_UNUSED(event)
 	QPainter painter(this);
 
+	const qreal currentHighlight = m_highlight->currentValue().toReal();
+
 	// draw background (only when previews are used)
 	if (m_previewSpace) {
 		QPixmap  backgroundPixmap;
 		m_background->setElementPrefix(NORMAL);
 		m_background->getMargins(normalLeft, normalTop, normalRight, normalBottom);
 
-		if (m_highlite.atBottom()) {
+		if (qFuzzyCompare(currentHighlight, qreal(0.0))) {
 			backgroundPixmap = m_background->framePixmap();
 		}
-		else if (m_highlite.atTop()) {
+		else if (qFuzzyCompare(currentHighlight, qreal(1.0))) {
 			m_background->setElementPrefix(HOVER);
 			backgroundPixmap = m_background->framePixmap();
 		}
 			m_background->setElementPrefix(HOVER);
 			QPixmap hover(m_background->framePixmap());
 				
-			backgroundPixmap = Plasma::PaintUtils::transition(normal, hover, m_highlite.value());
+			backgroundPixmap = Plasma::PaintUtils::transition(normal, hover, currentHighlight);
 		}
 		QRect  spaceGeom(m_previewSpace->geometry());
 		QPoint backgroundPos(
 		iconGeom.left() + (iconGeom.width()  - m_icon.width())  * 0.5,
 		iconGeom.top()  + (iconGeom.height() - m_icon.height()) * 0.5);
 
-	if (m_highlite.atBottom()) {
+	if (qFuzzyCompare(currentHighlight, qreal(0.0))) {
 		iconPixmap = m_icon;
 	}
-	else if (m_highlite.atTop()) {
+	else if (qFuzzyCompare(currentHighlight, qreal(1.0))) {
 		iconPixmap = hoverIcon();
 	}
 	else {
-		iconPixmap = Plasma::PaintUtils::transition(m_icon, hoverIcon(), m_highlite.value());
+		iconPixmap = Plasma::PaintUtils::transition(m_icon, hoverIcon(), currentHighlight);
 	}
 	painter.drawPixmap(iconPos, iconPixmap);
 }
 }
 
 void WindowPreview::hoverEnter() {
-	Applet *applet = m_toolTip->applet();
-	m_highlite.startUp(applet->fps(), applet->animationDuration());
+	m_highlight->setDuration(m_toolTip->applet()->animationDuration());
+	m_highlight->setDirection(QAbstractAnimation::Forward);
+	m_highlight->start();
 	m_hover = true;
 	emit enter(this);
 
 }
 
 void WindowPreview::hoverLeave() {
-	Applet *applet = m_toolTip->applet();
-	m_highlite.startDown(applet->fps(), applet->animationDuration());
+	m_highlight->setDuration(m_toolTip->applet()->animationDuration());
+	m_highlight->setDirection(QAbstractAnimation::Backward);
+	m_highlight->start();
 	m_hover = false;
 	if (m_activateTimer) {
 		delete m_activateTimer;
 	adjustSize();
 }
 
+qreal WindowPreview::highlight() const {
+	return m_highlight->currentValue().toReal();
+}
+
 } // namespace SmoothTasks

File applet/SmoothTasks/WindowPreview.h

 * Smooth Tasks
 * Copyright (C) 2009 Marcin Baszczewski <marcin.baszczewski@gmail.com>
 * Copyright (C) 2009 Mathias Panzenböck <grosser.meister.morti@gmx.net>
-* Copyright (C) 2010 Toni Dietze <smooth-tasks@derflupp.e4ward.com>
+* Copyright (C) 2010, 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/Applet.h"
 #include "SmoothTasks/SmoothToolTip.h"
 #include "SmoothTasks/FadedText.h"
-#include "SmoothTasks/ToggleAnimation.h"
 
 #include <QWidget>
 #include <QSize>
 
 namespace SmoothTasks {
 
+class AnimationVariant;
+
 class WindowPreview : public QWidget {
 	Q_OBJECT
 
 		QRect previewRect(int x, int y) const;
 		SmoothToolTip *toolTip() const { return m_toolTip; }
 		Task* task()             const { return m_task; }
-		qreal highlite()         const { return m_highlite.value(); }
 		int   index()            const { return m_index; }
+		qreal highlight() const;
 		void  hoverEnter();
 		void  hoverLeave();
 
 		FadedText             *m_taskNameLabel;
 		QSpacerItem           *m_iconSpace;
 		QSpacerItem           *m_previewSpace;
-		ToggleAnimation        m_highlite;
+		AnimationVariant      *m_highlight;
 		Task                  *m_task;
 		SmoothToolTip         *m_toolTip;
 		QSize                  m_previewSize;