1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-31 06:02:27 +02:00

* Fix the styling of the now playing row in the TreeView.

This commit is contained in:
Christian Muehlhaeuser 2011-06-23 20:02:26 +02:00
parent 2ef67f5b28
commit d5266f7147
4 changed files with 31 additions and 12 deletions

View File

@ -258,8 +258,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
if ( m_view->header()->visualIndex( index.column() ) == 0 )
{
r.adjust( 0, 0, 0, -3 );
painter->drawPixmap( r.adjusted( 3, 3, 18 - r.width(), 0 ), m_nowPlayingIcon );
r.adjust( 22, 0, 0, 3 );
painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
r.adjust( 25, 0, 0, 3 );
}
painter->setPen( opt.palette.text().color() );

View File

@ -22,6 +22,7 @@
#include <QDebug>
#include <QPainter>
#include <QAbstractItemView>
#include <QHeaderView>
#include "query.h"
#include "result.h"
@ -30,13 +31,15 @@
#include "treemodelitem.h"
#include "treeproxymodel.h"
#include "artistview.h"
TreeItemDelegate::TreeItemDelegate( QAbstractItemView* parent, TreeProxyModel* proxy )
TreeItemDelegate::TreeItemDelegate( ArtistView* parent, TreeProxyModel* proxy )
: QStyledItemDelegate( (QObject*)parent )
, m_view( parent )
, m_model( proxy )
{
m_nowPlayingIcon = QPixmap( RESPATH "images/now-playing-speaker.png" );
}
@ -82,8 +85,27 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
o.state |= QStyle::State_Selected;
}
return QStyledItemDelegate::paint( painter, o, index );
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &o, painter );
{
QRect r = o.rect.adjusted( 3, 0, 0, 0 );
// Paint Now Playing Speaker Icon
if ( item->isPlaying() && m_view->header()->visualIndex( index.column() ) == 0 )
{
r.adjust( 0, 0, 0, -3 );
painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
r.adjust( 25, 0, 0, 3 );
}
painter->setPen( o.palette.text().color() );
QTextOption to( Qt::AlignVCenter );
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to );
}
}
return;
}
else
return;

View File

@ -23,6 +23,7 @@
#include "dllmacro.h"
class ArtistView;
class TreeProxyModel;
class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate
@ -30,7 +31,7 @@ class DLLEXPORT TreeItemDelegate : public QStyledItemDelegate
Q_OBJECT
public:
TreeItemDelegate( QAbstractItemView* parent = 0, TreeProxyModel* proxy = 0 );
TreeItemDelegate( ArtistView* parent = 0, TreeProxyModel* proxy = 0 );
protected:
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
@ -39,8 +40,10 @@ protected:
// QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private:
QAbstractItemView* m_view;
ArtistView* m_view;
TreeProxyModel* m_model;
QPixmap m_nowPlayingIcon;
};
#endif // TREEITEMDELEGATE_H

View File

@ -215,12 +215,6 @@ 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();