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

Try harder to make artist name hover disappear, not perfect yet

This commit is contained in:
Leo Franchi
2011-11-01 22:27:14 -04:00
parent d442c2158a
commit 5c700394a8
5 changed files with 23 additions and 7 deletions

View File

@@ -157,6 +157,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
// If the user is hovering over an artist rect, draw a background so she knows it's clickable // If the user is hovering over an artist rect, draw a background so she knows it's clickable
QRect r = textRect; QRect r = textRect;
r.setTop( r.bottom() - painter->fontMetrics().height() ); r.setTop( r.bottom() - painter->fontMetrics().height() );
r.adjust( 4, 0, -4, -1 );
if ( m_hoveringOver == index ) if ( m_hoveringOver == index )
TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.5 ); TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.5 );
@@ -183,7 +184,8 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
if ( event->type() != QEvent::MouseButtonRelease && if ( event->type() != QEvent::MouseButtonRelease &&
event->type() != QEvent::MouseMove && event->type() != QEvent::MouseMove &&
event->type() != QEvent::MouseButtonPress ) event->type() != QEvent::MouseButtonPress &&
event->type() != QEvent::Leave )
return false; return false;
if ( m_artistNameRects.contains( index ) ) if ( m_artistNameRects.contains( index ) )
@@ -202,6 +204,7 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
emit updateIndex( index ); emit updateIndex( index );
} }
event->accept();
return true; return true;
} }
else if ( event->type() == QEvent::MouseButtonRelease ) else if ( event->type() == QEvent::MouseButtonRelease )
@@ -212,21 +215,29 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
ViewManager::instance()->show( item->album()->artist() ); ViewManager::instance()->show( item->album()->artist() );
event->accept();
return true; return true;
} else if ( event->type() == QEvent::MouseButtonPress ) } else if ( event->type() == QEvent::MouseButtonPress )
{ {
// Stop the whole album from having a down click action as we just want the artist name to be clicked // Stop the whole album from having a down click action as we just want the artist name to be clicked
event->accept();
return true; return true;
} }
} }
} }
whitespaceMouseEvent();
return false;
}
void
AlbumItemDelegate::whitespaceMouseEvent()
{
if ( m_hoveringOver.isValid() ) if ( m_hoveringOver.isValid() )
{ {
QModelIndex old = m_hoveringOver; QModelIndex old = m_hoveringOver;
m_hoveringOver = QPersistentModelIndex(); m_hoveringOver = QPersistentModelIndex();
emit updateIndex( old ); emit updateIndex( old );
} }
return false;
} }

View File

@@ -33,6 +33,8 @@ Q_OBJECT
public: public:
AlbumItemDelegate( QAbstractItemView* parent = 0, AlbumProxyModel* proxy = 0 ); AlbumItemDelegate( QAbstractItemView* parent = 0, AlbumProxyModel* proxy = 0 );
void whitespaceMouseEvent();
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; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;

View File

@@ -43,6 +43,7 @@ AlbumView::AlbumView( QWidget* parent )
: QListView( parent ) : QListView( parent )
, m_model( 0 ) , m_model( 0 )
, m_proxyModel( 0 ) , m_proxyModel( 0 )
, m_delegate( 0 )
, m_loadingSpinner( new LoadingSpinner( this ) ) , m_loadingSpinner( new LoadingSpinner( this ) )
{ {
setDragEnabled( true ); setDragEnabled( true );
@@ -79,9 +80,9 @@ void
AlbumView::setProxyModel( AlbumProxyModel* model ) AlbumView::setProxyModel( AlbumProxyModel* model )
{ {
m_proxyModel = model; m_proxyModel = model;
AlbumItemDelegate* del = new AlbumItemDelegate( this, m_proxyModel ); m_delegate = new AlbumItemDelegate( this, m_proxyModel );
connect( del, SIGNAL( updateIndex( QModelIndex ) ), this, SLOT( update( QModelIndex ) ) ); connect( m_delegate, SIGNAL( updateIndex( QModelIndex ) ), this, SLOT( update( QModelIndex ) ) );
setItemDelegate( del ); setItemDelegate( m_delegate );
QListView::setModel( m_proxyModel ); QListView::setModel( m_proxyModel );
} }

View File

@@ -29,6 +29,7 @@
class AlbumModel; class AlbumModel;
class LoadingSpinner; class LoadingSpinner;
class AlbumItemDelegate;
class DLLEXPORT AlbumView : public QListView, public Tomahawk::ViewPage class DLLEXPORT AlbumView : public QListView, public Tomahawk::ViewPage
{ {
@@ -75,6 +76,7 @@ private slots:
private: private:
AlbumModel* m_model; AlbumModel* m_model;
AlbumProxyModel* m_proxyModel; AlbumProxyModel* m_proxyModel;
AlbumItemDelegate* m_delegate;
LoadingSpinner* m_loadingSpinner; LoadingSpinner* m_loadingSpinner;
QTimer m_timer; QTimer m_timer;