Add smart playlists, ratings and Qobuz

Fixes #259
Fixes #264
This commit is contained in:
Jonas Kvinge
2020-09-17 17:50:17 +02:00
parent fdf96e8342
commit 89d6b7cec0
102 changed files with 10949 additions and 525 deletions

View File

@@ -29,6 +29,7 @@
#include <QMenu>
#include <QAction>
#include <QActionGroup>
#include <QSettings>
#include <QEvent>
#include <QContextMenuEvent>
#include <QEnterEvent>
@@ -36,25 +37,37 @@
#include "playlistheader.h"
#include "playlistview.h"
#include "settings/playlistsettingspage.h"
PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView *view, QWidget *parent)
: StretchHeaderView(orientation, parent),
view_(view),
menu_(new QMenu(this)) {
menu_(new QMenu(this)),
action_hide_(nullptr),
action_reset_(nullptr),
action_stretch_(nullptr),
action_rating_lock_(nullptr),
action_align_left_(nullptr),
action_align_center_(nullptr),
action_align_right_(nullptr)
{
hide_action_ = menu_->addAction(tr("&Hide..."), this, SLOT(HideCurrent()));
stretch_action_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled()));
reset_action_ = menu_->addAction(tr("&Reset columns to default"), this, SLOT(ResetColumns()));
action_hide_ = menu_->addAction(tr("&Hide..."), this, SLOT(HideCurrent()));
action_stretch_ = menu_->addAction(tr("&Stretch columns to fit window"), this, SLOT(ToggleStretchEnabled()));
action_reset_ = menu_->addAction(tr("&Reset columns to default"), this, SLOT(ResetColumns()));
action_rating_lock_ = menu_->addAction(tr("&Lock rating"), this, SLOT(ToggleRatingEditStatus()));
action_rating_lock_->setCheckable(true);
menu_->addSeparator();
QMenu *align_menu = new QMenu(tr("&Align text"), this);
QActionGroup *align_group = new QActionGroup(this);
align_left_action_ = new QAction(tr("&Left"), align_group);
align_center_action_ = new QAction(tr("&Center"), align_group);
align_right_action_ = new QAction(tr("&Right"), align_group);
action_align_left_ = new QAction(tr("&Left"), align_group);
action_align_center_ = new QAction(tr("&Center"), align_group);
action_align_right_ = new QAction(tr("&Right"), align_group);
align_left_action_->setCheckable(true);
align_center_action_->setCheckable(true);
align_right_action_->setCheckable(true);
action_align_left_->setCheckable(true);
action_align_center_->setCheckable(true);
action_align_right_->setCheckable(true);
align_menu->addActions(align_group->actions());
connect(align_group, SIGNAL(triggered(QAction*)), SLOT(SetColumnAlignment(QAction*)));
@@ -62,10 +75,15 @@ PlaylistHeader::PlaylistHeader(Qt::Orientation orientation, PlaylistView *view,
menu_->addMenu(align_menu);
menu_->addSeparator();
stretch_action_->setCheckable(true);
stretch_action_->setChecked(is_stretch_enabled());
action_stretch_->setCheckable(true);
action_stretch_->setChecked(is_stretch_enabled());
connect(this, SIGNAL(StretchEnabledChanged(bool)), stretch_action_, SLOT(setChecked(bool)));
connect(this, SIGNAL(StretchEnabledChanged(bool)), action_stretch_, SLOT(setChecked(bool)));
QSettings s;
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
action_rating_lock_->setChecked(s.value("rating_locked", false).toBool());
s.endGroup();
}
@@ -74,17 +92,21 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent *e) {
menu_section_ = logicalIndexAt(e->pos());
if (menu_section_ == -1 || (menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
hide_action_->setVisible(false);
action_hide_->setVisible(false);
else {
hide_action_->setVisible(true);
action_hide_->setVisible(true);
QString title(model()->headerData(menu_section_, Qt::Horizontal).toString());
hide_action_->setText(tr("&Hide %1").arg(title));
action_hide_->setText(tr("&Hide %1").arg(title));
Qt::Alignment alignment = view_->column_alignment(menu_section_);
if (alignment & Qt::AlignLeft) align_left_action_->setChecked(true);
else if (alignment & Qt::AlignHCenter) align_center_action_->setChecked(true);
else if (alignment & Qt::AlignRight) align_right_action_->setChecked(true);
if (alignment & Qt::AlignLeft) action_align_left_->setChecked(true);
else if (alignment & Qt::AlignHCenter) action_align_center_->setChecked(true);
else if (alignment & Qt::AlignRight) action_align_right_->setChecked(true);
// Show rating lock action only for ratings section
action_rating_lock_->setVisible(menu_section_ == Playlist::Column_Rating);
}
qDeleteAll(show_actions_);
@@ -126,9 +148,9 @@ void PlaylistHeader::SetColumnAlignment(QAction *action) {
Qt::Alignment alignment = Qt::AlignVCenter;
if (action == align_left_action_) alignment |= Qt::AlignLeft;
if (action == align_center_action_) alignment |= Qt::AlignHCenter;
if (action == align_right_action_) alignment |= Qt::AlignRight;
if (action == action_align_left_) alignment |= Qt::AlignLeft;
if (action == action_align_center_) alignment |= Qt::AlignHCenter;
if (action == action_align_right_) alignment |= Qt::AlignRight;
view_->SetColumnAlignment(menu_section_, alignment);
@@ -150,3 +172,8 @@ void PlaylistHeader::enterEvent(QEvent*) {
void PlaylistHeader::ResetColumns() {
view_->ResetHeaderState();
}
void PlaylistHeader::ToggleRatingEditStatus() {
emit SectionRatingLockStatusChanged(action_rating_lock_->isChecked());
}