mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-22 16:59:58 +01:00
work on new welcome widget
This commit is contained in:
parent
e8be8e95b5
commit
55be3010e5
@ -158,6 +158,7 @@ set( libSources
|
||||
|
||||
widgets/newplaylistwidget.cpp
|
||||
widgets/welcomewidget.cpp
|
||||
widgets/welcomeplaylistmodel.cpp
|
||||
widgets/overlaywidget.cpp
|
||||
widgets/infowidgets/sourceinfowidget.cpp
|
||||
|
||||
@ -316,6 +317,7 @@ set( libHeaders
|
||||
|
||||
widgets/newplaylistwidget.h
|
||||
widgets/welcomewidget.h
|
||||
widgets/welcomeplaylistmodel.h
|
||||
widgets/overlaywidget.h
|
||||
widgets/infowidgets/sourceinfowidget.h
|
||||
|
||||
|
@ -262,4 +262,6 @@ private:
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
|
||||
|
||||
#endif // PLAYLIST_H
|
||||
|
@ -294,6 +294,12 @@ TomahawkSettings::recentlyPlayedPlaylists() const
|
||||
return playlists;
|
||||
}
|
||||
|
||||
QStringList
|
||||
TomahawkSettings::recentlyPlayedPlaylistGuids() const
|
||||
{
|
||||
return value( "playlists/recentlyPlayed" ).toStringList();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||
@ -304,6 +310,8 @@ TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& pl
|
||||
playlist_guids.append( playlist->guid() );
|
||||
|
||||
setValue( "playlists/recentlyPlayed", playlist_guids );
|
||||
|
||||
emit recentlyPlayedPlaylistAdded( playlist );
|
||||
}
|
||||
|
||||
QString
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state );
|
||||
|
||||
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
|
||||
QStringList recentlyPlayedPlaylistGuids() const;
|
||||
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||
|
||||
void setBookmarkPlaylist( const QString& guid );
|
||||
@ -182,6 +183,7 @@ public:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
void recentlyPlayedPlaylistAdded( const Tomahawk::playlist_ptr& playlist );
|
||||
|
||||
private:
|
||||
static TomahawkSettings* s_instance;
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "tomahawksettings.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include "welcomeplaylistmodel.h"
|
||||
|
||||
#define HISTORY_TRACK_ITEMS 50
|
||||
#define HISTORY_PLAYLIST_ITEMS 10
|
||||
@ -44,6 +45,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
|
||||
ui->setupUi( this );
|
||||
|
||||
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
|
||||
ui->playlistWidget->setModel( new WelcomePlaylistModel( this ) );
|
||||
ui->playlistWidget->overlay()->resize( 380, 86 );
|
||||
ui->tracksView->overlay()->setEnabled( false );
|
||||
|
||||
@ -56,7 +58,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
|
||||
|
||||
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||
|
||||
connect( ui->playlistWidget, SIGNAL( itemActivated( QListWidgetItem* ) ), SLOT( onPlaylistActivated( QListWidgetItem* ) ) );
|
||||
connect( ui->playlistWidget, SIGNAL( activated( QModelIndex ) ), SLOT( onPlaylistActivated( QModelIndex ) ) );
|
||||
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
@ -70,10 +72,10 @@ WelcomeWidget::~WelcomeWidget()
|
||||
void
|
||||
WelcomeWidget::updatePlaylists()
|
||||
{
|
||||
ui->playlistWidget->clear();
|
||||
|
||||
QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
||||
// ui->playlistWidget->clear();
|
||||
|
||||
// QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
||||
/*
|
||||
foreach( const Tomahawk::playlist_ptr& playlist, playlists )
|
||||
{
|
||||
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( refresh() ) );
|
||||
@ -81,9 +83,10 @@ WelcomeWidget::updatePlaylists()
|
||||
PlaylistWidgetItem* item = new PlaylistWidgetItem( playlist );
|
||||
ui->playlistWidget->addItem( item );
|
||||
item->setData( Qt::DisplayRole, playlist->title() );
|
||||
}
|
||||
}*/
|
||||
|
||||
if ( !playlists.count() )
|
||||
int num = ui->playlistWidget->model()->rowCount( QModelIndex() );
|
||||
if ( num == 0 )
|
||||
{
|
||||
ui->playlistWidget->overlay()->setText( tr( "You have not played any playlists yet." ) );
|
||||
ui->playlistWidget->overlay()->show();
|
||||
@ -92,19 +95,9 @@ WelcomeWidget::updatePlaylists()
|
||||
ui->playlistWidget->overlay()->hide();
|
||||
}
|
||||
|
||||
void
|
||||
WelcomeWidget::refresh()
|
||||
{
|
||||
ui->playlistWidget->update();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||
{
|
||||
connect( source->collection().data(), SIGNAL( playlistsAdded( QList<Tomahawk::playlist_ptr> ) ), SLOT( updatePlaylists() ) );
|
||||
connect( source->collection().data(), SIGNAL( playlistsDeleted( QList<Tomahawk::playlist_ptr> ) ), SLOT( updatePlaylists() ) );
|
||||
|
||||
connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) );
|
||||
}
|
||||
|
||||
@ -132,15 +125,15 @@ WelcomeWidget::onPlaybackFinished( const Tomahawk::query_ptr& query )
|
||||
|
||||
|
||||
void
|
||||
WelcomeWidget::onPlaylistActivated( QListWidgetItem* item )
|
||||
WelcomeWidget::onPlaylistActivated( const QModelIndex& item )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
PlaylistWidgetItem* pwi = dynamic_cast<PlaylistWidgetItem*>(item);
|
||||
if( Tomahawk::dynplaylist_ptr dynplaylist = pwi->playlist().dynamicCast< Tomahawk::DynamicPlaylist >() )
|
||||
Tomahawk::playlist_ptr pl = item.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
|
||||
if( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
|
||||
ViewManager::instance()->show( dynplaylist );
|
||||
else
|
||||
ViewManager::instance()->show( pwi->playlist() );
|
||||
ViewManager::instance()->show( pl );
|
||||
}
|
||||
|
||||
|
||||
@ -159,42 +152,6 @@ WelcomeWidget::changeEvent( QEvent* e )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QVariant
|
||||
PlaylistWidgetItem::data( int role ) const
|
||||
{
|
||||
if ( role == ArtistRole )
|
||||
{
|
||||
if ( m_artists.isEmpty() )
|
||||
{
|
||||
QStringList artists;
|
||||
|
||||
foreach( const Tomahawk::plentry_ptr& entry, m_playlist->entries() )
|
||||
{
|
||||
if ( !artists.contains( entry->query()->artist() ) )
|
||||
artists << entry->query()->artist();
|
||||
}
|
||||
|
||||
m_artists = artists.join( ", " );
|
||||
}
|
||||
|
||||
return m_artists;
|
||||
}
|
||||
|
||||
if ( role == TrackCountRole )
|
||||
{
|
||||
return m_playlist->entries().count();
|
||||
}
|
||||
|
||||
if ( role == Qt::DisplayRole )
|
||||
{
|
||||
return m_playlist->title();
|
||||
}
|
||||
|
||||
return QListWidgetItem::data( role );
|
||||
}
|
||||
|
||||
|
||||
QSize
|
||||
PlaylistDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
{
|
||||
@ -228,9 +185,9 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
|
||||
painter->drawPixmap( option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 ), m_playlistIcon );
|
||||
|
||||
painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), index.data( PlaylistWidgetItem::ArtistRole ).toString() );
|
||||
painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), index.data( WelcomePlaylistModel::ArtistRole ).toString() );
|
||||
|
||||
QString trackCount = tr( "%1 tracks" ).arg( index.data( PlaylistWidgetItem::TrackCountRole ).toString() );
|
||||
QString trackCount = tr( "%1 tracks" ).arg( index.data( WelcomePlaylistModel::TrackCountRole ).toString() );
|
||||
painter->drawText( option.rect.adjusted( option.rect.width() - 96, 2, 0, -2 ), trackCount, to );
|
||||
|
||||
painter->setFont( boldFont );
|
||||
@ -241,7 +198,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
|
||||
|
||||
PlaylistWidget::PlaylistWidget( QWidget* parent )
|
||||
: QListWidget( parent )
|
||||
: QListView( parent )
|
||||
{
|
||||
m_overlay = new OverlayWidget( this );
|
||||
}
|
||||
|
@ -59,28 +59,7 @@ private:
|
||||
QPixmap m_playlistIcon;
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT PlaylistWidgetItem : public QListWidgetItem
|
||||
{
|
||||
public:
|
||||
enum ItemRoles
|
||||
{ ArtistRole = Qt::UserRole, TrackCountRole };
|
||||
|
||||
PlaylistWidgetItem( const Tomahawk::playlist_ptr& playlist ) : QListWidgetItem() { m_playlist = playlist; }
|
||||
~PlaylistWidgetItem() {}
|
||||
|
||||
virtual QVariant data( int role ) const;
|
||||
|
||||
Tomahawk::playlist_ptr playlist() const { return m_playlist; }
|
||||
|
||||
private:
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
|
||||
mutable QString m_artists;
|
||||
};
|
||||
|
||||
|
||||
class DLLEXPORT PlaylistWidget : public QListWidget
|
||||
class DLLEXPORT PlaylistWidget : public QListView
|
||||
{
|
||||
public:
|
||||
PlaylistWidget( QWidget* parent = 0 );
|
||||
@ -118,11 +97,10 @@ signals:
|
||||
|
||||
public slots:
|
||||
void updatePlaylists();
|
||||
void refresh();
|
||||
|
||||
private slots:
|
||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||
void onPlaylistActivated( QListWidgetItem* item );
|
||||
void onPlaylistActivated( const QModelIndex& );
|
||||
void onPlaybackFinished( const Tomahawk::query_ptr& query );
|
||||
|
||||
void checkQueries();
|
||||
|
Loading…
x
Reference in New Issue
Block a user