diff --git a/src/libtomahawk/utils/SharedTimeLine.cpp b/src/libtomahawk/utils/SharedTimeLine.cpp index 7904b8599..e55ab5575 100644 --- a/src/libtomahawk/utils/SharedTimeLine.cpp +++ b/src/libtomahawk/utils/SharedTimeLine.cpp @@ -38,17 +38,26 @@ SharedTimeLine::SharedTimeLine() void -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) SharedTimeLine::connectNotify( const QMetaMethod& signal ) -#else -SharedTimeLine::connectNotify( const char* signal ) -#endif { #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) if ( signal == QMetaMethod::fromSignal( &SharedTimeLine::frameChanged ) ) + { + m_refcount++; + if ( m_timeline.state() != QTimeLine::Running ) + { + m_timeline.start(); + } + } #else - if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) + Q_ASSERT( false ); #endif +} + +void +SharedTimeLine::connectNotify( const char* signal ) +{ + if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) { m_refcount++; if ( m_timeline.state() != QTimeLine::Running ) @@ -60,17 +69,28 @@ SharedTimeLine::connectNotify( const char* signal ) void -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) SharedTimeLine::disconnectNotify( const QMetaMethod& signal ) -#else -SharedTimeLine::disconnectNotify( const char* signal ) -#endif { #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) if ( signal == QMetaMethod::fromSignal( &SharedTimeLine::frameChanged ) ) + { + m_refcount--; + if ( m_timeline.state() == QTimeLine::Running && m_refcount == 0 ) + { + m_timeline.stop(); + deleteLater(); + } + } #else - if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) + Q_ASSERT( false ); #endif +} + + +void +SharedTimeLine::disconnectNotify( const char* signal ) +{ + if ( signal == QMetaObject::normalizedSignature( SIGNAL( frameChanged( int ) ) ) ) { m_refcount--; if ( m_timeline.state() == QTimeLine::Running && m_refcount == 0 ) diff --git a/src/libtomahawk/utils/SharedTimeLine.h b/src/libtomahawk/utils/SharedTimeLine.h index a4bec18d3..30b5b76c8 100644 --- a/src/libtomahawk/utils/SharedTimeLine.h +++ b/src/libtomahawk/utils/SharedTimeLine.h @@ -46,13 +46,14 @@ signals: void frameChanged( int ); protected slots: -#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) - virtual void connectNotify( const QMetaMethod & signal ); - virtual void disconnectNotify( const QMetaMethod & signal ); -#else + // Would be nice to ifdef this, but we would need CMake 2.8.11 for that as a requirement +// #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) + virtual void connectNotify( const QMetaMethod& signal ); + virtual void disconnectNotify( const QMetaMethod& signal ); +// #else virtual void connectNotify( const char *signal ); virtual void disconnectNotify( const char *signal ); -#endif +// #endif private: int m_refcount;