mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
* Updated Album- & PlaylistChartItemDelegate.
This commit is contained in:
@@ -119,21 +119,28 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
painter->setFont( boldFont );
|
painter->setFont( boldFont );
|
||||||
painter->setPen( option.palette.text().color().lighter( 450 ) );
|
painter->setPen( option.palette.text().color().lighter( 450 ) );
|
||||||
|
|
||||||
QRect figureRect = r.adjusted( 4, 0, 0, 0 );
|
QRect figureRect = r.adjusted( 4, 0, 0, 0 );
|
||||||
figureRect.setWidth( QFontMetrics( painter->font() ).width( "888" ) );
|
figureRect.setWidth( QFontMetrics( painter->font() ).width( "888" ) );
|
||||||
painter->drawText( figureRect, QString::number( index.row() + 1 ), QTextOption( Qt::AlignCenter ) );
|
painter->drawText( figureRect, QString::number( index.row() + 1 ), QTextOption( Qt::AlignCenter ) );
|
||||||
|
|
||||||
r.adjust( figureRect.width() + 12, 0, 0, 0 );
|
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 );
|
QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
|
||||||
|
QRect leftRect = r.adjusted( 0, 0, -( rightRect.width() + 8 ), 0 );
|
||||||
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
|
|
||||||
painter->setPen( opt.palette.text().color() );
|
|
||||||
painter->drawText( leftRect, text, m_centerOption );
|
|
||||||
|
|
||||||
const int sourceIconSize = r.height();
|
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 ) );
|
const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) );
|
||||||
painter->setOpacity( 0.8 );
|
painter->setOpacity( 0.8 );
|
||||||
@@ -142,6 +149,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
|
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 )
|
if ( duration > 0 )
|
||||||
{
|
{
|
||||||
painter->setPen( opt.palette.text().color() );
|
painter->setPen( opt.palette.text().color() );
|
||||||
|
@@ -43,7 +43,7 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
|
|
||||||
PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, PlayableProxyModel* proxy )
|
PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, PlayableProxyModel* proxy )
|
||||||
: QStyledItemDelegate( (QObject*)parent )
|
: PlaylistItemDelegate( parent, proxy )
|
||||||
, m_view( parent )
|
, m_view( parent )
|
||||||
, m_model( proxy )
|
, m_model( proxy )
|
||||||
{
|
{
|
||||||
@@ -59,11 +59,8 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, Playabl
|
|||||||
m_bottomOption = QTextOption( Qt::AlignBottom );
|
m_bottomOption = QTextOption( Qt::AlignBottom );
|
||||||
m_bottomOption.setWrapMode( QTextOption::NoWrap );
|
m_bottomOption.setWrapMode( QTextOption::NoWrap );
|
||||||
|
|
||||||
connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) );
|
connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) );
|
||||||
|
connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) );
|
||||||
connect( m_model, SIGNAL( modelReset() ), this, SLOT( modelChanged() ) );
|
|
||||||
if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) )
|
|
||||||
connect( plView, SIGNAL( modelChanged() ), this, 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
|
void
|
||||||
PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
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 );
|
painter->drawPixmap( pixmapRect, pixmap );
|
||||||
|
|
||||||
r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
|
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 );
|
painter->setFont( boldFont );
|
||||||
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
|
QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
|
||||||
@@ -216,10 +226,9 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
|
|
||||||
if ( duration > 0 )
|
if ( duration > 0 )
|
||||||
{
|
{
|
||||||
|
painter->setPen( opt.palette.text().color() );
|
||||||
painter->setFont( durationFont );
|
painter->setFont( durationFont );
|
||||||
QRect rightRect = r.adjusted( r.width() - durationFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
|
painter->drawText( rightRect, TomahawkUtils::timeToString( duration ), m_centerRightOption );
|
||||||
text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() );
|
|
||||||
painter->drawText( rightRect, text, m_centerRightOption );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
@@ -229,7 +238,8 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
void
|
void
|
||||||
PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
||||||
{
|
{
|
||||||
emit updateIndex( idx );
|
if ( idx.isValid() )
|
||||||
|
emit updateIndex( idx );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -19,9 +19,9 @@
|
|||||||
#ifndef PLAYLISTCHARTITEMDELEGATE_H
|
#ifndef PLAYLISTCHARTITEMDELEGATE_H
|
||||||
#define PLAYLISTCHARTITEMDELEGATE_H
|
#define PLAYLISTCHARTITEMDELEGATE_H
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
|
||||||
#include <QTextOption>
|
#include <QTextOption>
|
||||||
|
|
||||||
|
#include "PlaylistItemDelegate.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
@@ -35,36 +35,32 @@ class PlayableItem;
|
|||||||
class PlayableProxyModel;
|
class PlayableProxyModel;
|
||||||
class TrackView;
|
class TrackView;
|
||||||
|
|
||||||
class DLLEXPORT PlaylistChartItemDelegate : public QStyledItemDelegate
|
class DLLEXPORT PlaylistChartItemDelegate : public PlaylistItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlaylistChartItemDelegate( TrackView* parent = 0, PlayableProxyModel* proxy = 0 );
|
PlaylistChartItemDelegate( TrackView* parent = 0, PlayableProxyModel* proxy = 0 );
|
||||||
|
|
||||||
signals:
|
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
void updateIndex( const QModelIndex& idx );
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void modelChanged();
|
|
||||||
void doUpdateIndex( const QPersistentModelIndex& idx );
|
void doUpdateIndex( const QPersistentModelIndex& idx );
|
||||||
|
void modelChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ) const;
|
|
||||||
|
|
||||||
QTextOption m_topOption;
|
QTextOption m_topOption;
|
||||||
QTextOption m_centerOption;
|
QTextOption m_centerOption;
|
||||||
QTextOption m_centerRightOption;
|
QTextOption m_centerRightOption;
|
||||||
QTextOption m_bottomOption;
|
QTextOption m_bottomOption;
|
||||||
|
|
||||||
|
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
||||||
|
|
||||||
TrackView* m_view;
|
TrackView* m_view;
|
||||||
PlayableProxyModel* m_model;
|
PlayableProxyModel* m_model;
|
||||||
|
|
||||||
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYLISTCHARTITEMDELEGATE_H
|
#endif // PLAYLISTCHARTITEMDELEGATE_H
|
||||||
|
Reference in New Issue
Block a user