mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Wrote this SharedTimeLine thing, then converted the wrong class to use it, oops. Seems to work perfectly, though, so might as well use it.
This commit is contained in:
parent
4e01387eb9
commit
546abf4a6d
@ -609,7 +609,8 @@ removeDirectory( const QString& dir )
|
||||
}
|
||||
|
||||
|
||||
quint64 infosystemRequestId()
|
||||
quint64
|
||||
infosystemRequestId()
|
||||
{
|
||||
QMutexLocker locker( &s_infosystemRequestIdMutex );
|
||||
quint64 result = s_infosystemRequestId;
|
||||
@ -633,4 +634,42 @@ crash()
|
||||
*a = 1;
|
||||
}
|
||||
|
||||
|
||||
SharedTimeLine::SharedTimeLine()
|
||||
: QObject( 0 )
|
||||
, m_refcount( 0 )
|
||||
{
|
||||
m_timeline.setCurveShape( QTimeLine::LinearCurve );
|
||||
m_timeline.setFrameRange( 0, INT_MAX );
|
||||
m_timeline.setDuration( INT_MAX );
|
||||
m_timeline.setUpdateInterval( 40 );
|
||||
connect( &m_timeline, SIGNAL( frameChanged( int ) ), SIGNAL( frameChanged( int ) ) );
|
||||
}
|
||||
|
||||
void
|
||||
SharedTimeLine::connectNotify( const char* signal )
|
||||
{
|
||||
if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) {
|
||||
m_refcount++;
|
||||
if ( m_timeline.state() != QTimeLine::Running )
|
||||
m_timeline.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SharedTimeLine::disconnectNotify( const char* signal )
|
||||
{
|
||||
if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) )
|
||||
{
|
||||
m_refcount--;
|
||||
if ( m_timeline.state() == QTimeLine::Running && m_refcount == 0 )
|
||||
{
|
||||
m_timeline.stop();
|
||||
deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // ns
|
||||
|
@ -26,9 +26,9 @@
|
||||
#include <QtCore/QThread>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QTimeLine>
|
||||
#include <typedefs.h>
|
||||
|
||||
|
||||
#define RESPATH ":/data/"
|
||||
|
||||
|
||||
@ -61,6 +61,34 @@ namespace TomahawkUtils
|
||||
ScaledCover
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT SharedTimeLine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SharedTimeLine();
|
||||
|
||||
virtual ~SharedTimeLine() {}
|
||||
|
||||
int currentFrame() { return m_timeline.currentFrame(); }
|
||||
|
||||
void setUpdateInterval( int msec ) { if ( msec != m_timeline.updateInterval() ) m_timeline.setUpdateInterval( msec ); }
|
||||
|
||||
signals:
|
||||
void frameChanged( int );
|
||||
|
||||
protected slots:
|
||||
virtual void connectNotify( const char *signal );
|
||||
|
||||
virtual void disconnectNotify( const char *signal );
|
||||
|
||||
private:
|
||||
int m_refcount;
|
||||
QTimeLine m_timeline;
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory
|
||||
{
|
||||
public:
|
||||
@ -85,6 +113,7 @@ namespace TomahawkUtils
|
||||
QStringList m_noProxyHosts;
|
||||
QNetworkProxy m_proxy;
|
||||
};
|
||||
|
||||
|
||||
DLLEXPORT QString appFriendlyVersion();
|
||||
|
||||
@ -107,7 +136,7 @@ namespace TomahawkUtils
|
||||
|
||||
DLLEXPORT QString md5( const QByteArray& data );
|
||||
DLLEXPORT bool removeDirectory( const QString& dir );
|
||||
|
||||
|
||||
/**
|
||||
* This helper is designed to help "update" an existing playlist with a newer revision of itself.
|
||||
* To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,
|
||||
|
@ -18,22 +18,33 @@
|
||||
|
||||
#include "FadingPixmap.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QBuffer>
|
||||
#include <QPainter>
|
||||
|
||||
#define ANIMATION_TIME 1000
|
||||
|
||||
QWeakPointer< TomahawkUtils::SharedTimeLine > FadingPixmap::s_stlInstance = QWeakPointer< TomahawkUtils::SharedTimeLine >();
|
||||
|
||||
QWeakPointer< TomahawkUtils::SharedTimeLine >
|
||||
FadingPixmap::stlInstance()
|
||||
{
|
||||
if ( s_stlInstance.isNull() )
|
||||
s_stlInstance = QWeakPointer< TomahawkUtils::SharedTimeLine> ( new TomahawkUtils::SharedTimeLine() );
|
||||
|
||||
return s_stlInstance;
|
||||
}
|
||||
|
||||
|
||||
FadingPixmap::FadingPixmap( QWidget* parent )
|
||||
: QLabel( parent )
|
||||
, m_oldPixmap( QPixmap() )
|
||||
, m_fadePct( 100 )
|
||||
, m_startFrame( 0 )
|
||||
{
|
||||
// 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() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -45,8 +56,14 @@ FadingPixmap::~FadingPixmap()
|
||||
void
|
||||
FadingPixmap::onAnimationStep( int frame )
|
||||
{
|
||||
m_fadePct = (float)frame / 10.0;
|
||||
m_fadePct = (float)( frame - m_startFrame ) / 10.0;
|
||||
if ( m_fadePct > 100.0 )
|
||||
m_fadePct = 100.0;
|
||||
|
||||
repaint();
|
||||
|
||||
if ( m_fadePct == 100.0 )
|
||||
QTimer::singleShot( 0, this, SLOT( onAnimationFinished() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -60,13 +77,25 @@ FadingPixmap::onAnimationFinished()
|
||||
{
|
||||
setPixmap( m_pixmapQueue.takeFirst() );
|
||||
}
|
||||
|
||||
disconnect( stlInstance().data(), SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FadingPixmap::setPixmap( const QPixmap& pixmap, bool clearQueue )
|
||||
{
|
||||
if ( m_timeLine->state() == QTimeLine::Running )
|
||||
QByteArray ba;
|
||||
QBuffer buffer( &ba );
|
||||
buffer.open( QIODevice::WriteOnly );
|
||||
pixmap.save( &buffer, "PNG" );
|
||||
QString newImageMd5 = TomahawkUtils::md5( buffer.data() );
|
||||
if ( m_oldImageMd5 == newImageMd5 )
|
||||
return;
|
||||
|
||||
m_oldImageMd5 = newImageMd5;
|
||||
|
||||
if ( !m_oldPixmap.isNull() )
|
||||
{
|
||||
if ( clearQueue )
|
||||
m_pixmapQueue.clear();
|
||||
@ -78,9 +107,10 @@ FadingPixmap::setPixmap( const QPixmap& pixmap, bool clearQueue )
|
||||
m_oldPixmap = m_pixmap;
|
||||
m_pixmap = pixmap;
|
||||
|
||||
m_timeLine->setFrameRange( 0, 1000 );
|
||||
m_timeLine->setDirection( QTimeLine::Forward );
|
||||
m_timeLine->start();
|
||||
stlInstance().data()->setUpdateInterval( 20 );
|
||||
m_startFrame = stlInstance().data()->currentFrame();
|
||||
m_fadePct = 0;
|
||||
connect( stlInstance().data(), SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,9 +19,12 @@
|
||||
#ifndef FADINGPIXMAP_H
|
||||
#define FADINGPIXMAP_H
|
||||
|
||||
#include "utils/tomahawkutils.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPaintEvent>
|
||||
#include <QTimeLine>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
@ -33,12 +36,15 @@ class DLLEXPORT FadingPixmap : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
static QWeakPointer< TomahawkUtils::SharedTimeLine > stlInstance();
|
||||
|
||||
public:
|
||||
FadingPixmap( QWidget* parent = 0 );
|
||||
virtual ~FadingPixmap();
|
||||
|
||||
public slots:
|
||||
virtual void setPixmap( const QPixmap& pixmap, bool clearQueue = true );
|
||||
void onAnimationStep( int frame );
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
@ -48,17 +54,21 @@ protected:
|
||||
void mouseReleaseEvent( QMouseEvent* event );
|
||||
|
||||
private slots:
|
||||
void onAnimationStep( int frame );
|
||||
void onAnimationFinished();
|
||||
|
||||
private:
|
||||
QPixmap m_pixmap;
|
||||
QPixmap m_oldPixmap;
|
||||
|
||||
QString m_oldImageMd5;
|
||||
|
||||
QList<QPixmap> m_pixmapQueue;
|
||||
|
||||
QTimeLine* m_timeLine;
|
||||
int m_fadePct;
|
||||
|
||||
int m_startFrame;
|
||||
|
||||
static QWeakPointer< TomahawkUtils::SharedTimeLine > s_stlInstance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user