mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Disable on-hovered stars when mouse moves away, make sure to repaint in that case
This commit is contained in:
@@ -259,7 +259,6 @@ bool
|
|||||||
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||||
{
|
{
|
||||||
Q_UNUSED( option );
|
Q_UNUSED( option );
|
||||||
m_hoveringOver = -1;
|
|
||||||
|
|
||||||
if ( event->type() != QEvent::MouseButtonRelease &&
|
if ( event->type() != QEvent::MouseButtonRelease &&
|
||||||
event->type() != QEvent::MouseMove )
|
event->type() != QEvent::MouseMove )
|
||||||
@@ -288,15 +287,12 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
|
|
||||||
if ( fullStars.contains( me->pos() ) )
|
if ( fullStars.contains( me->pos() ) )
|
||||||
{
|
{
|
||||||
tDebug() << "A star was pressed...which one?";
|
|
||||||
|
|
||||||
const int eachStar = starsWidth / 5;
|
const int eachStar = starsWidth / 5;
|
||||||
const int clickOffset = me->pos().x() - fullStars.x();
|
const int clickOffset = me->pos().x() - fullStars.x();
|
||||||
const int whichStar = (clickOffset / eachStar) + 1;
|
const int whichStar = (clickOffset / eachStar) + 1;
|
||||||
|
|
||||||
if ( event->type() == QEvent::MouseButtonRelease )
|
if ( event->type() == QEvent::MouseButtonRelease )
|
||||||
{
|
{
|
||||||
tDebug() << "Clicked on:" << whichStar;
|
|
||||||
model->setData( index, whichStar, GetNewStuffModel::RatingRole );
|
model->setData( index, whichStar, GetNewStuffModel::RatingRole );
|
||||||
}
|
}
|
||||||
else if ( event->type() == QEvent::MouseMove )
|
else if ( event->type() == QEvent::MouseMove )
|
||||||
@@ -310,5 +306,13 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m_hoveringOver > -1 )
|
||||||
|
{
|
||||||
|
QModelIndex idx = model->index( m_hoveringItem.first, m_hoveringItem.second );
|
||||||
|
emit update( idx );
|
||||||
|
m_hoveringOver = -1;
|
||||||
|
m_hoveringItem = QPair<int, int>();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,9 @@ public:
|
|||||||
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void update( const QModelIndex& idx );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
|
||||||
|
|
||||||
|
@@ -30,7 +30,9 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget *parent, Qt::WindowFlags f )
|
|||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
|
|
||||||
ui->listView->setModel( m_model );
|
ui->listView->setModel( m_model );
|
||||||
ui->listView->setItemDelegate( new GetNewStuffDelegate( ui->listView ) );
|
GetNewStuffDelegate* del = new GetNewStuffDelegate( ui->listView );
|
||||||
|
connect( del, SIGNAL( update( QModelIndex ) ), ui->listView, SLOT( update( QModelIndex ) ) );
|
||||||
|
ui->listView->setItemDelegate( del );
|
||||||
ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
ui->listView->setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
|
||||||
|
|
||||||
ui->listView->setMouseTracking( true );
|
ui->listView->setMouseTracking( true );
|
||||||
|
Reference in New Issue
Block a user