From db5313129eb8f53a0a760fdc7e6371bfe227922d Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 3 Nov 2011 21:43:16 -0400 Subject: [PATCH] Show rated resolver star in yellow, so it's clear what you have rated and can no longer change --- src/GetNewStuffDelegate.cpp | 23 ++++++++++++++--------- src/GetNewStuffDelegate.h | 2 +- src/GetNewStuffModel.cpp | 2 ++ src/GetNewStuffModel.h | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/GetNewStuffDelegate.cpp b/src/GetNewStuffDelegate.cpp index 1e6466de8..1e1c5d381 100644 --- a/src/GetNewStuffDelegate.cpp +++ b/src/GetNewStuffDelegate.cpp @@ -191,8 +191,10 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio if ( i == 1 ) m_cachedStarRects[ QPair(index.row(), index.column()) ] = r; - QPixmap pm; - if ( m_hoveringOver > -1 && ( m_hoveringItem.first == index.row() && m_hoveringItem.second == index.column() ) ) + const bool userHasRated = index.data( GetNewStuffModel::UserHasRatedRole ).toBool(); + if ( !userHasRated && // Show on-hover animation if the user hasn't rated it yet, and is hovering over it + m_hoveringOver > -1 && + m_hoveringItem == index ) { if ( i <= m_hoveringOver ) // positive star painter->drawPixmap( r, m_onHoverStar ); @@ -201,8 +203,13 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio } else { - if ( i <= rating ) // positive star - painter->drawPixmap( r, m_ratingStarPositive ); + if ( i <= rating ) // positive or rated star + { + if ( userHasRated ) + painter->drawPixmap( r, m_onHoverStar ); + else + painter->drawPixmap( r, m_ratingStarPositive ); + } else painter->drawPixmap( r, m_ratingStarNegative ); } @@ -299,8 +306,7 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons { // 0-indexed m_hoveringOver = whichStar; - m_hoveringItem.first = index.row(); - m_hoveringItem.second = index.column(); + m_hoveringItem = index; } return true; @@ -309,10 +315,9 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons if ( m_hoveringOver > -1 ) { - QModelIndex idx = model->index( m_hoveringItem.first, m_hoveringItem.second ); - emit update( idx ); + emit update( m_hoveringItem ); m_hoveringOver = -1; - m_hoveringItem = QPair(); + m_hoveringItem = QPersistentModelIndex(); } return false; } diff --git a/src/GetNewStuffDelegate.h b/src/GetNewStuffDelegate.h index 93e32bd9a..570210226 100644 --- a/src/GetNewStuffDelegate.h +++ b/src/GetNewStuffDelegate.h @@ -42,7 +42,7 @@ private: int m_widestTextWidth; int m_hoveringOver; - QPair m_hoveringItem; + QPersistentModelIndex m_hoveringItem; mutable QHash< QPair, QRect > m_cachedButtonRects; mutable QHash< QPair, QRect > m_cachedStarRects; }; diff --git a/src/GetNewStuffModel.cpp b/src/GetNewStuffModel.cpp index cb2aa99cc..405ca968b 100644 --- a/src/GetNewStuffModel.cpp +++ b/src/GetNewStuffModel.cpp @@ -94,6 +94,8 @@ GetNewStuffModel::data( const QModelIndex& index, int role ) const return resolver.author(); case StateRole: return (int)AtticaManager::instance()->resolverState( resolver ); + case UserHasRatedRole: + return AtticaManager::instance()->userHasRated( resolver ); } return QVariant(); } diff --git a/src/GetNewStuffModel.h b/src/GetNewStuffModel.h index 60e2e9104..378057e1e 100644 --- a/src/GetNewStuffModel.h +++ b/src/GetNewStuffModel.h @@ -38,7 +38,8 @@ public: DescriptionRole = Qt::UserRole + 5, TypeRole = Qt::UserRole + 6, // Category in attica-speak. What sort of item this is (resolver, etc). AuthorRole = Qt::UserRole + 7, - StateRole = Qt::UserRole + 8 + StateRole = Qt::UserRole + 8, + UserHasRatedRole = Qt::UserRole + 9 }; enum Types {