diff --git a/data/data.qrc b/data/data.qrc index 41f47825e..293700776 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -275,9 +275,8 @@ providers/cdbaby.png providers/echonest.png lumberjacksong.txt - icons/22x22/rating.png - icons/32x32/rating.png - icons/48x48/rating.png schema/schema-18.sql + star-off.png + star-on.png diff --git a/data/icons/22x22/rating.png b/data/icons/22x22/rating.png deleted file mode 100644 index 5ef37a611..000000000 Binary files a/data/icons/22x22/rating.png and /dev/null differ diff --git a/data/icons/32x32/rating.png b/data/icons/32x32/rating.png deleted file mode 100644 index 5ef37a611..000000000 Binary files a/data/icons/32x32/rating.png and /dev/null differ diff --git a/data/icons/48x48/rating.png b/data/icons/48x48/rating.png deleted file mode 100644 index 5ef37a611..000000000 Binary files a/data/icons/48x48/rating.png and /dev/null differ diff --git a/data/star-off.png b/data/star-off.png new file mode 100644 index 000000000..ca999b44a Binary files /dev/null and b/data/star-off.png differ diff --git a/data/star-on.png b/data/star-on.png new file mode 100644 index 000000000..3df0f8160 Binary files /dev/null and b/data/star-on.png differ diff --git a/src/playlist/playlistdelegates.cpp b/src/playlist/playlistdelegates.cpp index 91ca5ac15..c5c82f56a 100644 --- a/src/playlist/playlistdelegates.cpp +++ b/src/playlist/playlistdelegates.cpp @@ -42,9 +42,8 @@ const float QueuedItemDelegate::kQueueOpacityLowerBound = 0.4; const int PlaylistDelegateBase::kMinHeight = 19; -const int RatingItemDelegate::kStarCount = 5; // There are 4 stars -const float RatingItemDelegate::kFullOpacity = 1.0; -const float RatingItemDelegate::kEmptyOpacity = 0.5; +const int RatingItemDelegate::kStarCount; +const int RatingItemDelegate::kStarSize; QueuedItemDelegate::QueuedItemDelegate(QObject *parent, int indicator_column) : QStyledItemDelegate(parent), @@ -291,9 +290,43 @@ QWidget* TextItemDelegate::createEditor( } RatingItemDelegate::RatingItemDelegate(QObject* parent) - : PlaylistDelegateBase(parent), - star_(IconLoader::Load("rating")) + : PlaylistDelegateBase(parent) { + // Load the base pixmaps + QPixmap on(":/star-on.png"); + QPixmap off(":/star-off.png"); + + // Generate the 10 states, better to do it now than on the fly + for (int i=0 ; isetClipRect(option.rect); - // Draw the stars - for (int i=0 ; isetOpacity(kEmptyOpacity); - painter->drawPixmap(rect, empty); - } else if (rating - 0.75 <= i) { - // Half full - const QRect target_left(rect.x(), rect.y(), rect.width()/2, rect.height()); - const QRect target_right(rect.x() + rect.width()/2, rect.y(), rect.width()/2, rect.height()); - const QRect source_left(0, 0, empty.width()/2, empty.height()); - const QRect source_right(empty.width()/2, 0, empty.width()/2, empty.height()); - painter->setOpacity(kFullOpacity); - painter->drawPixmap(target_left, full, source_left); - painter->setOpacity(kEmptyOpacity); - painter->drawPixmap(target_right, empty, source_right); - } else { - // Totally full - painter->setOpacity(kFullOpacity); - painter->drawPixmap(rect, full); - } - } - - painter->setOpacity(1.0); - painter->setClipping(false); + const int star = qBound(0, int(rating*2.0 + 0.5), kStarCount*2); + painter->drawPixmap(QRect(pos, size), stars_[star], QRect(QPoint(0,0), size)); } QSize RatingItemDelegate::sizeHint( diff --git a/src/playlist/playlistdelegates.h b/src/playlist/playlistdelegates.h index 5689e1d9a..c2fcf8b2d 100644 --- a/src/playlist/playlistdelegates.h +++ b/src/playlist/playlistdelegates.h @@ -120,12 +120,11 @@ public: static QRect ContentRect(const QRect& total); static double RatingForPos(const QPoint& pos, const QRect& total_rect); - static const int kStarCount; - static const float kEmptyOpacity; - static const float kFullOpacity; + static const int kStarCount = 5; + static const int kStarSize = 15; private: - QIcon star_; + QPixmap stars_[kStarCount*2+1]; QModelIndex mouse_over_index_; QPoint mouse_over_pos_;