From 124706afab96d69efcbc847675e2287101ca14db Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 2 Nov 2011 22:46:56 -0400 Subject: [PATCH] Disable on-hovered stars when mouse moves away, make sure to repaint in that case --- src/GetNewStuffDelegate.cpp | 12 ++++++++---- src/GetNewStuffDelegate.h | 3 +++ src/GetNewStuffDialog.cpp | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/GetNewStuffDelegate.cpp b/src/GetNewStuffDelegate.cpp index 8a5e5d25f..1e6466de8 100644 --- a/src/GetNewStuffDelegate.cpp +++ b/src/GetNewStuffDelegate.cpp @@ -259,7 +259,6 @@ bool GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ) { Q_UNUSED( option ); - m_hoveringOver = -1; if ( event->type() != QEvent::MouseButtonRelease && event->type() != QEvent::MouseMove ) @@ -288,15 +287,12 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons if ( fullStars.contains( me->pos() ) ) { - tDebug() << "A star was pressed...which one?"; - const int eachStar = starsWidth / 5; const int clickOffset = me->pos().x() - fullStars.x(); const int whichStar = (clickOffset / eachStar) + 1; if ( event->type() == QEvent::MouseButtonRelease ) { - tDebug() << "Clicked on:" << whichStar; model->setData( index, whichStar, GetNewStuffModel::RatingRole ); } else if ( event->type() == QEvent::MouseMove ) @@ -310,5 +306,13 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons 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(); + } return false; } diff --git a/src/GetNewStuffDelegate.h b/src/GetNewStuffDelegate.h index 853e3c74d..93e32bd9a 100644 --- a/src/GetNewStuffDelegate.h +++ b/src/GetNewStuffDelegate.h @@ -31,6 +31,9 @@ public: virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; +signals: + void update( const QModelIndex& idx ); + protected: virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index ); diff --git a/src/GetNewStuffDialog.cpp b/src/GetNewStuffDialog.cpp index a0102c648..3a5997b26 100644 --- a/src/GetNewStuffDialog.cpp +++ b/src/GetNewStuffDialog.cpp @@ -30,7 +30,9 @@ GetNewStuffDialog::GetNewStuffDialog( QWidget *parent, Qt::WindowFlags f ) ui->setupUi( this ); 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->setMouseTracking( true );