diff --git a/src/libtomahawk/playlist/TreeView.cpp b/src/libtomahawk/playlist/TreeView.cpp index 57269b238..a0fc559ae 100644 --- a/src/libtomahawk/playlist/TreeView.cpp +++ b/src/libtomahawk/playlist/TreeView.cpp @@ -60,6 +60,7 @@ TreeView::TreeView( QWidget* parent ) setAttribute( Qt::WA_MacShowFocusRect, 0 ); setContentsMargins( 0, 0, 0, 0 ); + setMouseTracking( true ); setAlternatingRowColors( true ); setDragEnabled( true ); setDropIndicatorShown( false ); @@ -427,6 +428,96 @@ TreeView::jumpToCurrentTrack() } +void +TreeView::updateHoverIndex( const QPoint& pos ) +{ + QModelIndex idx = indexAt( pos ); + + if ( idx != m_hoveredIndex ) + { + m_hoveredIndex = idx; + repaint(); + } + + if ( !m_model || m_model->style() != PlayableModel::Collection ) + return; + + PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) ); + if ( idx.column() == 0 && !item->query().isNull() ) + { + if ( pos.x() > header()->sectionViewportPosition( idx.column() ) + header()->sectionSize( idx.column() ) - 16 && + pos.x() < header()->sectionViewportPosition( idx.column() ) + header()->sectionSize( idx.column() ) ) + { + setCursor( Qt::PointingHandCursor ); + return; + } + } + + if ( cursor().shape() != Qt::ArrowCursor ) + setCursor( Qt::ArrowCursor ); +} + + +void +TreeView::wheelEvent( QWheelEvent* event ) +{ + QTreeView::wheelEvent( event ); + + if ( m_hoveredIndex.isValid() ) + { + m_hoveredIndex = QModelIndex(); + repaint(); + } +} + + +void +TreeView::leaveEvent( QEvent* event ) +{ + QTreeView::leaveEvent( event ); + updateHoverIndex( QPoint( -1, -1 ) ); +} + + +void +TreeView::mouseMoveEvent( QMouseEvent* event ) +{ + QTreeView::mouseMoveEvent( event ); + updateHoverIndex( event->pos() ); +} + + +void +TreeView::mousePressEvent( QMouseEvent* event ) +{ + QTreeView::mousePressEvent( event ); + + if ( !m_model || m_model->style() != PlayableModel::Collection ) + return; + + QModelIndex idx = indexAt( event->pos() ); + if ( event->pos().x() > header()->sectionViewportPosition( idx.column() ) + header()->sectionSize( idx.column() ) - 16 && + event->pos().x() < header()->sectionViewportPosition( idx.column() ) + header()->sectionSize( idx.column() ) ) + { + PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) ); + if ( item->query().isNull() ) + return; + + switch ( idx.column() ) + { + case 0: + { + ViewManager::instance()->show( item->query()->displayQuery() ); + break; + } + + default: + break; + } + } +} + + QString TreeView::guid() const { diff --git a/src/libtomahawk/playlist/TreeView.h b/src/libtomahawk/playlist/TreeView.h index 8bd34cb03..27099db55 100644 --- a/src/libtomahawk/playlist/TreeView.h +++ b/src/libtomahawk/playlist/TreeView.h @@ -78,6 +78,8 @@ public: virtual bool jumpToCurrentTrack(); + QModelIndex hoveredIndex() const { return m_hoveredIndex; } + bool updatesContextView() const { return m_updateContextView; } void setUpdatesContextView( bool b ) { m_updateContextView = b; } @@ -92,6 +94,10 @@ protected: virtual void resizeEvent( QResizeEvent* event ); virtual void keyPressEvent( QKeyEvent* event ); + void wheelEvent( QWheelEvent* event ); + void mouseMoveEvent( QMouseEvent* event ); + void mousePressEvent( QMouseEvent* event ); + void leaveEvent( QEvent* event ); protected slots: virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous ); @@ -106,6 +112,8 @@ private slots: void onMenuTriggered( int action ); private: + void updateHoverIndex( const QPoint& pos ); + ViewHeader* m_header; OverlayWidget* m_overlay; TreeModel* m_model; @@ -114,6 +122,7 @@ private: bool m_updateContextView; + QModelIndex m_hoveredIndex; QModelIndex m_contextMenuIndex; Tomahawk::ContextMenu* m_contextMenu;