mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
* Forgot those files.
This commit is contained in:
parent
c054d07110
commit
48d66649b1
114
src/libtomahawk/widgets/FadingPixmap.cpp
Normal file
114
src/libtomahawk/widgets/FadingPixmap.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2011 - 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FadingPixmap.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#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();
|
||||
}
|
64
src/libtomahawk/widgets/FadingPixmap.h
Normal file
64
src/libtomahawk/widgets/FadingPixmap.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2011 - 2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FADINGPIXMAP_H
|
||||
#define FADINGPIXMAP_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
#include <QTimeLine>
|
||||
|
||||
#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<QPixmap> m_pixmapQueue;
|
||||
|
||||
QTimeLine* m_timeLine;
|
||||
int m_fadePct;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user