1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

* LoadingSpinner inherits AnimatedSpinner and automatically connects to a QAbstractItemView.

This commit is contained in:
Christian Muehlhaeuser 2012-05-31 21:31:43 +02:00
parent 7bdc5ea4f2
commit 72528ab089
2 changed files with 45 additions and 4 deletions

View File

@ -31,7 +31,7 @@
#include "utils/Logger.h"
AnimatedSpinner::AnimatedSpinner( QWidget *parent )
AnimatedSpinner::AnimatedSpinner( QWidget* parent )
: QWidget( parent )
, m_showHide( new QTimeLine )
, m_animation( new QTimeLine )
@ -41,7 +41,7 @@ AnimatedSpinner::AnimatedSpinner( QWidget *parent )
}
AnimatedSpinner::AnimatedSpinner( const QSize size, bool autoStart )
AnimatedSpinner::AnimatedSpinner( const QSize& size, bool autoStart )
: QWidget()
, m_showHide( new QTimeLine )
, m_animation( new QTimeLine )
@ -260,3 +260,27 @@ AnimatedSpinner::segmentCount() const
{
return 11;
}
LoadingSpinner::LoadingSpinner( QAbstractItemView* parent )
: AnimatedSpinner( parent )
, m_parent( parent )
{
if ( m_parent->model() )
{
connect( m_parent->model(), SIGNAL( loadingStarted() ), SLOT( fadeIn() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingFinished() ), SLOT( fadeOut() ), Qt::UniqueConnection );
}
connect( m_parent, SIGNAL( modelChanged() ), SLOT( onViewModelChanged() ) );
}
void
LoadingSpinner::onViewModelChanged()
{
if ( m_parent->model() )
{
connect( m_parent->model(), SIGNAL( loadingStarted() ), SLOT( fadeIn() ), Qt::UniqueConnection );
connect( m_parent->model(), SIGNAL( loadingFinished() ), SLOT( fadeOut() ), Qt::UniqueConnection );
}
}

View File

@ -26,6 +26,7 @@
#include <QtGui/QColor>
#include <QtGui/QPixmap>
#include <QPainter>
#include <QAbstractItemView>
class QTimeLine;
class QHideEvent;
@ -42,9 +43,10 @@ class QTimerEvent;
class DLLEXPORT AnimatedSpinner : public QWidget
{
Q_OBJECT
public:
explicit AnimatedSpinner( QWidget *parent = 0 ); // widget mode
AnimatedSpinner( const QSize size, bool autoStart ); // pixmap mode
explicit AnimatedSpinner( QWidget* parent = 0 ); // widget mode
AnimatedSpinner( const QSize& size, bool autoStart ); // pixmap mode
QSize sizeHint() const;
@ -87,4 +89,19 @@ private:
bool m_autoCenter;
};
class LoadingSpinner : public AnimatedSpinner
{
Q_OBJECT
public:
explicit LoadingSpinner( QAbstractItemView* parent = 0 ); // widget mode
private slots:
void onViewModelChanged();
private:
QAbstractItemView* m_parent;
};
#endif