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:
@@ -74,6 +74,14 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
{
|
{
|
||||||
QStyleOptionViewItemV4 o( *vioption );
|
QStyleOptionViewItemV4 o( *vioption );
|
||||||
o.palette.setColor( QPalette::Text, textColor );
|
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 );
|
return QStyledItemDelegate::paint( painter, o, index );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
#include "audio/audioengine.h"
|
||||||
#include "database/databasecommand_allalbums.h"
|
#include "database/databasecommand_allalbums.h"
|
||||||
#include "database/databasecommand_alltracks.h"
|
#include "database/databasecommand_alltracks.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
@@ -42,6 +43,9 @@ TreeModel::TreeModel( QObject* parent )
|
|||||||
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
|
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
|
||||||
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
.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(),
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||||
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
|
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
|
||||||
SLOT( infoSystemInfo( 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;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
|
TreeModelItem* oldEntry = itemFromIndex( m_currentIndex );
|
||||||
|
if ( oldEntry )
|
||||||
|
{
|
||||||
|
oldEntry->setIsPlaying( false );
|
||||||
|
}
|
||||||
|
|
||||||
TreeModelItem* entry = itemFromIndex( index );
|
TreeModelItem* entry = itemFromIndex( index );
|
||||||
if ( entry )
|
if ( entry )
|
||||||
{
|
{
|
||||||
m_currentIndex = index;
|
m_currentIndex = index;
|
||||||
|
entry->setIsPlaying( true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -204,6 +215,12 @@ TreeModel::data( const QModelIndex& index, int role ) const
|
|||||||
return QSize( 128, 0 );
|
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 )
|
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
|
||||||
return QVariant();
|
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
|
void
|
||||||
TreeModel::onDataChanged()
|
TreeModel::onDataChanged()
|
||||||
{
|
{
|
||||||
|
@@ -91,7 +91,9 @@ public:
|
|||||||
TreeModelItem* itemFromIndex( const QModelIndex& index ) const
|
TreeModelItem* itemFromIndex( const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
if ( index.isValid() )
|
if ( index.isValid() )
|
||||||
|
{
|
||||||
return static_cast<TreeModelItem*>( index.internalPointer() );
|
return static_cast<TreeModelItem*>( index.internalPointer() );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return m_rootItem;
|
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 infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||||
void infoSystemFinished( QString target );
|
void infoSystemFinished( QString target );
|
||||||
|
|
||||||
|
void onPlaybackFinished( const Tomahawk::result_ptr& result );
|
||||||
|
void onPlaybackStopped();
|
||||||
|
|
||||||
void onDataChanged();
|
void onDataChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -48,6 +48,7 @@ TreeModelItem::TreeModelItem( TreeModelItem* parent, QAbstractItemModel* model )
|
|||||||
childCount = 0;
|
childCount = 0;
|
||||||
toberemoved = false;
|
toberemoved = false;
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
m_isPlaying = false;
|
||||||
|
|
||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
@@ -62,6 +63,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::album_ptr& album, TreeModelItem* p
|
|||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
m_isPlaying = false;
|
||||||
|
|
||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
@@ -88,6 +90,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::artist_ptr& artist, TreeModelItem*
|
|||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
m_isPlaying = false;
|
||||||
|
|
||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
@@ -114,6 +117,7 @@ TreeModelItem::TreeModelItem( const Tomahawk::result_ptr& result, TreeModelItem*
|
|||||||
{
|
{
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
fetchingMore = false;
|
fetchingMore = false;
|
||||||
|
m_isPlaying = false;
|
||||||
|
|
||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
|
@@ -44,6 +44,9 @@ public:
|
|||||||
const Tomahawk::album_ptr& album() const { return m_album; };
|
const Tomahawk::album_ptr& album() const { return m_album; };
|
||||||
const Tomahawk::result_ptr& result() const { return m_result; };
|
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(); }
|
void setCover( const QPixmap& cover ) { this->cover = cover; emit dataChanged(); }
|
||||||
|
|
||||||
TreeModelItem* parent;
|
TreeModelItem* parent;
|
||||||
@@ -64,6 +67,8 @@ private:
|
|||||||
Tomahawk::artist_ptr m_artist;
|
Tomahawk::artist_ptr m_artist;
|
||||||
Tomahawk::album_ptr m_album;
|
Tomahawk::album_ptr m_album;
|
||||||
Tomahawk::result_ptr m_result;
|
Tomahawk::result_ptr m_result;
|
||||||
|
|
||||||
|
bool m_isPlaying;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TREEMODELITEM_H
|
#endif // TREEMODELITEM_H
|
||||||
|
Reference in New Issue
Block a user