1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Show info buttons for tracks in TreeViews.

This commit is contained in:
Christian Muehlhaeuser 2012-06-16 11:25:13 +02:00
parent bae8de0ca5
commit 69cec1b28e
2 changed files with 100 additions and 0 deletions

View File

@ -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
{

View File

@ -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;