Use float for rating
This commit is contained in:
@@ -2330,7 +2330,7 @@ void Playlist::TurnOffDynamicPlaylist() {
|
||||
|
||||
}
|
||||
|
||||
void Playlist::RateSong(const QModelIndex &idx, const double rating) {
|
||||
void Playlist::RateSong(const QModelIndex &idx, const float rating) {
|
||||
|
||||
if (has_item_at(idx.row())) {
|
||||
PlaylistItemPtr item = item_at(idx.row());
|
||||
@@ -2341,7 +2341,7 @@ void Playlist::RateSong(const QModelIndex &idx, const double rating) {
|
||||
|
||||
}
|
||||
|
||||
void Playlist::RateSongs(const QModelIndexList &index_list, const double rating) {
|
||||
void Playlist::RateSongs(const QModelIndexList &index_list, const float rating) {
|
||||
|
||||
QList<int> id_list;
|
||||
for (const QModelIndex &idx : index_list) {
|
||||
|
||||
@@ -295,8 +295,8 @@ class Playlist : public QAbstractListModel {
|
||||
void ItemChanged(const int row);
|
||||
|
||||
// Changes rating of a song to the given value asynchronously
|
||||
void RateSong(const QModelIndex &idx, const double rating);
|
||||
void RateSongs(const QModelIndexList &index_list, const double rating);
|
||||
void RateSong(const QModelIndex &idx, const float rating);
|
||||
void RateSongs(const QModelIndexList &index_list, const float rating);
|
||||
|
||||
void set_auto_sort(const bool auto_sort) { auto_sort_ = auto_sort; }
|
||||
|
||||
|
||||
@@ -522,7 +522,7 @@ void RatingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
||||
|
||||
const bool hover = mouse_over_index_.isValid() && (mouse_over_index_ == idx || (selected_indexes_.contains(mouse_over_index_) && selected_indexes_.contains(idx)));
|
||||
|
||||
const double rating = (hover ? RatingPainter::RatingForPos(mouse_over_pos_, option.rect) : idx.data().toDouble());
|
||||
const float rating = (hover ? RatingPainter::RatingForPos(mouse_over_pos_, option.rect) : idx.data().toFloat());
|
||||
|
||||
painter_.Paint(painter, option.rect, rating);
|
||||
|
||||
@@ -538,10 +538,10 @@ QSize RatingItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
|
||||
|
||||
QString RatingItemDelegate::displayText(const QVariant &value, const QLocale&) const {
|
||||
|
||||
if (value.isNull() || value.toDouble() <= 0) return QString();
|
||||
if (value.isNull() || value.toFloat() <= 0) return QString();
|
||||
|
||||
// Round to the nearest 0.5
|
||||
const double rating = static_cast<double>(lround(value.toDouble() * RatingPainter::kStarCount * 2)) / 2;
|
||||
const float rating = static_cast<float>(lround(value.toFloat() * RatingPainter::kStarCount * 2)) / 2;
|
||||
|
||||
return QString::number(rating, 'f', 1);
|
||||
|
||||
|
||||
@@ -643,10 +643,10 @@ void PlaylistManager::PlaySmartPlaylist(PlaylistGeneratorPtr generator, bool as_
|
||||
|
||||
}
|
||||
|
||||
void PlaylistManager::RateCurrentSong(const double rating) {
|
||||
void PlaylistManager::RateCurrentSong(const float rating) {
|
||||
active()->RateSong(active()->current_index(), rating);
|
||||
}
|
||||
|
||||
void PlaylistManager::RateCurrentSong(const int rating) {
|
||||
RateCurrentSong(rating / 5.0);
|
||||
void PlaylistManager::RateCurrentSong2(const int rating) {
|
||||
RateCurrentSong(static_cast<float>(rating) / 5.0F);
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ class PlaylistManagerInterface : public QObject {
|
||||
virtual void SetActiveStopped() = 0;
|
||||
|
||||
// Rate current song using 0.0 - 1.0 scale.
|
||||
virtual void RateCurrentSong(const double rating) = 0;
|
||||
virtual void RateCurrentSong(const float rating) = 0;
|
||||
// Rate current song using 0 - 5 scale.
|
||||
virtual void RateCurrentSong(const int rating) = 0;
|
||||
virtual void RateCurrentSong2(const int rating) = 0;
|
||||
|
||||
signals:
|
||||
void PlaylistManagerInitialized();
|
||||
@@ -218,9 +218,9 @@ class PlaylistManager : public PlaylistManagerInterface {
|
||||
void PlaySmartPlaylist(PlaylistGeneratorPtr generator, const bool as_new, const bool clear) override;
|
||||
|
||||
// Rate current song using 0.0 - 1.0 scale.
|
||||
void RateCurrentSong(const double rating) override;
|
||||
void RateCurrentSong(const float rating) override;
|
||||
// Rate current song using 0 - 5 scale.
|
||||
void RateCurrentSong(const int rating) override;
|
||||
void RateCurrentSong2(const int rating) override;
|
||||
|
||||
private slots:
|
||||
void SetActivePlaying() override;
|
||||
|
||||
@@ -859,7 +859,7 @@ void PlaylistView::mousePressEvent(QMouseEvent *event) {
|
||||
case Qt::LeftButton:{
|
||||
if (idx.data(Playlist::Role_CanSetRating).toBool() && !rating_locked_) {
|
||||
// Calculate which star was clicked
|
||||
double new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(idx));
|
||||
float new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(idx));
|
||||
if (selectedIndexes().contains(idx)) {
|
||||
// Update all the selected item ratings
|
||||
QModelIndexList src_index_list;
|
||||
|
||||
Reference in New Issue
Block a user