From 5c700394a862b49b2ec961c700189da5edd5a970 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 1 Nov 2011 22:27:14 -0400 Subject: [PATCH] Try harder to make artist name hover disappear, not perfect yet --- src/libtomahawk/playlist/albumitemdelegate.cpp | 17 ++++++++++++++--- src/libtomahawk/playlist/albumitemdelegate.h | 2 ++ src/libtomahawk/playlist/albumview.cpp | 7 ++++--- src/libtomahawk/playlist/albumview.h | 2 ++ .../playlist/dynamic/widgets/LoadingSpinner.h | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/playlist/albumitemdelegate.cpp b/src/libtomahawk/playlist/albumitemdelegate.cpp index ee461f225..377c0eddd 100644 --- a/src/libtomahawk/playlist/albumitemdelegate.cpp +++ b/src/libtomahawk/playlist/albumitemdelegate.cpp @@ -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 QRect r = textRect; r.setTop( r.bottom() - painter->fontMetrics().height() ); + r.adjust( 4, 0, -4, -1 ); if ( m_hoveringOver == index ) TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.5 ); @@ -183,7 +184,8 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const if ( event->type() != QEvent::MouseButtonRelease && event->type() != QEvent::MouseMove && - event->type() != QEvent::MouseButtonPress ) + event->type() != QEvent::MouseButtonPress && + event->type() != QEvent::Leave ) return false; if ( m_artistNameRects.contains( index ) ) @@ -202,6 +204,7 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const emit updateIndex( index ); } + event->accept(); return true; } else if ( event->type() == QEvent::MouseButtonRelease ) @@ -212,21 +215,29 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const ViewManager::instance()->show( item->album()->artist() ); + event->accept(); return true; } 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 + event->accept(); return true; } } } + whitespaceMouseEvent(); + + return false; +} + +void +AlbumItemDelegate::whitespaceMouseEvent() +{ if ( m_hoveringOver.isValid() ) { QModelIndex old = m_hoveringOver; m_hoveringOver = QPersistentModelIndex(); emit updateIndex( old ); } - - return false; } diff --git a/src/libtomahawk/playlist/albumitemdelegate.h b/src/libtomahawk/playlist/albumitemdelegate.h index 37a7226da..86b31bdf5 100644 --- a/src/libtomahawk/playlist/albumitemdelegate.h +++ b/src/libtomahawk/playlist/albumitemdelegate.h @@ -33,6 +33,8 @@ Q_OBJECT public: AlbumItemDelegate( QAbstractItemView* parent = 0, AlbumProxyModel* proxy = 0 ); + void whitespaceMouseEvent(); + protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; diff --git a/src/libtomahawk/playlist/albumview.cpp b/src/libtomahawk/playlist/albumview.cpp index 4718bdf41..d0a117a95 100644 --- a/src/libtomahawk/playlist/albumview.cpp +++ b/src/libtomahawk/playlist/albumview.cpp @@ -43,6 +43,7 @@ AlbumView::AlbumView( QWidget* parent ) : QListView( parent ) , m_model( 0 ) , m_proxyModel( 0 ) + , m_delegate( 0 ) , m_loadingSpinner( new LoadingSpinner( this ) ) { setDragEnabled( true ); @@ -79,9 +80,9 @@ void AlbumView::setProxyModel( AlbumProxyModel* model ) { m_proxyModel = model; - AlbumItemDelegate* del = new AlbumItemDelegate( this, m_proxyModel ); - connect( del, SIGNAL( updateIndex( QModelIndex ) ), this, SLOT( update( QModelIndex ) ) ); - setItemDelegate( del ); + m_delegate = new AlbumItemDelegate( this, m_proxyModel ); + connect( m_delegate, SIGNAL( updateIndex( QModelIndex ) ), this, SLOT( update( QModelIndex ) ) ); + setItemDelegate( m_delegate ); QListView::setModel( m_proxyModel ); } diff --git a/src/libtomahawk/playlist/albumview.h b/src/libtomahawk/playlist/albumview.h index d590bc050..b16f9e898 100644 --- a/src/libtomahawk/playlist/albumview.h +++ b/src/libtomahawk/playlist/albumview.h @@ -29,6 +29,7 @@ class AlbumModel; class LoadingSpinner; +class AlbumItemDelegate; class DLLEXPORT AlbumView : public QListView, public Tomahawk::ViewPage { @@ -75,6 +76,7 @@ private slots: private: AlbumModel* m_model; AlbumProxyModel* m_proxyModel; + AlbumItemDelegate* m_delegate; LoadingSpinner* m_loadingSpinner; QTimer m_timer; diff --git a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h b/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h index c2602cfa2..556dcd11c 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h +++ b/src/libtomahawk/playlist/dynamic/widgets/LoadingSpinner.h @@ -54,4 +54,4 @@ private: #endif -class QPaintEvent; \ No newline at end of file +class QPaintEvent;