1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-02 20:28:14 +02:00

* A few more improvements to TrackView & PlaylistItemDelegate.

This commit is contained in:
Christian Muehlhaeuser
2011-08-01 09:51:24 +02:00
parent cf56819b0c
commit de508c049b
3 changed files with 26 additions and 13 deletions

View File

@@ -48,6 +48,15 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel*
{ {
m_nowPlayingIcon = QPixmap( PLAYING_ICON ); m_nowPlayingIcon = QPixmap( PLAYING_ICON );
m_arrowIcon = QPixmap( ARROW_ICON ).scaled( 14, 14, Qt::KeepAspectRatio, Qt::SmoothTransformation ); m_arrowIcon = QPixmap( ARROW_ICON ).scaled( 14, 14, Qt::KeepAspectRatio, Qt::SmoothTransformation );
m_topOption = QTextOption( Qt::AlignTop );
m_topOption.setWrapMode( QTextOption::NoWrap );
m_bottomOption = QTextOption( Qt::AlignBottom );
m_bottomOption.setWrapMode( QTextOption::NoWrap );
m_centerOption = QTextOption( Qt::AlignVCenter );
m_centerOption.setWrapMode( QTextOption::NoWrap );
} }
@@ -214,16 +223,13 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
boldFont.setBold( true ); boldFont.setBold( true );
r.adjust( ir.width() + 12, 0, -12, 0 ); r.adjust( ir.width() + 12, 0, -12, 0 );
QTextOption to( Qt::AlignTop );
to.setWrapMode( QTextOption::NoWrap );
painter->setFont( boldFont ); painter->setFont( boldFont );
QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() ); QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );
to.setAlignment( Qt::AlignBottom );
painter->setFont( opt.font ); painter->setFont( opt.font );
text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() ); text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
} }
painter->restore(); painter->restore();
} }
@@ -285,19 +291,15 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
} }
painter->setPen( opt.palette.text().color() ); painter->setPen( opt.palette.text().color() );
QTextOption to( Qt::AlignVCenter );
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 ); QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, to ); painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_centerOption );
} }
} }
else else
{ {
painter->setPen( opt.palette.text().color() ); painter->setPen( opt.palette.text().color() );
QTextOption to( Qt::AlignVCenter );
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 3 ); QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 3 );
painter->drawText( opt.rect.adjusted( 3, 1, 0, 0 ), text, to ); painter->drawText( opt.rect.adjusted( 3, 1, 0, 0 ), text, m_centerOption );
} }
painter->restore(); painter->restore();

View File

@@ -20,6 +20,7 @@
#define PLAYLISTITEMDELEGATE_H #define PLAYLISTITEMDELEGATE_H
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTextOption>
#include "trackmodel.h" #include "trackmodel.h"
@@ -57,6 +58,10 @@ private:
QPixmap m_nowPlayingIcon; QPixmap m_nowPlayingIcon;
QPixmap m_arrowIcon; QPixmap m_arrowIcon;
QTextOption m_topOption;
QTextOption m_centerOption;
QTextOption m_bottomOption;
TrackView* m_view; TrackView* m_view;
TrackProxyModel* m_model; TrackProxyModel* m_model;
}; };

View File

@@ -462,6 +462,7 @@ TrackView::updateHoverIndex( const QPoint& pos )
} }
} }
if ( cursor().shape() != Qt::ArrowCursor )
setCursor( Qt::ArrowCursor ); setCursor( Qt::ArrowCursor );
} }
@@ -470,7 +471,12 @@ void
TrackView::wheelEvent( QWheelEvent* event ) TrackView::wheelEvent( QWheelEvent* event )
{ {
QTreeView::wheelEvent( event ); QTreeView::wheelEvent( event );
updateHoverIndex( event->pos() );
if ( m_hoveredIndex.isValid() )
{
m_hoveredIndex = QModelIndex();
repaint();
}
} }