diff --git a/src/libtomahawk/playlist/treeitemdelegate.cpp b/src/libtomahawk/playlist/treeitemdelegate.cpp index 3d499649d..3ad8e2cc8 100644 --- a/src/libtomahawk/playlist/treeitemdelegate.cpp +++ b/src/libtomahawk/playlist/treeitemdelegate.cpp @@ -74,6 +74,14 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, { QStyleOptionViewItemV4 o( *vioption ); o.palette.setColor( QPalette::Text, textColor ); + + if ( item->isPlaying() ) + { + o.palette.setColor( QPalette::Highlight, o.palette.color( QPalette::Mid ) ); + o.palette.setColor( QPalette::Text, o.palette.color( QPalette::HighlightedText ) ); + o.state |= QStyle::State_Selected; + } + return QStyledItemDelegate::paint( painter, o, index ); } } diff --git a/src/libtomahawk/playlist/treemodel.cpp b/src/libtomahawk/playlist/treemodel.cpp index eaa83f07a..020a21a78 100644 --- a/src/libtomahawk/playlist/treemodel.cpp +++ b/src/libtomahawk/playlist/treemodel.cpp @@ -23,6 +23,7 @@ #include #include +#include "audio/audioengine.h" #include "database/databasecommand_allalbums.h" #include "database/databasecommand_alltracks.h" #include "database/database.h" @@ -42,6 +43,9 @@ TreeModel::TreeModel( QObject* parent ) m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" ) .scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); + connect( AudioEngine::instance(), SIGNAL( finished( Tomahawk::result_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::result_ptr ) ), Qt::DirectConnection ); + connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection ); + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ), SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) ); @@ -60,10 +64,17 @@ TreeModel::setCurrentItem( const QModelIndex& index ) { qDebug() << Q_FUNC_INFO; + TreeModelItem* oldEntry = itemFromIndex( m_currentIndex ); + if ( oldEntry ) + { + oldEntry->setIsPlaying( false ); + } + TreeModelItem* entry = itemFromIndex( index ); if ( entry ) { m_currentIndex = index; + entry->setIsPlaying( true ); } else { @@ -204,6 +215,12 @@ TreeModel::data( const QModelIndex& index, int role ) const return QSize( 128, 0 ); } + if ( role == Qt::DecorationRole ) + { + if ( entry->isPlaying() && index.column() == 0 ) + return QPixmap( RESPATH "images/now-playing-speaker.png" ); + } + if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) return QVariant(); @@ -618,6 +635,29 @@ TreeModel::infoSystemFinished( QString target ) } +void +TreeModel::onPlaybackFinished( const Tomahawk::result_ptr& result ) +{ + TreeModelItem* oldEntry = itemFromIndex( m_currentIndex ); + qDebug() << oldEntry->result().data() << result.data(); + if ( oldEntry && !oldEntry->result().isNull() && oldEntry->result().data() == result.data() ) + { + oldEntry->setIsPlaying( false ); + } +} + + +void +TreeModel::onPlaybackStopped() +{ + TreeModelItem* oldEntry = itemFromIndex( m_currentIndex ); + if ( oldEntry ) + { + oldEntry->setIsPlaying( false ); + } +} + + void TreeModel::onDataChanged() { diff --git a/src/libtomahawk/playlist/treemodel.h b/src/libtomahawk/playlist/treemodel.h index 5e9379406..b1dae2de8 100644 --- a/src/libtomahawk/playlist/treemodel.h +++ b/src/libtomahawk/playlist/treemodel.h @@ -91,7 +91,9 @@ public: TreeModelItem* itemFromIndex( const QModelIndex& index ) const { if ( index.isValid() ) + { return static_cast( index.internalPointer() ); + } else { return m_rootItem; @@ -125,6 +127,9 @@ private slots: void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData ); void infoSystemFinished( QString target ); + void onPlaybackFinished( const Tomahawk::result_ptr& result ); + void onPlaybackStopped(); + void onDataChanged(); private: diff --git a/src/libtomahawk/playlist/treemodelitem.cpp b/src/libtomahawk/playlist/treemodelitem.cpp index 09688a56d..5406be52f 100644 --- a/src/libtomahawk/playlist/treemodelitem.cpp +++ b/src/libtomahawk/playlist/treemodelitem.cpp @@ -48,6 +48,7 @@ TreeModelItem::TreeModelItem( TreeModelItem* parent, QAbstractItemModel* model ) childCount = 0; toberemoved = false; fetchingMore = false; + m_isPlaying = false; if ( parent ) { @@ -62,6 +63,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::album_ptr& album, TreeModelItem* p { this->parent = parent; fetchingMore = false; + m_isPlaying = false; if ( parent ) { @@ -88,6 +90,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::artist_ptr& artist, TreeModelItem* { this->parent = parent; fetchingMore = false; + m_isPlaying = false; if ( parent ) { @@ -114,6 +117,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::result_ptr& result, TreeModelItem* { this->parent = parent; fetchingMore = false; + m_isPlaying = false; if ( parent ) { diff --git a/src/libtomahawk/playlist/treemodelitem.h b/src/libtomahawk/playlist/treemodelitem.h index 16538727b..01f3b226e 100644 --- a/src/libtomahawk/playlist/treemodelitem.h +++ b/src/libtomahawk/playlist/treemodelitem.h @@ -44,6 +44,9 @@ public: const Tomahawk::album_ptr& album() const { return m_album; }; const Tomahawk::result_ptr& result() const { return m_result; }; + bool isPlaying() { return m_isPlaying; } + void setIsPlaying( bool b ) { m_isPlaying = b; emit dataChanged(); } + void setCover( const QPixmap& cover ) { this->cover = cover; emit dataChanged(); } TreeModelItem* parent; @@ -64,6 +67,8 @@ private: Tomahawk::artist_ptr m_artist; Tomahawk::album_ptr m_album; Tomahawk::result_ptr m_result; + + bool m_isPlaying; }; #endif // TREEMODELITEM_H