mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 17:29:42 +01:00
* Delegates can now reset the hover-index upon request.
This commit is contained in:
parent
65a598ef8b
commit
359321f19c
@ -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();
|
||||
}
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user