diff --git a/src/sourcetree/items/collectionitem.cpp b/src/sourcetree/items/collectionitem.cpp index 1505c398c..2ea070168 100644 --- a/src/sourcetree/items/collectionitem.cpp +++ b/src/sourcetree/items/collectionitem.cpp @@ -29,6 +29,7 @@ #include "playlist/customplaylistview.h" #include "source.h" #include "temporarypageitem.h" +#include /// CollectionItem @@ -39,6 +40,7 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons , m_source( source ) , m_playlists( 0 ) , m_stations( 0 ) + , m_latchedOn( false ) , m_sourceInfoItem( 0 ) , m_coolPlaylistsItem( 0 ) , m_lovedTracksItem() @@ -118,6 +120,8 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons connect( source.data(), SIGNAL( stateChanged() ), this, SIGNAL( updated() ) ); connect( source.data(), SIGNAL( offline() ), this, SIGNAL( updated() ) ); connect( source.data(), SIGNAL( online() ), this, SIGNAL( updated() ) ); + connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), this, SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( onPlaylistsAdded( QList ) ), Qt::QueuedConnection ); @@ -196,6 +200,26 @@ CollectionItem::icon() const } } +void +CollectionItem::latchedOff( const source_ptr& from, const source_ptr& to ) +{ + if ( from->isLocal() && m_source == to ) + { + m_latchedOn = false; + emit updated(); + } +} + +void +CollectionItem::latchedOn( const source_ptr& from, const source_ptr& to ) +{ + if ( from->isLocal() && m_source == to ) + { + m_latchedOn = true; + emit updated(); + } +} + void CollectionItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists ) diff --git a/src/sourcetree/items/collectionitem.h b/src/sourcetree/items/collectionitem.h index 9d4385f07..9d991d228 100644 --- a/src/sourcetree/items/collectionitem.h +++ b/src/sourcetree/items/collectionitem.h @@ -42,6 +42,8 @@ public: virtual int peerSortValue() const; virtual int IDValue() const; + virtual bool localLatchedOn() const { return m_latchedOn; } + Tomahawk::source_ptr source() const; CategoryItem* stationsCategory() const { return m_stations; } @@ -57,6 +59,9 @@ private slots: void onStationsAdded( const QList& stations ); void onStationDeleted( const Tomahawk::dynplaylist_ptr& stations ); + void latchedOn( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& ); + void latchedOff( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& ); + void requestExpanding(); void tempPageActivated( Tomahawk::ViewPage* ); @@ -79,6 +84,7 @@ private: QPixmap m_superCol, m_defaultAvatar; CategoryItem* m_playlists; CategoryItem* m_stations; + bool m_latchedOn; QList< TemporaryPageItem* > m_tempItems; GenericPageItem* m_sourceInfoItem; diff --git a/src/sourcetree/sourcedelegate.cpp b/src/sourcetree/sourcedelegate.cpp index 020bc9c8e..348332888 100644 --- a/src/sourcetree/sourcedelegate.cpp +++ b/src/sourcetree/sourcedelegate.cpp @@ -53,13 +53,15 @@ SourceDelegate::SourceDelegate( QAbstractItemView* parent ) m_dropTypeTextMap.insert( 3, tr( "Local" ) ); m_dropTypeTextMap.insert( 4, tr( "Top 10" ) ); - m_dropTypeImageMap.insert( 0, QPixmap( ":/data/images/drop-song.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); - m_dropTypeImageMap.insert( 1, QPixmap( ":/data/images/drop-album.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); - m_dropTypeImageMap.insert( 2, QPixmap( ":/data/images/drop-all-songs.png" ).scaledToHeight( 32, Qt::SmoothTransformation ) ); - m_dropTypeImageMap.insert( 3, QPixmap( ":/data/images/drop-local-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); - m_dropTypeImageMap.insert( 4, QPixmap( ":/data/images/drop-top-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + m_dropTypeImageMap.insert( 0, QPixmap( RESPATH "images/drop-song.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + m_dropTypeImageMap.insert( 1, QPixmap( RESPATH "images/drop-album.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + m_dropTypeImageMap.insert( 2, QPixmap( RESPATH "images/drop-all-songs.png" ).scaledToHeight( 32, Qt::SmoothTransformation ) ); + m_dropTypeImageMap.insert( 3, QPixmap( RESPATH "images/drop-local-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); + m_dropTypeImageMap.insert( 4, QPixmap( RESPATH "images/drop-top-songs.png" ).scaledToWidth( 32, Qt::SmoothTransformation ) ); m_dropMimeData = new QMimeData(); + + m_headphones.load( RESPATH "images/headphones.png" ); } @@ -156,7 +158,16 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co QRect iconRect = option.rect.adjusted( 4, 6, -option.rect.width() + option.rect.height() - 12 + 4, -6 ); QPixmap avatar = colItem->icon().pixmap( iconRect.size() ); - painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); + if ( index.data( SourcesModel::LatchedOnRole ).toBool() && !m_headphones.isNull() ) + { + // Draw headphones around the source + painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); +// painter->drawPixmap( iconRect, m_headphones.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); +// QRect inHeadphones = iconRect.adjusted( 5, 10, -5, 0); +// painter->drawPixmap( inHeadphones, avatar.scaledToHeight( inHeadphones.height(), Qt::SmoothTransformation ) ); + } + else + painter->drawPixmap( iconRect, avatar.scaledToHeight( iconRect.height(), Qt::SmoothTransformation ) ); if ( ( option.state & QStyle::State_Selected ) == QStyle::State_Selected ) { diff --git a/src/sourcetree/sourcedelegate.h b/src/sourcetree/sourcedelegate.h index 7d3d88f15..7d53c35de 100644 --- a/src/sourcetree/sourcedelegate.h +++ b/src/sourcetree/sourcedelegate.h @@ -59,6 +59,7 @@ private: QMimeData *m_dropMimeData; mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint() QMap< QModelIndex, AnimationHelper* > m_expandedMap; + QPixmap m_headphones; QMap< int, SourceTreeItem::DropType > m_dropTypeMap; QMap< int, QString > m_dropTypeTextMap; diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index 41f27dddf..601c4a258 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -110,6 +110,15 @@ SourcesModel::data( const QModelIndex& index, int role ) const return itemFromIndex( index )->peerSortValue(); case SourcesModel::IDRole: return itemFromIndex( index )->IDValue(); + case SourcesModel::LatchedOnRole: + { + if ( itemFromIndex( index )->type() == Collection ) + { + CollectionItem* cItem = qobject_cast< CollectionItem* >( itemFromIndex( index ) ); + return cItem->localLatchedOn(); + } + return false; + } } return QVariant(); } diff --git a/src/sourcetree/sourcesmodel.h b/src/sourcetree/sourcesmodel.h index 234a299c3..7e9dc08f2 100644 --- a/src/sourcetree/sourcesmodel.h +++ b/src/sourcetree/sourcesmodel.h @@ -64,7 +64,8 @@ public: SourceTreeItemRole = Qt::UserRole + 10, SourceTreeItemTypeRole = Qt::UserRole + 11, SortRole = Qt::UserRole + 12, - IDRole = Qt::UserRole + 13 + IDRole = Qt::UserRole + 13, + LatchedOnRole = Qt::UserRole + 14 }; SourcesModel( QObject* parent = 0 );