1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Updated Album- & PlaylistChartItemDelegate.

This commit is contained in:
Christian Muehlhaeuser 2013-04-17 06:45:14 +02:00
parent 618dff77e4
commit 9830b20ca1
3 changed files with 54 additions and 37 deletions

@ -119,21 +119,28 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setFont( boldFont );
painter->setPen( option.palette.text().color().lighter( 450 ) );
QRect figureRect = r.adjusted( 4, 0, 0, 0 );
figureRect.setWidth( QFontMetrics( painter->font() ).width( "888" ) );
painter->drawText( figureRect, QString::number( index.row() + 1 ), QTextOption( Qt::AlignCenter ) );
r.adjust( figureRect.width() + 12, 0, 0, 0 );
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
painter->setPen( opt.palette.text().color() );
painter->drawText( leftRect, text, m_centerOption );
QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 );
const int sourceIconSize = r.height();
if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
if ( hoveringOver() == index && index.column() == 0 )
{
const QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, QSize( sourceIconSize, sourceIconSize ) );
QRect arrowRect = QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, infoIcon.width(), infoIcon.height() );
painter->drawPixmap( arrowRect, infoIcon );
setInfoButtonRect( index, arrowRect );
rightRect.moveLeft( rightRect.left() - infoIcon.width() - 8 );
leftRect.adjust( 0, 0, -( infoIcon.width() + 8 ), 0 );
}
else if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
{
const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) );
painter->setOpacity( 0.8 );
@ -142,6 +149,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
}
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
painter->setPen( opt.palette.text().color() );
painter->drawText( leftRect, text, m_centerOption );
if ( duration > 0 )
{
painter->setPen( opt.palette.text().color() );

@ -43,7 +43,7 @@ using namespace Tomahawk;
PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, PlayableProxyModel* proxy )
: QStyledItemDelegate( (QObject*)parent )
: PlaylistItemDelegate( parent, proxy )
, m_view( parent )
, m_model( proxy )
{
@ -59,11 +59,8 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, Playabl
m_bottomOption = QTextOption( Qt::AlignBottom );
m_bottomOption.setWrapMode( QTextOption::NoWrap );
connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) );
connect( m_model, SIGNAL( modelReset() ), this, SLOT( modelChanged() ) );
if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) )
connect( plView, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) );
connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) );
}
@ -99,15 +96,6 @@ PlaylistChartItemDelegate::sizeHint( const QStyleOptionViewItem& option, const Q
}
void
PlaylistChartItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const
{
initStyleOption( option, index );
TomahawkUtils::prepareStyleOption( option, index, item );
}
void
PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
@ -204,7 +192,29 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
painter->drawPixmap( pixmapRect, pixmap );
r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
QRect leftRect = r.adjusted( 0, 0, -durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ) - 8, 0 );
QRect rightRect = r.adjusted( r.width() - durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 );
/* const int sourceIconSize = r.height();
if ( hoveringOver() == index && index.column() == 0 )
{
const QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, QSize( sourceIconSize, sourceIconSize ) );
QRect arrowRect = QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, infoIcon.width(), infoIcon.height() );
painter->drawPixmap( arrowRect, infoIcon );
setInfoButtonRect( index, arrowRect );
rightRect.moveLeft( rightRect.left() - infoIcon.width() - 8 );
leftRect.adjust( 0, 0, -( infoIcon.width() + 8 ), 0 );
}
else if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
{
const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) );
painter->setOpacity( 0.8 );
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
painter->setOpacity( 1.0 );
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
}*/
painter->setFont( boldFont );
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
@ -216,10 +226,9 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
if ( duration > 0 )
{
painter->setPen( opt.palette.text().color() );
painter->setFont( durationFont );
QRect rightRect = r.adjusted( r.width() - durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() );
painter->drawText( rightRect, text, m_centerRightOption );
painter->drawText( rightRect, TomahawkUtils::timeToString( duration ), m_centerRightOption );
}
}
painter->restore();
@ -229,7 +238,8 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
void
PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
{
emit updateIndex( idx );
if ( idx.isValid() )
emit updateIndex( idx );
}

@ -19,9 +19,9 @@
#ifndef PLAYLISTCHARTITEMDELEGATE_H
#define PLAYLISTCHARTITEMDELEGATE_H
#include <QStyledItemDelegate>
#include <QTextOption>
#include "PlaylistItemDelegate.h"
#include "DllMacro.h"
#include "Typedefs.h"
@ -35,36 +35,32 @@ class PlayableItem;
class PlayableProxyModel;
class TrackView;
class DLLEXPORT PlaylistChartItemDelegate : public QStyledItemDelegate
class DLLEXPORT PlaylistChartItemDelegate : public PlaylistItemDelegate
{
Q_OBJECT
public:
PlaylistChartItemDelegate( TrackView* parent = 0, PlayableProxyModel* proxy = 0 );
signals:
void updateIndex( const QModelIndex& idx );
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
protected:
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private slots:
void modelChanged();
void doUpdateIndex( const QPersistentModelIndex& idx );
void modelChanged();
private:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
QTextOption m_topOption;
QTextOption m_centerOption;
QTextOption m_centerRightOption;
QTextOption m_bottomOption;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
TrackView* m_view;
PlayableProxyModel* m_model;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
};
#endif // PLAYLISTCHARTITEMDELEGATE_H