From 359321f19cef552010a37fe4c25e63791ce691bc Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 17 Apr 2013 03:29:32 +0200 Subject: [PATCH] * Delegates can now reset the hover-index upon request. --- .../playlist/PlaylistItemDelegate.cpp | 12 ++++++-- .../playlist/PlaylistItemDelegate.h | 3 ++ src/libtomahawk/playlist/TreeItemDelegate.cpp | 29 +++++++++++-------- src/libtomahawk/playlist/TreeItemDelegate.h | 3 ++ 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index 0f2d33319..052f58f30 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -314,11 +314,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con else m_view->setCursor( Qt::ArrowCursor ); - if ( m_hoveringOver != index || ( !hoveringInfo && m_hoveringOver.isValid() ) ) + if ( m_hoveringOver != index ) { emit updateIndex( m_hoveringOver ); m_hoveringOver = index; - emit updateIndex( index ); + emit updateIndex( m_hoveringOver ); } event->accept(); @@ -382,3 +382,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con return false; } + + +void +PlaylistItemDelegate::resetHoverIndex() +{ + m_hoveringOver = QModelIndex(); + m_infoButtonRects.clear(); +} diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.h b/src/libtomahawk/playlist/PlaylistItemDelegate.h index b56b04bbd..eaf7ab997 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.h +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.h @@ -40,6 +40,9 @@ public: virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; +public slots: + void resetHoverIndex(); + signals: void updateIndex( const QModelIndex& idx ); diff --git a/src/libtomahawk/playlist/TreeItemDelegate.cpp b/src/libtomahawk/playlist/TreeItemDelegate.cpp index fd1a3e4f8..7b3b3509c 100644 --- a/src/libtomahawk/playlist/TreeItemDelegate.cpp +++ b/src/libtomahawk/playlist/TreeItemDelegate.cpp @@ -186,16 +186,13 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); } - if ( m_hoveringOver == index.sibling( index.row(), 0 ) - && m_view->header()->visualIndex( index.column() ) == m_view->header()->count() - 1 - && !index.data().toString().isEmpty() ) + QRect arrowRect( m_view->viewport()->width() - option.rect.height(), option.rect.y() + 1, option.rect.height() - 2, option.rect.height() - 2 ); + if ( m_hoveringOver.row() == index.row() && m_hoveringOver.parent() == index.parent() ) { - QRect arrowRect( m_view->viewport()->width() - option.rect.height(), option.rect.y() + 1, option.rect.height() - 2, option.rect.height() - 2 ); - QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); painter->drawPixmap( arrowRect, infoIcon ); - m_infoButtonRects[ index.sibling( index.row(), 0 ) ] = arrowRect; + m_infoButtonRects[ index ] = arrowRect; } if ( index.column() > 0 ) @@ -255,9 +252,9 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q return false; bool hoveringInfo = false; - if ( m_infoButtonRects.contains( index.sibling( index.row(), 0 ) ) ) + if ( m_infoButtonRects.contains( index ) ) { - const QRect infoRect = m_infoButtonRects[ index.sibling( index.row(), 0 ) ]; + const QRect infoRect = m_infoButtonRects[ index ]; const QMouseEvent* ev = static_cast< QMouseEvent* >( event ); hoveringInfo = infoRect.contains( ev->pos() ); } @@ -269,11 +266,11 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q else m_view->setCursor( Qt::ArrowCursor ); - if ( m_hoveringOver != index || ( !hoveringInfo && m_hoveringOver.isValid() ) ) + if ( m_hoveringOver != index ) { - emit updateIndex( m_hoveringOver.sibling( index.row(), m_view->header()->logicalIndex( m_view->header()->count() ) ) ); - m_hoveringOver = index.sibling( index.row(), 0 ); - emit updateIndex( index.sibling( index.row(), m_view->header()->logicalIndex( m_view->header()->count() ) ) ); + emit updateIndex( m_hoveringOver ); + m_hoveringOver = index; + emit updateIndex( m_hoveringOver ); } event->accept(); @@ -317,3 +314,11 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q return false; } + + +void +TreeItemDelegate::resetHoverIndex() +{ + m_hoveringOver = QModelIndex(); + m_infoButtonRects.clear(); +} diff --git a/src/libtomahawk/playlist/TreeItemDelegate.h b/src/libtomahawk/playlist/TreeItemDelegate.h index 8cdef6206..a2b493ae3 100644 --- a/src/libtomahawk/playlist/TreeItemDelegate.h +++ b/src/libtomahawk/playlist/TreeItemDelegate.h @@ -40,6 +40,9 @@ public: virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; +public slots: + void resetHoverIndex(); + protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );