diff --git a/src/playlist/playlistheader.cpp b/src/playlist/playlistheader.cpp index 51a79c2dc..90f256fed 100644 --- a/src/playlist/playlistheader.cpp +++ b/src/playlist/playlistheader.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view, @@ -32,6 +33,13 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view, hide_action_ = menu_->addAction(tr("&Hide..."), this, SLOT(HideCurrent())); stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled())); + rating_lock_ = menu_->addAction(tr("&Lock Rating"), this, + SLOT(ToggleRatingEditStatus())); + rating_lock_->setCheckable(true); + QSettings s; + s.beginGroup("Playlist"); + rating_lock_->setChecked(s.value("RatingLocked", false).toBool()); + s.endGroup(); menu_->addSeparator(); QMenu* align_menu = new QMenu(tr("&Align text"), this); @@ -71,6 +79,9 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) { QString title( model()->headerData(menu_section_, Qt::Horizontal).toString()); hide_action_->setText(tr("&Hide %1").arg(title)); + + // show rating_lock action only for ratings section + rating_lock_->setVisible(menu_section_ == Playlist::Column_Rating); Qt::Alignment alignment = view_->column_alignment(menu_section_); if (alignment & Qt::AlignLeft) @@ -129,3 +140,7 @@ void PlaylistHeader::ToggleVisible(int section) { } void PlaylistHeader::enterEvent(QEvent*) { emit MouseEntered(); } + +void PlaylistHeader::ToggleRatingEditStatus() { + emit SectionRatingLockStatusChanged(rating_lock_->isChecked()); +} diff --git a/src/playlist/playlistheader.h b/src/playlist/playlistheader.h index a2e2e3d2f..613813bf9 100644 --- a/src/playlist/playlistheader.h +++ b/src/playlist/playlistheader.h @@ -38,11 +38,13 @@ class PlaylistHeader : public StretchHeaderView { signals: void SectionVisibilityChanged(int logical, bool visible); + void SectionRatingLockStatusChanged(bool state); void MouseEntered(); private slots: void HideCurrent(); void ToggleVisible(int section); + void ToggleRatingEditStatus(); void SetColumnAlignment(QAction* action); private: @@ -54,6 +56,7 @@ signals: int menu_section_; QMenu* menu_; QAction* hide_action_; + QAction* rating_lock_; QAction* stretch_action_; QAction* align_left_action_; QAction* align_center_action_; diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 1b0abfb62..d4292a07a 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -144,6 +144,8 @@ PlaylistView::PlaylistView(QWidget* parent) SLOT(SaveGeometry())); connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)), SLOT(SaveGeometry())); + connect(header_, SIGNAL(SectionRatingLockStatusChanged(bool)), + SLOT(SetRatingLockStatus(bool))); connect(header_, SIGNAL(sectionResized(int, int, int)), SLOT(InvalidateCachedCurrentPixmap())); connect(header_, SIGNAL(sectionMoved(int, int, int)), @@ -270,6 +272,7 @@ void PlaylistView::SetPlaylist(Playlist* playlist) { playlist_ = playlist; LoadGeometry(); + LoadRatingLockStatus(); ReloadSettings(); DynamicModeChanged(playlist->is_dynamic()); setFocus(); @@ -386,6 +389,12 @@ void PlaylistView::LoadGeometry() { } } +void PlaylistView::LoadRatingLockStatus() { + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + ratings_locked_ = s.value("RatingLocked", false).toBool(); +} + void PlaylistView::SaveGeometry() { if (read_only_settings_) return; @@ -395,6 +404,15 @@ void PlaylistView::SaveGeometry() { settings.setValue("state_version", kStateVersion); } +void PlaylistView::SetRatingLockStatus(bool state) { + if (read_only_settings_) return; + + ratings_locked_ = state; + QSettings s; + s.beginGroup(Playlist::kSettingsGroup); + s.setValue("RatingLocked", state); +} + void PlaylistView::ReloadBarPixmaps() { currenttrack_bar_left_ = LoadBarPixmap(":currenttrack_bar_left.png"); currenttrack_bar_mid_ = LoadBarPixmap(":currenttrack_bar_mid.png"); @@ -714,11 +732,14 @@ void PlaylistView::closeEditor(QWidget* editor, } void PlaylistView::mouseMoveEvent(QMouseEvent* event) { - QModelIndex index = indexAt(event->pos()); - if (index.isValid() && index.data(Playlist::Role_CanSetRating).toBool()) { - RatingHoverIn(index, event->pos()); - } else if (rating_delegate_->is_mouse_over()) { - RatingHoverOut(); + // Check wheather rating section is locked by user or not + if (!ratings_locked_) { + QModelIndex index = indexAt(event->pos()); + if (index.isValid() && index.data(Playlist::Role_CanSetRating).toBool()) { + RatingHoverIn(index, event->pos()); + } else if (rating_delegate_->is_mouse_over()) { + RatingHoverOut(); + } } if (!drag_over_) { QTreeView::mouseMoveEvent(event); @@ -726,7 +747,7 @@ void PlaylistView::mouseMoveEvent(QMouseEvent* event) { } void PlaylistView::leaveEvent(QEvent* e) { - if (rating_delegate_->is_mouse_over()) { + if (rating_delegate_->is_mouse_over() && !ratings_locked_) { RatingHoverOut(); } QTreeView::leaveEvent(e); @@ -784,13 +805,13 @@ void PlaylistView::mousePressEvent(QMouseEvent* event) { QModelIndex index = indexAt(event->pos()); if (event->button() == Qt::LeftButton && index.isValid() && - index.data(Playlist::Role_CanSetRating).toBool()) { + index.data(Playlist::Role_CanSetRating).toBool() && !ratings_locked_) { // Calculate which star was clicked double new_rating = RatingPainter::RatingForPos(event->pos(), visualRect(index)); if (selectedIndexes().contains(index)) { - // Update all the selected items + // Update all the selected item ratings QModelIndexList src_index_list; for (const QModelIndex& index : selectedIndexes()) { if (index.data(Playlist::Role_CanSetRating).toBool()) { @@ -800,7 +821,7 @@ void PlaylistView::mousePressEvent(QMouseEvent* event) { } playlist_->RateSongs(src_index_list, new_rating); } else { - // Update only this item + // Update only this item rating playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating); } } else { diff --git a/src/playlist/playlistview.h b/src/playlist/playlistview.h index 184c8810d..656ab3523 100644 --- a/src/playlist/playlistview.h +++ b/src/playlist/playlistview.h @@ -142,7 +142,9 @@ signals: private slots: void LoadGeometry(); + void LoadRatingLockStatus(); void SaveGeometry(); + void SetRatingLockStatus(bool state); void GlowIntensityChanged(); void InhibitAutoscrollTimeout(); void MaybeAutoscroll(); @@ -244,6 +246,8 @@ signals: int drop_indicator_row_; bool drag_over_; + bool ratings_locked_; // To store Ratings section lock status + DynamicPlaylistControls* dynamic_controls_; ColumnAlignmentMap column_alignment_;