From 48d66649b1b96ed59b751cef08c38399d9c33000 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 31 Mar 2012 07:18:01 +0200 Subject: [PATCH] * Forgot those files. --- src/libtomahawk/widgets/FadingPixmap.cpp | 114 +++++++++++++++++++++++ src/libtomahawk/widgets/FadingPixmap.h | 64 +++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/libtomahawk/widgets/FadingPixmap.cpp create mode 100644 src/libtomahawk/widgets/FadingPixmap.h diff --git a/src/libtomahawk/widgets/FadingPixmap.cpp b/src/libtomahawk/widgets/FadingPixmap.cpp new file mode 100644 index 000000000..29b7304c4 --- /dev/null +++ b/src/libtomahawk/widgets/FadingPixmap.cpp @@ -0,0 +1,114 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011 - 2012, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + +#include "FadingPixmap.h" + +#include + +#define ANIMATION_TIME 1000 + +FadingPixmap::FadingPixmap( QWidget* parent ) + : QLabel( parent ) + , m_fadePct( 100 ) +{ +// setCursor( Qt::PointingHandCursor ); + + m_timeLine = new QTimeLine( ANIMATION_TIME, this ); + m_timeLine->setUpdateInterval( 20 ); + m_timeLine->setEasingCurve( QEasingCurve::Linear ); + + connect( m_timeLine, SIGNAL( frameChanged( int ) ), SLOT( onAnimationStep( int ) ) ); + connect( m_timeLine, SIGNAL( finished() ), SLOT( onAnimationFinished() ) ); +} + + +FadingPixmap::~FadingPixmap() +{ +} + + +void +FadingPixmap::onAnimationStep( int frame ) +{ + m_fadePct = (float)frame / 10.0; + repaint(); +} + + +void +FadingPixmap::onAnimationFinished() +{ + m_oldPixmap = QPixmap(); + repaint(); + + if ( m_pixmapQueue.count() ) + { + setPixmap( m_pixmapQueue.takeFirst() ); + } +} + + +void +FadingPixmap::setPixmap( const QPixmap& pixmap, bool clearQueue ) +{ + if ( m_timeLine->state() == QTimeLine::Running ) + { + if ( clearQueue ) + m_pixmapQueue.clear(); + + m_pixmapQueue << pixmap; + return; + } + + m_oldPixmap = m_pixmap; + m_pixmap = pixmap; + + m_timeLine->setFrameRange( 0, 1000 ); + m_timeLine->setDirection( QTimeLine::Forward ); + m_timeLine->start(); +} + + +void +FadingPixmap::mouseReleaseEvent( QMouseEvent* event ) +{ + QFrame::mouseReleaseEvent( event ); + + emit clicked(); +} + + +void +FadingPixmap::paintEvent( QPaintEvent* event ) +{ + Q_UNUSED( event ); + + QPainter p( this ); + QRect r = contentsRect(); + + p.save(); + p.setRenderHint( QPainter::Antialiasing ); + + p.setOpacity( float( 100.0 - m_fadePct ) / 100.0 ); + p.drawPixmap( r, m_oldPixmap ); + + p.setOpacity( float( m_fadePct ) / 100.0 ); + p.drawPixmap( r, m_pixmap ); + + p.restore(); +} diff --git a/src/libtomahawk/widgets/FadingPixmap.h b/src/libtomahawk/widgets/FadingPixmap.h new file mode 100644 index 000000000..e6bd7720f --- /dev/null +++ b/src/libtomahawk/widgets/FadingPixmap.h @@ -0,0 +1,64 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011 - 2012, Christian Muehlhaeuser + * + * Tomahawk 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 3 of the License, or + * (at your option) any later version. + * + * Tomahawk 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 Tomahawk. If not, see . + */ + +#ifndef FADINGPIXMAP_H +#define FADINGPIXMAP_H + +#include +#include +#include + +#include "dllmacro.h" + +/** + * \class FadingPixmap + * \brief Fades to the new image when calling setPixmap. + */ +class DLLEXPORT FadingPixmap : public QLabel +{ +Q_OBJECT + +public: + FadingPixmap( QWidget* parent = 0 ); + virtual ~FadingPixmap(); + +public slots: + virtual void setPixmap( const QPixmap& pixmap, bool clearQueue = true ); + +signals: + void clicked(); + +protected: + virtual void paintEvent( QPaintEvent* ); + void mouseReleaseEvent( QMouseEvent* event ); + +private slots: + void onAnimationStep( int frame ); + void onAnimationFinished(); + +private: + QPixmap m_pixmap; + QPixmap m_oldPixmap; + + QList m_pixmapQueue; + + QTimeLine* m_timeLine; + int m_fadePct; +}; + +#endif