mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
* Delegates can now reset the hover-index upon request.
This commit is contained in:
@@ -314,11 +314,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
|
|||||||
else
|
else
|
||||||
m_view->setCursor( Qt::ArrowCursor );
|
m_view->setCursor( Qt::ArrowCursor );
|
||||||
|
|
||||||
if ( m_hoveringOver != index || ( !hoveringInfo && m_hoveringOver.isValid() ) )
|
if ( m_hoveringOver != index )
|
||||||
{
|
{
|
||||||
emit updateIndex( m_hoveringOver );
|
emit updateIndex( m_hoveringOver );
|
||||||
m_hoveringOver = index;
|
m_hoveringOver = index;
|
||||||
emit updateIndex( index );
|
emit updateIndex( m_hoveringOver );
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
@@ -382,3 +382,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
|
|||||||
|
|
||||||
return false;
|
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;
|
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void resetHoverIndex();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateIndex( const QModelIndex& idx );
|
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 ) );
|
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_hoveringOver == index.sibling( index.row(), 0 )
|
QRect arrowRect( m_view->viewport()->width() - option.rect.height(), option.rect.y() + 1, option.rect.height() - 2, option.rect.height() - 2 );
|
||||||
&& m_view->header()->visualIndex( index.column() ) == m_view->header()->count() - 1
|
if ( m_hoveringOver.row() == index.row() && m_hoveringOver.parent() == index.parent() )
|
||||||
&& !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 );
|
|
||||||
|
|
||||||
QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
|
QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
|
||||||
painter->drawPixmap( arrowRect, infoIcon );
|
painter->drawPixmap( arrowRect, infoIcon );
|
||||||
|
|
||||||
m_infoButtonRects[ index.sibling( index.row(), 0 ) ] = arrowRect;
|
m_infoButtonRects[ index ] = arrowRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( index.column() > 0 )
|
if ( index.column() > 0 )
|
||||||
@@ -255,9 +252,9 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool hoveringInfo = 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 );
|
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||||
hoveringInfo = infoRect.contains( ev->pos() );
|
hoveringInfo = infoRect.contains( ev->pos() );
|
||||||
}
|
}
|
||||||
@@ -269,11 +266,11 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
|
|||||||
else
|
else
|
||||||
m_view->setCursor( Qt::ArrowCursor );
|
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() ) ) );
|
emit updateIndex( m_hoveringOver );
|
||||||
m_hoveringOver = index.sibling( index.row(), 0 );
|
m_hoveringOver = index;
|
||||||
emit updateIndex( index.sibling( index.row(), m_view->header()->logicalIndex( m_view->header()->count() ) ) );
|
emit updateIndex( m_hoveringOver );
|
||||||
}
|
}
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
@@ -317,3 +314,11 @@ TreeItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
|
|||||||
|
|
||||||
return false;
|
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;
|
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void resetHoverIndex();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||||
|
Reference in New Issue
Block a user