From 65b01ffbca04171d4dbbbabb9a9c0594589935b6 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 27 Apr 2012 17:38:43 -0400 Subject: [PATCH] Port to new AnimatedSpinner --- src/AccountDelegate.cpp | 2 +- src/SettingsDialog.cpp | 4 +- src/SettingsDialog.h | 4 +- src/accounts/spotify/SpotifyAccountConfig.cpp | 4 +- src/accounts/spotify/SpotifyAccountConfig.h | 4 +- src/libtomahawk/CMakeLists.txt | 1 - src/libtomahawk/playlist/AlbumView.cpp | 4 +- src/libtomahawk/playlist/AlbumView.h | 4 +- src/libtomahawk/playlist/ArtistView.cpp | 4 +- src/libtomahawk/playlist/ArtistView.h | 4 +- src/libtomahawk/playlist/TrackView.cpp | 1 - src/libtomahawk/playlist/TrackView.h | 1 - .../dynamic/widgets/DynamicWidget.cpp | 4 +- .../playlist/dynamic/widgets/DynamicWidget.h | 4 +- .../dynamic/widgets/LoadingSpinner.cpp | 128 ------------------ .../playlist/dynamic/widgets/LoadingSpinner.h | 56 -------- src/libtomahawk/utils/AnimatedSpinner.cpp | 17 ++- src/libtomahawk/utils/AnimatedSpinner.h | 4 +- src/libtomahawk/widgets/SearchWidget.cpp | 1 - 19 files changed, 39 insertions(+), 212 deletions(-) delete mode 100644 src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.cpp delete mode 100644 src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h diff --git a/src/AccountDelegate.cpp b/src/AccountDelegate.cpp index 157061fa7..150da0642 100644 --- a/src/AccountDelegate.cpp +++ b/src/AccountDelegate.cpp @@ -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 ); } } diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index b25fb7991..1795035b5 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -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() ) ); diff --git a/src/SettingsDialog.h b/src/SettingsDialog.h index 991723423..7d1ab0d1b 100644 --- a/src/SettingsDialog.h +++ b/src/SettingsDialog.h @@ -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 diff --git a/src/accounts/spotify/SpotifyAccountConfig.cpp b/src/accounts/spotify/SpotifyAccountConfig.cpp index 2d475bad2..b3fa5f629 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/accounts/spotify/SpotifyAccountConfig.cpp @@ -19,7 +19,7 @@ #include "SpotifyAccountConfig.h" #include "SpotifyAccount.h" -#include +#include "utils/AnimatedSpinner.h" #include "ui_SpotifyAccountConfig.h" #include @@ -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 ); } diff --git a/src/accounts/spotify/SpotifyAccountConfig.h b/src/accounts/spotify/SpotifyAccountConfig.h index 56d3ff748..79c398e04 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.h +++ b/src/accounts/spotify/SpotifyAccountConfig.h @@ -23,7 +23,7 @@ #include #include -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; }; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index b9349143e..c77b302e5 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -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 diff --git a/src/libtomahawk/playlist/AlbumView.cpp b/src/libtomahawk/playlist/AlbumView.cpp index a3b2c6080..881a566b8 100644 --- a/src/libtomahawk/playlist/AlbumView.cpp +++ b/src/libtomahawk/playlist/AlbumView.cpp @@ -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 ) { diff --git a/src/libtomahawk/playlist/AlbumView.h b/src/libtomahawk/playlist/AlbumView.h index 6e5cd73f9..c7d3918b5 100644 --- a/src/libtomahawk/playlist/AlbumView.h +++ b/src/libtomahawk/playlist/AlbumView.h @@ -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; diff --git a/src/libtomahawk/playlist/ArtistView.cpp b/src/libtomahawk/playlist/ArtistView.cpp index ce22cccd8..fec374771 100644 --- a/src/libtomahawk/playlist/ArtistView.cpp +++ b/src/libtomahawk/playlist/ArtistView.cpp @@ -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 ) diff --git a/src/libtomahawk/playlist/ArtistView.h b/src/libtomahawk/playlist/ArtistView.h index 1926acd4e..90c76e66f 100644 --- a/src/libtomahawk/playlist/ArtistView.h +++ b/src/libtomahawk/playlist/ArtistView.h @@ -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; diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index d50ddcf47..74651b917 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -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" diff --git a/src/libtomahawk/playlist/TrackView.h b/src/libtomahawk/playlist/TrackView.h index ecd62cad4..1a27ccfed 100644 --- a/src/libtomahawk/playlist/TrackView.h +++ b/src/libtomahawk/playlist/TrackView.h @@ -30,7 +30,6 @@ #include "DllMacro.h" class QAction; -class LoadingSpinner; class AnimatedSpinner; class TrackHeader; class TrackModel; diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp index d5eb6cd77..eabad53e9 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp @@ -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 ); diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.h b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.h index 2a8d33e81..7773f2269 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.h +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.h @@ -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; diff --git a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.cpp b/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.cpp deleted file mode 100644 index 9b0ff0524..000000000 --- a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010 Leo Franchi - * Copyright 2010-2011, Jeff Mitchell - * - * 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 . - */ - -#include "LoadingSpinner.h" - -#include -#include -#include -#include -#include - -#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() ); -} diff --git a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h b/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h deleted file mode 100644 index fe51bb4fc..000000000 --- a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h +++ /dev/null @@ -1,56 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2010 Leo Franchi - * - * 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 . - */ - -#ifndef LOADING_SPINNER_H -#define LOADING_SPINNER_H - -#include - -#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; diff --git a/src/libtomahawk/utils/AnimatedSpinner.cpp b/src/libtomahawk/utils/AnimatedSpinner.cpp index 25c131eb7..0f98bc69a 100644 --- a/src/libtomahawk/utils/AnimatedSpinner.cpp +++ b/src/libtomahawk/utils/AnimatedSpinner.cpp @@ -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 ) { diff --git a/src/libtomahawk/utils/AnimatedSpinner.h b/src/libtomahawk/utils/AnimatedSpinner.h index 2bed69daa..cfe76d388 100644 --- a/src/libtomahawk/utils/AnimatedSpinner.h +++ b/src/libtomahawk/utils/AnimatedSpinner.h @@ -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(); diff --git a/src/libtomahawk/widgets/SearchWidget.cpp b/src/libtomahawk/widgets/SearchWidget.cpp index 8e7c60d70..30a9a84c5 100644 --- a/src/libtomahawk/widgets/SearchWidget.cpp +++ b/src/libtomahawk/widgets/SearchWidget.cpp @@ -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"