mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-28 03:32:27 +01:00
* Added context menus for Artists & Albums, too.
This commit is contained in:
parent
1c820a2beb
commit
4abb52d198
@ -21,7 +21,6 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "globalactionmanager.h"
|
||||
#include "pipeline.h"
|
||||
#include "playlistview.h"
|
||||
#include "viewmanager.h"
|
||||
|
||||
@ -38,10 +37,24 @@ ContextMenu::ContextMenu( QWidget* parent )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::clear()
|
||||
{
|
||||
QMenu::clear();
|
||||
|
||||
m_queries.clear();
|
||||
m_albums.clear();
|
||||
m_artists.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
|
||||
{
|
||||
clear();
|
||||
if ( queries.isEmpty() )
|
||||
return;
|
||||
|
||||
QMenu::clear();
|
||||
m_queries.clear();
|
||||
m_queries << queries;
|
||||
|
||||
@ -55,8 +68,8 @@ ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
|
||||
|
||||
addSeparator();
|
||||
|
||||
if ( m_supportedActions & ActionCopyLink )
|
||||
m_sigmap->setMapping( addAction( tr( "Copy Track Link" ) ), ActionCopyLink );
|
||||
if ( m_supportedActions & ActionCopyLink && itemCount() == 1 )
|
||||
m_sigmap->setMapping( addAction( tr( "Copy Track &Link" ) ), ActionCopyLink );
|
||||
|
||||
addSeparator();
|
||||
|
||||
@ -79,6 +92,84 @@ ContextMenu::setQuery( const Tomahawk::query_ptr& query )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setAlbums( const QList<Tomahawk::album_ptr>& albums )
|
||||
{
|
||||
if ( albums.isEmpty() )
|
||||
return;
|
||||
|
||||
QMenu::clear();
|
||||
m_albums.clear();
|
||||
m_albums << albums;
|
||||
|
||||
if ( m_supportedActions & ActionPlay )
|
||||
m_sigmap->setMapping( addAction( tr( "&Play" ) ), ActionPlay );
|
||||
|
||||
if ( m_supportedActions & ActionQueue )
|
||||
m_sigmap->setMapping( addAction( tr( "Add to &Queue" ) ), ActionQueue );
|
||||
|
||||
//m_sigmap->setMapping( addAction( tr( "&Add to Playlist" ) ), ActionAddToPlaylist );
|
||||
|
||||
addSeparator();
|
||||
|
||||
/* if ( m_supportedActions & ActionCopyLink && itemCount() == 1 )
|
||||
m_sigmap->setMapping( addAction( tr( "Copy Album &Link" ) ), ActionCopyLink ); */
|
||||
|
||||
foreach ( QAction* action, actions() )
|
||||
{
|
||||
connect( action, SIGNAL( triggered() ), m_sigmap, SLOT( map() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setAlbum( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
QList<album_ptr> albums;
|
||||
albums << album;
|
||||
setAlbums( albums );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setArtists( const QList<Tomahawk::artist_ptr>& artists )
|
||||
{
|
||||
if ( artists.isEmpty() )
|
||||
return;
|
||||
|
||||
QMenu::clear();
|
||||
m_artists.clear();
|
||||
m_artists << artists;
|
||||
|
||||
if ( m_supportedActions & ActionPlay )
|
||||
m_sigmap->setMapping( addAction( tr( "&Play" ) ), ActionPlay );
|
||||
|
||||
if ( m_supportedActions & ActionQueue )
|
||||
m_sigmap->setMapping( addAction( tr( "Add to &Queue" ) ), ActionQueue );
|
||||
|
||||
//m_sigmap->setMapping( addAction( tr( "&Add to Playlist" ) ), ActionAddToPlaylist );
|
||||
|
||||
addSeparator();
|
||||
|
||||
/* if ( m_supportedActions & ActionCopyLink && itemCount() == 1 )
|
||||
m_sigmap->setMapping( addAction( tr( "Copy Artist &Link" ) ), ActionCopyLink ); */
|
||||
|
||||
foreach ( QAction* action, actions() )
|
||||
{
|
||||
connect( action, SIGNAL( triggered() ), m_sigmap, SLOT( map() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setArtist( const Tomahawk::artist_ptr& artist )
|
||||
{
|
||||
QList<artist_ptr> artists;
|
||||
artists << artist;
|
||||
setArtists( artists );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::onTriggered( int action )
|
||||
{
|
||||
@ -102,11 +193,16 @@ void ContextMenu::addToQueue()
|
||||
{
|
||||
foreach ( const query_ptr& query, m_queries )
|
||||
{
|
||||
if ( !query->resolvingFinished() )
|
||||
Pipeline::instance()->resolve( query );
|
||||
|
||||
ViewManager::instance()->queue()->model()->append( query );
|
||||
}
|
||||
foreach ( const artist_ptr& artist, m_artists )
|
||||
{
|
||||
ViewManager::instance()->queue()->model()->append( artist );
|
||||
}
|
||||
foreach ( const album_ptr& album, m_albums )
|
||||
{
|
||||
ViewManager::instance()->queue()->model()->append( album );
|
||||
}
|
||||
|
||||
ViewManager::instance()->showQueue();
|
||||
}
|
||||
|
@ -45,6 +45,16 @@ public:
|
||||
void setQuery( const Tomahawk::query_ptr& query );
|
||||
void setQueries( const QList<Tomahawk::query_ptr>& queries );
|
||||
|
||||
void setArtist( const Tomahawk::artist_ptr& artist );
|
||||
void setArtists( const QList<Tomahawk::artist_ptr>& artists );
|
||||
|
||||
void setAlbum( const Tomahawk::album_ptr& album );
|
||||
void setAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||
|
||||
void clear();
|
||||
|
||||
unsigned int itemCount() const { return m_queries.count() + m_artists.count() + m_albums.count(); }
|
||||
|
||||
signals:
|
||||
void triggered( int action );
|
||||
|
||||
@ -57,7 +67,10 @@ private slots:
|
||||
private:
|
||||
QSignalMapper* m_sigmap;
|
||||
int m_supportedActions;
|
||||
|
||||
QList<Tomahawk::query_ptr> m_queries;
|
||||
QList<Tomahawk::artist_ptr> m_artists;
|
||||
QList<Tomahawk::album_ptr> m_albums;
|
||||
};
|
||||
|
||||
}; // ns
|
||||
|
@ -257,6 +257,8 @@ ArtistView::onScrollTimeout()
|
||||
void
|
||||
ArtistView::onCustomContextMenu( const QPoint& pos )
|
||||
{
|
||||
m_contextMenu->clear();
|
||||
|
||||
QModelIndex idx = indexAt( pos );
|
||||
idx = idx.sibling( idx.row(), 0 );
|
||||
m_contextMenuIndex = idx;
|
||||
@ -265,17 +267,28 @@ ArtistView::onCustomContextMenu( const QPoint& pos )
|
||||
return;
|
||||
|
||||
QList<query_ptr> queries;
|
||||
QList<artist_ptr> artists;
|
||||
QList<album_ptr> albums;
|
||||
|
||||
foreach ( const QModelIndex& index, selectedIndexes() )
|
||||
{
|
||||
if ( index.column() )
|
||||
if ( index.column() || selectedIndexes().contains( index.parent() ) )
|
||||
continue;
|
||||
|
||||
TreeModelItem* item = m_proxyModel->itemFromIndex( m_proxyModel->mapToSource( index ) );
|
||||
|
||||
if ( item && !item->result().isNull() )
|
||||
queries << item->result()->toQuery();
|
||||
if ( item && !item->artist().isNull() )
|
||||
artists << item->artist();
|
||||
if ( item && !item->album().isNull() )
|
||||
albums << item->album();
|
||||
}
|
||||
|
||||
m_contextMenu->setQueries( queries );
|
||||
m_contextMenu->setArtists( artists );
|
||||
m_contextMenu->setAlbums( albums );
|
||||
|
||||
m_contextMenu->exec( mapToGlobal( pos ) );
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,8 @@ public:
|
||||
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllTracks::SortOrder order );
|
||||
|
||||
virtual void append( const Tomahawk::query_ptr& /*query*/ ) {}
|
||||
virtual void append( const Tomahawk::artist_ptr& /*artist*/ ) {}
|
||||
virtual void append( const Tomahawk::album_ptr& /*album*/ ) {}
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <QTreeView>
|
||||
|
||||
#include "album.h"
|
||||
|
||||
#include "pipeline.h"
|
||||
#include "database/database.h"
|
||||
#include "database/databasecommand_playbackhistory.h"
|
||||
#include "dynamic/GeneratorInterface.h"
|
||||
@ -188,6 +188,9 @@ PlaylistModel::append( const Tomahawk::query_ptr& query )
|
||||
QList< Tomahawk::query_ptr > ql;
|
||||
ql << query;
|
||||
|
||||
if ( !query->resolvingFinished() )
|
||||
Pipeline::instance()->resolve( query );
|
||||
|
||||
onTracksAdded( ql );
|
||||
}
|
||||
|
||||
@ -201,7 +204,8 @@ PlaylistModel::append( const Tomahawk::album_ptr& album )
|
||||
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
if( rowCount( QModelIndex() ) == 0 ) {
|
||||
if ( rowCount( QModelIndex() ) == 0 )
|
||||
{
|
||||
setTitle( album->name() );
|
||||
setDescription( tr( "All tracks by %1 on album %2" ).arg( album->artist()->name() ).arg( album->name() ) );
|
||||
m_isTemporary = true;
|
||||
@ -220,7 +224,8 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist )
|
||||
connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
if( rowCount( QModelIndex() ) == 0 ) {
|
||||
if ( rowCount( QModelIndex() ) == 0 )
|
||||
{
|
||||
setTitle( artist->name() );
|
||||
setDescription( tr( "All tracks by %1" ).arg( artist->name() ) );
|
||||
m_isTemporary = true;
|
||||
|
@ -89,6 +89,8 @@ public:
|
||||
virtual void ensureResolved();
|
||||
|
||||
virtual void append( const Tomahawk::query_ptr& query ) = 0;
|
||||
virtual void append( const Tomahawk::artist_ptr& artist ) = 0;
|
||||
virtual void append( const Tomahawk::album_ptr& album ) = 0;
|
||||
|
||||
TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
|
||||
|
||||
|
@ -394,6 +394,8 @@ TrackView::startDrag( Qt::DropActions supportedActions )
|
||||
void
|
||||
TrackView::onCustomContextMenu( const QPoint& pos )
|
||||
{
|
||||
m_contextMenu->clear();
|
||||
|
||||
QModelIndex idx = indexAt( pos );
|
||||
idx = idx.sibling( idx.row(), 0 );
|
||||
setContextMenuIndex( idx );
|
||||
|
Loading…
x
Reference in New Issue
Block a user