mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 17:14:00 +02: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:
@@ -609,7 +609,8 @@ removeDirectory( const QString& dir )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
quint64 infosystemRequestId()
|
quint64
|
||||||
|
infosystemRequestId()
|
||||||
{
|
{
|
||||||
QMutexLocker locker( &s_infosystemRequestIdMutex );
|
QMutexLocker locker( &s_infosystemRequestIdMutex );
|
||||||
quint64 result = s_infosystemRequestId;
|
quint64 result = s_infosystemRequestId;
|
||||||
@@ -633,4 +634,42 @@ crash()
|
|||||||
*a = 1;
|
*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
|
} // ns
|
||||||
|
@@ -26,9 +26,9 @@
|
|||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
#include <QtNetwork/QNetworkProxy>
|
#include <QtNetwork/QNetworkProxy>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
|
#include <QTimeLine>
|
||||||
#include <typedefs.h>
|
#include <typedefs.h>
|
||||||
|
|
||||||
|
|
||||||
#define RESPATH ":/data/"
|
#define RESPATH ":/data/"
|
||||||
|
|
||||||
|
|
||||||
@@ -61,6 +61,34 @@ namespace TomahawkUtils
|
|||||||
ScaledCover
|
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
|
class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -86,6 +114,7 @@ namespace TomahawkUtils
|
|||||||
QNetworkProxy m_proxy;
|
QNetworkProxy m_proxy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DLLEXPORT QString appFriendlyVersion();
|
DLLEXPORT QString appFriendlyVersion();
|
||||||
|
|
||||||
DLLEXPORT QDir appConfigDir();
|
DLLEXPORT QDir appConfigDir();
|
||||||
|
@@ -18,22 +18,33 @@
|
|||||||
|
|
||||||
#include "FadingPixmap.h"
|
#include "FadingPixmap.h"
|
||||||
|
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QBuffer>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#define ANIMATION_TIME 1000
|
#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 )
|
FadingPixmap::FadingPixmap( QWidget* parent )
|
||||||
: QLabel( parent )
|
: QLabel( parent )
|
||||||
|
, m_oldPixmap( QPixmap() )
|
||||||
, m_fadePct( 100 )
|
, m_fadePct( 100 )
|
||||||
|
, m_startFrame( 0 )
|
||||||
{
|
{
|
||||||
// setCursor( Qt::PointingHandCursor );
|
// 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
|
void
|
||||||
FadingPixmap::onAnimationStep( int frame )
|
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();
|
repaint();
|
||||||
|
|
||||||
|
if ( m_fadePct == 100.0 )
|
||||||
|
QTimer::singleShot( 0, this, SLOT( onAnimationFinished() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,13 +77,25 @@ FadingPixmap::onAnimationFinished()
|
|||||||
{
|
{
|
||||||
setPixmap( m_pixmapQueue.takeFirst() );
|
setPixmap( m_pixmapQueue.takeFirst() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disconnect( stlInstance().data(), SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FadingPixmap::setPixmap( const QPixmap& pixmap, bool clearQueue )
|
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 )
|
if ( clearQueue )
|
||||||
m_pixmapQueue.clear();
|
m_pixmapQueue.clear();
|
||||||
@@ -78,9 +107,10 @@ FadingPixmap::setPixmap( const QPixmap& pixmap, bool clearQueue )
|
|||||||
m_oldPixmap = m_pixmap;
|
m_oldPixmap = m_pixmap;
|
||||||
m_pixmap = pixmap;
|
m_pixmap = pixmap;
|
||||||
|
|
||||||
m_timeLine->setFrameRange( 0, 1000 );
|
stlInstance().data()->setUpdateInterval( 20 );
|
||||||
m_timeLine->setDirection( QTimeLine::Forward );
|
m_startFrame = stlInstance().data()->currentFrame();
|
||||||
m_timeLine->start();
|
m_fadePct = 0;
|
||||||
|
connect( stlInstance().data(), SIGNAL( frameChanged( int ) ), this, SLOT( onAnimationStep( int ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,9 +19,12 @@
|
|||||||
#ifndef FADINGPIXMAP_H
|
#ifndef FADINGPIXMAP_H
|
||||||
#define FADINGPIXMAP_H
|
#define FADINGPIXMAP_H
|
||||||
|
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QTimeLine>
|
#include <QTimeLine>
|
||||||
|
#include <QWeakPointer>
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -33,12 +36,15 @@ class DLLEXPORT FadingPixmap : public QLabel
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
static QWeakPointer< TomahawkUtils::SharedTimeLine > stlInstance();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FadingPixmap( QWidget* parent = 0 );
|
FadingPixmap( QWidget* parent = 0 );
|
||||||
virtual ~FadingPixmap();
|
virtual ~FadingPixmap();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setPixmap( const QPixmap& pixmap, bool clearQueue = true );
|
virtual void setPixmap( const QPixmap& pixmap, bool clearQueue = true );
|
||||||
|
void onAnimationStep( int frame );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
@@ -48,17 +54,21 @@ protected:
|
|||||||
void mouseReleaseEvent( QMouseEvent* event );
|
void mouseReleaseEvent( QMouseEvent* event );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAnimationStep( int frame );
|
|
||||||
void onAnimationFinished();
|
void onAnimationFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
QPixmap m_oldPixmap;
|
QPixmap m_oldPixmap;
|
||||||
|
|
||||||
|
QString m_oldImageMd5;
|
||||||
|
|
||||||
QList<QPixmap> m_pixmapQueue;
|
QList<QPixmap> m_pixmapQueue;
|
||||||
|
|
||||||
QTimeLine* m_timeLine;
|
|
||||||
int m_fadePct;
|
int m_fadePct;
|
||||||
|
|
||||||
|
int m_startFrame;
|
||||||
|
|
||||||
|
static QWeakPointer< TomahawkUtils::SharedTimeLine > s_stlInstance;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user