mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
work on new welcome widget
This commit is contained in:
@@ -158,6 +158,7 @@ set( libSources
|
|||||||
|
|
||||||
widgets/newplaylistwidget.cpp
|
widgets/newplaylistwidget.cpp
|
||||||
widgets/welcomewidget.cpp
|
widgets/welcomewidget.cpp
|
||||||
|
widgets/welcomeplaylistmodel.cpp
|
||||||
widgets/overlaywidget.cpp
|
widgets/overlaywidget.cpp
|
||||||
widgets/infowidgets/sourceinfowidget.cpp
|
widgets/infowidgets/sourceinfowidget.cpp
|
||||||
|
|
||||||
@@ -316,6 +317,7 @@ set( libHeaders
|
|||||||
|
|
||||||
widgets/newplaylistwidget.h
|
widgets/newplaylistwidget.h
|
||||||
widgets/welcomewidget.h
|
widgets/welcomewidget.h
|
||||||
|
widgets/welcomeplaylistmodel.h
|
||||||
widgets/overlaywidget.h
|
widgets/overlaywidget.h
|
||||||
widgets/infowidgets/sourceinfowidget.h
|
widgets/infowidgets/sourceinfowidget.h
|
||||||
|
|
||||||
|
@@ -262,4 +262,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Playlist > )
|
||||||
|
|
||||||
#endif // PLAYLIST_H
|
#endif // PLAYLIST_H
|
||||||
|
@@ -294,6 +294,12 @@ TomahawkSettings::recentlyPlayedPlaylists() const
|
|||||||
return playlists;
|
return playlists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
TomahawkSettings::recentlyPlayedPlaylistGuids() const
|
||||||
|
{
|
||||||
|
return value( "playlists/recentlyPlayed" ).toStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist )
|
TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist )
|
||||||
@@ -304,6 +310,8 @@ TomahawkSettings::appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& pl
|
|||||||
playlist_guids.append( playlist->guid() );
|
playlist_guids.append( playlist->guid() );
|
||||||
|
|
||||||
setValue( "playlists/recentlyPlayed", playlist_guids );
|
setValue( "playlists/recentlyPlayed", playlist_guids );
|
||||||
|
|
||||||
|
emit recentlyPlayedPlaylistAdded( playlist );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
|
@@ -66,6 +66,7 @@ public:
|
|||||||
void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state );
|
void setPlaylistColumnSizes( const QString& playlistid, const QByteArray& state );
|
||||||
|
|
||||||
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
|
QList<Tomahawk::playlist_ptr> recentlyPlayedPlaylists() const;
|
||||||
|
QStringList recentlyPlayedPlaylistGuids() const;
|
||||||
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
|
void appendRecentlyPlayedPlaylist( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
|
||||||
void setBookmarkPlaylist( const QString& guid );
|
void setBookmarkPlaylist( const QString& guid );
|
||||||
@@ -182,6 +183,7 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
void recentlyPlayedPlaylistAdded( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static TomahawkSettings* s_instance;
|
static TomahawkSettings* s_instance;
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include "welcomeplaylistmodel.h"
|
||||||
|
|
||||||
#define HISTORY_TRACK_ITEMS 50
|
#define HISTORY_TRACK_ITEMS 50
|
||||||
#define HISTORY_PLAYLIST_ITEMS 10
|
#define HISTORY_PLAYLIST_ITEMS 10
|
||||||
@@ -44,6 +45,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
|
|||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
|
|
||||||
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
|
ui->playlistWidget->setItemDelegate( new PlaylistDelegate() );
|
||||||
|
ui->playlistWidget->setModel( new WelcomePlaylistModel( this ) );
|
||||||
ui->playlistWidget->overlay()->resize( 380, 86 );
|
ui->playlistWidget->overlay()->resize( 380, 86 );
|
||||||
ui->tracksView->overlay()->setEnabled( false );
|
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( 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 );
|
connect( AudioEngine::instance() ,SIGNAL( playlistChanged( PlaylistInterface* ) ), this, SLOT( updatePlaylists() ), Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,10 +72,10 @@ WelcomeWidget::~WelcomeWidget()
|
|||||||
void
|
void
|
||||||
WelcomeWidget::updatePlaylists()
|
WelcomeWidget::updatePlaylists()
|
||||||
{
|
{
|
||||||
ui->playlistWidget->clear();
|
// ui->playlistWidget->clear();
|
||||||
|
|
||||||
QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
|
||||||
|
|
||||||
|
// QList<Tomahawk::playlist_ptr> playlists = TomahawkSettings::instance()->recentlyPlayedPlaylists();
|
||||||
|
/*
|
||||||
foreach( const Tomahawk::playlist_ptr& playlist, playlists )
|
foreach( const Tomahawk::playlist_ptr& playlist, playlists )
|
||||||
{
|
{
|
||||||
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( refresh() ) );
|
connect( playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), SLOT( refresh() ) );
|
||||||
@@ -81,9 +83,10 @@ WelcomeWidget::updatePlaylists()
|
|||||||
PlaylistWidgetItem* item = new PlaylistWidgetItem( playlist );
|
PlaylistWidgetItem* item = new PlaylistWidgetItem( playlist );
|
||||||
ui->playlistWidget->addItem( item );
|
ui->playlistWidget->addItem( item );
|
||||||
item->setData( Qt::DisplayRole, playlist->title() );
|
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()->setText( tr( "You have not played any playlists yet." ) );
|
||||||
ui->playlistWidget->overlay()->show();
|
ui->playlistWidget->overlay()->show();
|
||||||
@@ -92,19 +95,9 @@ WelcomeWidget::updatePlaylists()
|
|||||||
ui->playlistWidget->overlay()->hide();
|
ui->playlistWidget->overlay()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
WelcomeWidget::refresh()
|
|
||||||
{
|
|
||||||
ui->playlistWidget->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source )
|
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 ) ) );
|
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
|
void
|
||||||
WelcomeWidget::onPlaylistActivated( QListWidgetItem* item )
|
WelcomeWidget::onPlaylistActivated( const QModelIndex& item )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
PlaylistWidgetItem* pwi = dynamic_cast<PlaylistWidgetItem*>(item);
|
Tomahawk::playlist_ptr pl = item.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >();
|
||||||
if( Tomahawk::dynplaylist_ptr dynplaylist = pwi->playlist().dynamicCast< Tomahawk::DynamicPlaylist >() )
|
if( Tomahawk::dynplaylist_ptr dynplaylist = pl.dynamicCast< Tomahawk::DynamicPlaylist >() )
|
||||||
ViewManager::instance()->show( dynplaylist );
|
ViewManager::instance()->show( dynplaylist );
|
||||||
else
|
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
|
QSize
|
||||||
PlaylistDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
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->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->drawText( option.rect.adjusted( option.rect.width() - 96, 2, 0, -2 ), trackCount, to );
|
||||||
|
|
||||||
painter->setFont( boldFont );
|
painter->setFont( boldFont );
|
||||||
@@ -241,7 +198,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
|
|
||||||
PlaylistWidget::PlaylistWidget( QWidget* parent )
|
PlaylistWidget::PlaylistWidget( QWidget* parent )
|
||||||
: QListWidget( parent )
|
: QListView( parent )
|
||||||
{
|
{
|
||||||
m_overlay = new OverlayWidget( this );
|
m_overlay = new OverlayWidget( this );
|
||||||
}
|
}
|
||||||
|
@@ -59,28 +59,7 @@ private:
|
|||||||
QPixmap m_playlistIcon;
|
QPixmap m_playlistIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class DLLEXPORT PlaylistWidget : public QListView
|
||||||
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
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlaylistWidget( QWidget* parent = 0 );
|
PlaylistWidget( QWidget* parent = 0 );
|
||||||
@@ -118,11 +97,10 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePlaylists();
|
void updatePlaylists();
|
||||||
void refresh();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onSourceAdded( const Tomahawk::source_ptr& source );
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
void onPlaylistActivated( QListWidgetItem* item );
|
void onPlaylistActivated( const QModelIndex& );
|
||||||
void onPlaybackFinished( const Tomahawk::query_ptr& query );
|
void onPlaybackFinished( const Tomahawk::query_ptr& query );
|
||||||
|
|
||||||
void checkQueries();
|
void checkQueries();
|
||||||
|
Reference in New Issue
Block a user