1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 19:37:09 +02:00

* Mark the now playing item in the TreeView, just like we do in the TrackView.

This commit is contained in:
Christian Muehlhaeuser
2011-06-23 19:25:59 +02:00
parent 337c4e6e9c
commit 2ef67f5b28
5 changed files with 62 additions and 0 deletions

View File

@@ -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 );
}
}

View File

@@ -23,6 +23,7 @@
#include <QMimeData>
#include <QNetworkReply>
#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()
{

View File

@@ -91,7 +91,9 @@ public:
TreeModelItem* itemFromIndex( const QModelIndex& index ) const
{
if ( index.isValid() )
{
return static_cast<TreeModelItem*>( 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:

View File

@@ -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 )
{

View File

@@ -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