Lock/Unlock Ratings edit status
add comment organize unclutter patch to work with other languages Update playlistheader.cpp
This commit is contained in:
parent
5984c881c6
commit
bcceae175d
@ -21,6 +21,7 @@
|
|||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QSettings>
|
||||||
#include <QSignalMapper>
|
#include <QSignalMapper>
|
||||||
|
|
||||||
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView* view,
|
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()));
|
hide_action_ = menu_->addAction(tr("&Hide..."), this, SLOT(HideCurrent()));
|
||||||
stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this,
|
stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this,
|
||||||
SLOT(ToggleStretchEnabled()));
|
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();
|
menu_->addSeparator();
|
||||||
|
|
||||||
QMenu* align_menu = new QMenu(tr("&Align text"), this);
|
QMenu* align_menu = new QMenu(tr("&Align text"), this);
|
||||||
@ -71,6 +79,9 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent* e) {
|
|||||||
QString title(
|
QString title(
|
||||||
model()->headerData(menu_section_, Qt::Horizontal).toString());
|
model()->headerData(menu_section_, Qt::Horizontal).toString());
|
||||||
hide_action_->setText(tr("&Hide %1").arg(title));
|
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_);
|
Qt::Alignment alignment = view_->column_alignment(menu_section_);
|
||||||
if (alignment & Qt::AlignLeft)
|
if (alignment & Qt::AlignLeft)
|
||||||
@ -129,3 +140,7 @@ void PlaylistHeader::ToggleVisible(int section) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistHeader::enterEvent(QEvent*) { emit MouseEntered(); }
|
void PlaylistHeader::enterEvent(QEvent*) { emit MouseEntered(); }
|
||||||
|
|
||||||
|
void PlaylistHeader::ToggleRatingEditStatus() {
|
||||||
|
emit SectionRatingLockStatusChanged(rating_lock_->isChecked());
|
||||||
|
}
|
||||||
|
@ -38,11 +38,13 @@ class PlaylistHeader : public StretchHeaderView {
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void SectionVisibilityChanged(int logical, bool visible);
|
void SectionVisibilityChanged(int logical, bool visible);
|
||||||
|
void SectionRatingLockStatusChanged(bool state);
|
||||||
void MouseEntered();
|
void MouseEntered();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void HideCurrent();
|
void HideCurrent();
|
||||||
void ToggleVisible(int section);
|
void ToggleVisible(int section);
|
||||||
|
void ToggleRatingEditStatus();
|
||||||
void SetColumnAlignment(QAction* action);
|
void SetColumnAlignment(QAction* action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -54,6 +56,7 @@ signals:
|
|||||||
int menu_section_;
|
int menu_section_;
|
||||||
QMenu* menu_;
|
QMenu* menu_;
|
||||||
QAction* hide_action_;
|
QAction* hide_action_;
|
||||||
|
QAction* rating_lock_;
|
||||||
QAction* stretch_action_;
|
QAction* stretch_action_;
|
||||||
QAction* align_left_action_;
|
QAction* align_left_action_;
|
||||||
QAction* align_center_action_;
|
QAction* align_center_action_;
|
||||||
|
@ -144,6 +144,8 @@ PlaylistView::PlaylistView(QWidget* parent)
|
|||||||
SLOT(SaveGeometry()));
|
SLOT(SaveGeometry()));
|
||||||
connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)),
|
connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)),
|
||||||
SLOT(SaveGeometry()));
|
SLOT(SaveGeometry()));
|
||||||
|
connect(header_, SIGNAL(SectionRatingLockStatusChanged(bool)),
|
||||||
|
SLOT(SetRatingLockStatus(bool)));
|
||||||
connect(header_, SIGNAL(sectionResized(int, int, int)),
|
connect(header_, SIGNAL(sectionResized(int, int, int)),
|
||||||
SLOT(InvalidateCachedCurrentPixmap()));
|
SLOT(InvalidateCachedCurrentPixmap()));
|
||||||
connect(header_, SIGNAL(sectionMoved(int, int, int)),
|
connect(header_, SIGNAL(sectionMoved(int, int, int)),
|
||||||
@ -270,6 +272,7 @@ void PlaylistView::SetPlaylist(Playlist* playlist) {
|
|||||||
|
|
||||||
playlist_ = playlist;
|
playlist_ = playlist;
|
||||||
LoadGeometry();
|
LoadGeometry();
|
||||||
|
LoadRatingLockStatus();
|
||||||
ReloadSettings();
|
ReloadSettings();
|
||||||
DynamicModeChanged(playlist->is_dynamic());
|
DynamicModeChanged(playlist->is_dynamic());
|
||||||
setFocus();
|
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() {
|
void PlaylistView::SaveGeometry() {
|
||||||
if (read_only_settings_) return;
|
if (read_only_settings_) return;
|
||||||
|
|
||||||
@ -395,6 +404,15 @@ void PlaylistView::SaveGeometry() {
|
|||||||
settings.setValue("state_version", kStateVersion);
|
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() {
|
void PlaylistView::ReloadBarPixmaps() {
|
||||||
currenttrack_bar_left_ = LoadBarPixmap(":currenttrack_bar_left.png");
|
currenttrack_bar_left_ = LoadBarPixmap(":currenttrack_bar_left.png");
|
||||||
currenttrack_bar_mid_ = LoadBarPixmap(":currenttrack_bar_mid.png");
|
currenttrack_bar_mid_ = LoadBarPixmap(":currenttrack_bar_mid.png");
|
||||||
@ -714,11 +732,14 @@ void PlaylistView::closeEditor(QWidget* editor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistView::mouseMoveEvent(QMouseEvent* event) {
|
void PlaylistView::mouseMoveEvent(QMouseEvent* event) {
|
||||||
QModelIndex index = indexAt(event->pos());
|
// Check wheather rating section is locked by user or not
|
||||||
if (index.isValid() && index.data(Playlist::Role_CanSetRating).toBool()) {
|
if (!ratings_locked_) {
|
||||||
RatingHoverIn(index, event->pos());
|
QModelIndex index = indexAt(event->pos());
|
||||||
} else if (rating_delegate_->is_mouse_over()) {
|
if (index.isValid() && index.data(Playlist::Role_CanSetRating).toBool()) {
|
||||||
RatingHoverOut();
|
RatingHoverIn(index, event->pos());
|
||||||
|
} else if (rating_delegate_->is_mouse_over()) {
|
||||||
|
RatingHoverOut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!drag_over_) {
|
if (!drag_over_) {
|
||||||
QTreeView::mouseMoveEvent(event);
|
QTreeView::mouseMoveEvent(event);
|
||||||
@ -726,7 +747,7 @@ void PlaylistView::mouseMoveEvent(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistView::leaveEvent(QEvent* e) {
|
void PlaylistView::leaveEvent(QEvent* e) {
|
||||||
if (rating_delegate_->is_mouse_over()) {
|
if (rating_delegate_->is_mouse_over() && !ratings_locked_) {
|
||||||
RatingHoverOut();
|
RatingHoverOut();
|
||||||
}
|
}
|
||||||
QTreeView::leaveEvent(e);
|
QTreeView::leaveEvent(e);
|
||||||
@ -782,27 +803,30 @@ void PlaylistView::mousePressEvent(QMouseEvent* event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex index = indexAt(event->pos());
|
// Check wheather rating section is locked by user or not
|
||||||
if (event->button() == Qt::LeftButton && index.isValid() &&
|
if (!ratings_locked_) {
|
||||||
index.data(Playlist::Role_CanSetRating).toBool()) {
|
QModelIndex index = indexAt(event->pos());
|
||||||
// Calculate which star was clicked
|
if (event->button() == Qt::LeftButton && index.isValid() &&
|
||||||
double new_rating =
|
index.data(Playlist::Role_CanSetRating).toBool()) {
|
||||||
RatingPainter::RatingForPos(event->pos(), visualRect(index));
|
// Calculate which star was clicked
|
||||||
|
double new_rating =
|
||||||
|
RatingPainter::RatingForPos(event->pos(), visualRect(index));
|
||||||
|
|
||||||
if (selectedIndexes().contains(index)) {
|
if (selectedIndexes().contains(index)) {
|
||||||
// Update all the selected items
|
// Update all the selected items
|
||||||
QModelIndexList src_index_list;
|
QModelIndexList src_index_list;
|
||||||
for (const QModelIndex& index : selectedIndexes()) {
|
for (const QModelIndex& index : selectedIndexes()) {
|
||||||
if (index.data(Playlist::Role_CanSetRating).toBool()) {
|
if (index.data(Playlist::Role_CanSetRating).toBool()) {
|
||||||
QModelIndex src_index = playlist_->proxy()->mapToSource(index);
|
QModelIndex src_index = playlist_->proxy()->mapToSource(index);
|
||||||
src_index_list << src_index;
|
src_index_list << src_index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
playlist_->RateSongs(src_index_list, new_rating);
|
||||||
|
} else {
|
||||||
|
// Update only this item
|
||||||
|
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
||||||
}
|
}
|
||||||
playlist_->RateSongs(src_index_list, new_rating);
|
}
|
||||||
} else {
|
|
||||||
// Update only this item
|
|
||||||
playlist_->RateSong(playlist_->proxy()->mapToSource(index), new_rating);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
QTreeView::mousePressEvent(event);
|
QTreeView::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,9 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void LoadGeometry();
|
void LoadGeometry();
|
||||||
|
void LoadRatingLockStatus();
|
||||||
void SaveGeometry();
|
void SaveGeometry();
|
||||||
|
void SetRatingLockStatus(bool state);
|
||||||
void GlowIntensityChanged();
|
void GlowIntensityChanged();
|
||||||
void InhibitAutoscrollTimeout();
|
void InhibitAutoscrollTimeout();
|
||||||
void MaybeAutoscroll();
|
void MaybeAutoscroll();
|
||||||
@ -244,6 +246,8 @@ signals:
|
|||||||
int drop_indicator_row_;
|
int drop_indicator_row_;
|
||||||
bool drag_over_;
|
bool drag_over_;
|
||||||
|
|
||||||
|
bool ratings_locked_; // To store Ratings section lock status
|
||||||
|
|
||||||
DynamicPlaylistControls* dynamic_controls_;
|
DynamicPlaylistControls* dynamic_controls_;
|
||||||
|
|
||||||
ColumnAlignmentMap column_alignment_;
|
ColumnAlignmentMap column_alignment_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user