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

Port to new AnimatedSpinner

This commit is contained in:
Leo Franchi 2012-04-27 17:38:43 -04:00
parent 1d5e124b46
commit 65b01ffbca
19 changed files with 39 additions and 212 deletions

View File

@ -171,7 +171,7 @@ AccountDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option,
if ( m_loadingSpinners[ index ] )
{
painter->setOpacity( 1.0 );
const QPixmap pm = QPixmap::grabWidget( m_loadingSpinners[ index ] );
const QPixmap pm = m_loadingSpinners[index]->pixmap();
painter->drawPixmap( checkRect.adjusted( -2, -2, 2, 2 ), pm );
}
}

View File

@ -44,7 +44,7 @@
#include "AccountDelegate.h"
#include "database/Database.h"
#include "network/Servent.h"
#include "playlist/dynamic/widgets/LoadingSpinner.h"
#include "utils/AnimatedSpinner.h"
#include "accounts/AccountModel.h"
#include "accounts/Account.h"
#include "accounts/AccountManager.h"
@ -132,7 +132,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
if ( !Servent::instance()->isReady() )
{
m_sipSpinner = new LoadingSpinner( ui->accountsView );
m_sipSpinner = new AnimatedSpinner( ui->accountsView );
m_sipSpinner->fadeIn();
connect( Servent::instance(), SIGNAL( ready() ), this, SLOT( serventReady() ) );

View File

@ -26,7 +26,7 @@
#include "config.h"
class LoadingSpinner;
class AnimatedSpinner;
class QListWidgetItem;
class Ui_StackedSettingsDialog;
class SipPlugin;
@ -112,7 +112,7 @@ private:
bool m_rejected;
Tomahawk::Accounts::AccountModel* m_accountModel;
Tomahawk::Accounts::AccountModelFilterProxy* m_accountProxy;
LoadingSpinner* m_sipSpinner;
AnimatedSpinner* m_sipSpinner;
};
#endif // SETTINGSDIALOG_H

View File

@ -19,7 +19,7 @@
#include "SpotifyAccountConfig.h"
#include "SpotifyAccount.h"
#include <playlist/dynamic/widgets/LoadingSpinner.h>
#include "utils/AnimatedSpinner.h"
#include "ui_SpotifyAccountConfig.h"
#include <QListWidget>
@ -44,7 +44,7 @@ SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account )
connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( resetLoginButton() ) );
loadFromConfig();
m_playlistsLoading = new LoadingSpinner( m_ui->playlistList );
m_playlistsLoading = new AnimatedSpinner( m_ui->playlistList );
}

View File

@ -23,7 +23,7 @@
#include <QVariantMap>
#include <QTimer>
class LoadingSpinner;
class AnimatedSpinner;
class QShowEvent;
namespace Ui
@ -74,7 +74,7 @@ private slots:
private:
Ui::SpotifyConfig* m_ui;
SpotifyAccount* m_account;
LoadingSpinner* m_playlistsLoading;
AnimatedSpinner* m_playlistsLoading;
bool m_loggedInManually;
};

View File

@ -96,7 +96,6 @@ set( libGuiSources
playlist/dynamic/widgets/MiscControlWidgets.cpp
playlist/dynamic/widgets/CollapsibleControls.cpp
playlist/dynamic/widgets/DynamicSetupWidget.cpp
playlist/dynamic/widgets/LoadingSpinner.cpp
playlist/topbar/TopBar.cpp
playlist/topbar/ClearButton.cpp

View File

@ -34,7 +34,7 @@
#include "AlbumModel.h"
#include "ViewManager.h"
#include "utils/Logger.h"
#include "dynamic/widgets/LoadingSpinner.h"
#include "utils/AnimatedSpinner.h"
#define SCROLL_TIMEOUT 280
@ -46,7 +46,7 @@ AlbumView::AlbumView( QWidget* parent )
, m_model( 0 )
, m_proxyModel( 0 )
, m_delegate( 0 )
, m_loadingSpinner( new LoadingSpinner( this ) )
, m_loadingSpinner( new AnimatedSpinner( this ) )
, m_overlay( new OverlayWidget( this ) )
, m_inited( false )
{

View File

@ -30,7 +30,7 @@
#include "DllMacro.h"
class AlbumModel;
class LoadingSpinner;
class AnimatedSpinner;
class AlbumItemDelegate;
class DLLEXPORT AlbumView : public QListView, public Tomahawk::ViewPage
@ -87,7 +87,7 @@ private:
AlbumModel* m_model;
AlbumProxyModel* m_proxyModel;
AlbumItemDelegate* m_delegate;
LoadingSpinner* m_loadingSpinner;
AnimatedSpinner* m_loadingSpinner;
OverlayWidget* m_overlay;
bool m_inited;

View File

@ -26,7 +26,7 @@
#include "audio/AudioEngine.h"
#include "context/ContextWidget.h"
#include "dynamic/widgets/LoadingSpinner.h"
#include "utils/AnimatedSpinner.h"
#include "widgets/OverlayWidget.h"
#include "ContextMenu.h"
@ -49,7 +49,7 @@ ArtistView::ArtistView( QWidget* parent )
, m_model( 0 )
, m_proxyModel( 0 )
// , m_delegate( 0 )
, m_loadingSpinner( new LoadingSpinner( this ) )
, m_loadingSpinner( new AnimatedSpinner( this ) )
, m_updateContextView( true )
, m_contextMenu( new ContextMenu( this ) )
, m_showModes( true )

View File

@ -37,7 +37,7 @@ namespace Tomahawk
};
class TreeHeader;
class LoadingSpinner;
class AnimatedSpinner;
class OverlayWidget;
class TreeModel;
@ -108,7 +108,7 @@ private:
TreeModel* m_model;
TreeProxyModel* m_proxyModel;
// PlaylistItemDelegate* m_delegate;
LoadingSpinner* m_loadingSpinner;
AnimatedSpinner* m_loadingSpinner;
bool m_updateContextView;

View File

@ -30,7 +30,6 @@
#include "audio/AudioEngine.h"
#include "context/ContextWidget.h"
#include "widgets/OverlayWidget.h"
#include "dynamic/widgets/LoadingSpinner.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#include "utils/Closure.h"

View File

@ -30,7 +30,6 @@
#include "DllMacro.h"
class QAction;
class LoadingSpinner;
class AnimatedSpinner;
class TrackHeader;
class TrackModel;

View File

@ -41,7 +41,7 @@
#include "ViewManager.h"
#include "dynamic/DynamicView.h"
#include "DynamicSetupWidget.h"
#include "LoadingSpinner.h"
#include "utils/AnimatedSpinner.h"
#include "utils/Logger.h"
using namespace Tomahawk;
@ -74,7 +74,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
connect( m_model, SIGNAL( collapseFromTo( int, int ) ), m_view, SLOT( collapseEntries( int, int ) ) );
connect( m_model, SIGNAL( trackGenerationFailure( QString ) ), this, SLOT( stationFailed( QString ) ) );
m_loading = new LoadingSpinner( m_view );
m_loading = new AnimatedSpinner( m_view );
connect( m_model, SIGNAL( tracksAdded() ), m_loading, SLOT( fadeOut() ) );
m_setup = new DynamicSetupWidget( playlist, this );

View File

@ -26,7 +26,7 @@
#include "ViewPage.h"
#include "playlist/dynamic/DynamicPlaylistRevision.h"
class LoadingSpinner;
class AnimatedSpinner;
class QShowEvent;
class QHideEvent;
class QSpinBox;
@ -119,7 +119,7 @@ private:
bool m_activePlaylist;
// loading animation
LoadingSpinner* m_loading;
AnimatedSpinner* m_loading;
// setup controls
DynamicSetupWidget* m_setup;

View File

@ -1,128 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010 Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@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 "LoadingSpinner.h"
#include <QTimeLine>
#include <QPaintEvent>
#include <QPainter>
#include <QMovie>
#include <QLabel>
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h"
#define ANIM_LENGTH 300
LoadingSpinner::LoadingSpinner( QWidget* parent )
: QWidget( parent )
, m_showHide( new QTimeLine )
{
m_showHide->setDuration( 300 );
m_showHide->setStartFrame( 0 );
m_showHide->setEndFrame( 100 );
m_showHide->setUpdateInterval( 20 );
connect( m_showHide, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
connect( m_showHide, SIGNAL( finished() ), this, SLOT( hideFinished() ) );
m_anim = new QMovie( RESPATH "/images/loading-animation.gif" );
m_anim->jumpToNextFrame();
connect( m_anim, SIGNAL( frameChanged( int ) ), this, SLOT( update() ) );
resize( m_anim->currentPixmap().size() );
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
hide();
}
LoadingSpinner::~LoadingSpinner()
{
}
void
LoadingSpinner::fadeIn()
{
if ( isVisible() )
return;
show();
m_anim->start();
m_showHide->setDirection( QTimeLine::Forward );
if ( m_showHide->state() != QTimeLine::Running )
m_showHide->start();
}
void
LoadingSpinner::fadeOut()
{
m_showHide->setDirection( QTimeLine::Backward );
if ( m_showHide->state() != QTimeLine::Running )
m_showHide->start();
}
void
LoadingSpinner::hideFinished()
{
if ( m_showHide->direction() == QTimeLine::Backward )
{
hide();
m_anim->stop();
}
}
QSize
LoadingSpinner::sizeHint() const
{
return m_anim->currentPixmap().size();
}
void
LoadingSpinner::paintEvent( QPaintEvent* ev )
{
Q_UNUSED( ev );
if ( !parentWidget() )
return;
QPoint center( ( parentWidget()->width() / 2 ) - ( width() / 2 ), ( parentWidget()->height() / 2 ) - ( height() / 2 ) );
if ( center != pos() )
{
move( center );
return;
}
QPainter p( this );
if ( m_showHide->state() == QTimeLine::Running )
{ // showing or hiding
p.setOpacity( (qreal)m_showHide->currentValue() );
}
p.drawPixmap( rect(), m_anim->currentPixmap() );
}

View File

@ -1,56 +0,0 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010 Leo Franchi <lfranchi@kde.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 LOADING_SPINNER_H
#define LOADING_SPINNER_H
#include <QWidget>
#include "DllMacro.h"
class QMovie;
class QTimeLine;
/**
* A small widget that displays an animated loading spinner
*/
class DLLEXPORT LoadingSpinner : public QWidget {
Q_OBJECT
public:
LoadingSpinner( QWidget* parent );
virtual ~LoadingSpinner();
virtual QSize sizeHint() const;
virtual void paintEvent( QPaintEvent* );
public slots:
void fadeIn();
void fadeOut();
private slots:
void hideFinished();
private:
void reposition();
QTimeLine* m_showHide;
QMovie* m_anim;
};
#endif
class QPaintEvent;

View File

@ -54,6 +54,11 @@ AnimatedSpinner::AnimatedSpinner(QWidget *parent)
hide();
if ( !parentWidget() )
{
m_pixmap = QPixmap( sizeHint() );
}
}
@ -72,7 +77,17 @@ AnimatedSpinner::paintEvent(QPaintEvent *event)
}
}
QPainter p(this);
QPainter p;
if ( parentWidget() )
{
p.begin(this);
}
else
{
m_pixmap.fill( Qt::transparent );
p.begin(&m_pixmap);
}
if ( m_showHide->state() == QTimeLine::Running )
{

View File

@ -42,9 +42,9 @@ public:
/**
If you don't pass a parent QWidget, this spinner will
draw into the pixmap instead
draw into the pixmap instead. If you do, this will be invalid.
*/
QPixmap pixmap() const;
QPixmap pixmap() const { return m_pixmap; }
public slots:
void fadeIn();

View File

@ -25,7 +25,6 @@
#include "SourceList.h"
#include "ViewManager.h"
#include "dynamic/widgets/LoadingSpinner.h"
#include "playlist/AlbumModel.h"
#include "playlist/PlaylistModel.h"
#include "widgets/OverlayWidget.h"