2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2019-09-23 19:17:41 +02:00
|
|
|
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Strawberry is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:10:03 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-06-14 23:54:18 +02:00
|
|
|
#include <cmath>
|
2018-10-19 20:18:46 +02:00
|
|
|
#include <algorithm>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QAbstractItemView>
|
2020-02-08 15:03:11 +01:00
|
|
|
#include <QItemSelectionModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QTreeView>
|
|
|
|
#include <QHeaderView>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QByteArray>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QClipboard>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QCommonStyle>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QKeySequence>
|
|
|
|
#include <QMimeData>
|
2020-02-08 15:03:11 +01:00
|
|
|
#include <QList>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QSize>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QTimeLine>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QStringBuilder>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QBrush>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QRegion>
|
|
|
|
#include <QStyleOptionHeader>
|
|
|
|
#include <QStyleOptionViewItem>
|
|
|
|
#include <QProxyStyle>
|
|
|
|
#include <QLinearGradient>
|
|
|
|
#include <QScrollBar>
|
|
|
|
#include <QtEvents>
|
|
|
|
#include <QSettings>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/player.h"
|
|
|
|
#include "core/qt_blurimage.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/song.h"
|
2019-07-30 21:32:56 +02:00
|
|
|
#include "playlistmanager.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "playlistdelegates.h"
|
|
|
|
#include "playlistheader.h"
|
|
|
|
#include "playlistview.h"
|
2019-07-07 21:14:24 +02:00
|
|
|
#include "covermanager/currentalbumcoverloader.h"
|
2020-04-20 18:03:18 +02:00
|
|
|
#include "covermanager/albumcoverloaderresult.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "settings/appearancesettingspage.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "settings/playlistsettingspage.h"
|
|
|
|
|
2019-04-18 15:03:01 +02:00
|
|
|
#ifdef HAVE_MOODBAR
|
|
|
|
# include "moodbar/moodbaritemdelegate.h"
|
|
|
|
#endif
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
const int PlaylistView::kGlowIntensitySteps = 24;
|
|
|
|
const int PlaylistView::kAutoscrollGraceTimeout = 30; // seconds
|
|
|
|
const int PlaylistView::kDropIndicatorWidth = 2;
|
|
|
|
const int PlaylistView::kDropIndicatorGradientWidth = 5;
|
|
|
|
|
2020-02-22 13:43:33 +01:00
|
|
|
PlaylistProxyStyle::PlaylistProxyStyle() : QProxyStyle(nullptr), common_style_(new QCommonStyle) {}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void PlaylistProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
|
|
|
|
|
|
|
|
if (element == CE_Header) {
|
|
|
|
const QStyleOptionHeader *header_option = qstyleoption_cast<const QStyleOptionHeader*>(option);
|
|
|
|
const QRect &rect = header_option->rect;
|
|
|
|
const QString &text = header_option->text;
|
|
|
|
const QFontMetrics &font_metrics = header_option->fontMetrics;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Spaces added to make transition less abrupt
|
2019-07-08 23:27:45 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
2019-07-08 22:19:14 +02:00
|
|
|
if (rect.width() < font_metrics.horizontalAdvance(text + " ")) {
|
2019-07-08 23:27:45 +02:00
|
|
|
#else
|
|
|
|
if (rect.width() < font_metrics.width(text + " ")) {
|
|
|
|
#endif
|
2018-02-27 18:06:05 +01:00
|
|
|
const Playlist::Column column = static_cast<Playlist::Column>(header_option->section);
|
|
|
|
QStyleOptionHeader new_option(*header_option);
|
|
|
|
new_option.text = Playlist::abbreviated_column_name(column);
|
|
|
|
QProxyStyle::drawControl(element, &new_option, painter, widget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element == CE_ItemViewItem)
|
|
|
|
common_style_->drawControl(element, option, painter, widget);
|
|
|
|
else
|
|
|
|
QProxyStyle::drawControl(element, option, painter, widget);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
|
|
|
|
|
|
|
|
if (element == QStyle::PE_PanelItemViewRow || element == QStyle::PE_PanelItemViewItem)
|
|
|
|
common_style_->drawPrimitive(element, option, painter, widget);
|
|
|
|
else
|
|
|
|
QProxyStyle::drawPrimitive(element, option, painter, widget);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlaylistView::PlaylistView(QWidget *parent)
|
|
|
|
: QTreeView(parent),
|
|
|
|
app_(nullptr),
|
2020-02-22 13:43:33 +01:00
|
|
|
style_(new PlaylistProxyStyle()),
|
2018-02-27 18:06:05 +01:00
|
|
|
playlist_(nullptr),
|
|
|
|
header_(new PlaylistHeader(Qt::Horizontal, this, this)),
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_type_(AppearanceSettingsPage::BackgroundImageType_Default),
|
|
|
|
background_image_position_(AppearanceSettingsPage::BackgroundImagePosition_BottomRight),
|
|
|
|
background_image_maxsize_(0),
|
|
|
|
background_image_stretch_(false),
|
2019-06-30 19:37:05 +02:00
|
|
|
background_image_do_not_cut_(true),
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_keep_aspect_ratio_(true),
|
|
|
|
blur_radius_(AppearanceSettingsPage::kDefaultBlurRadius),
|
|
|
|
opacity_level_(AppearanceSettingsPage::kDefaultOpacityLevel),
|
2018-11-18 23:21:12 +01:00
|
|
|
initialized_(false),
|
2019-03-25 22:00:40 +01:00
|
|
|
background_initialized_(false),
|
2018-02-27 18:06:05 +01:00
|
|
|
setting_initial_header_layout_(false),
|
|
|
|
read_only_settings_(true),
|
2019-04-28 14:14:19 +02:00
|
|
|
state_loaded_(false),
|
2018-02-27 18:06:05 +01:00
|
|
|
previous_background_image_opacity_(0.0),
|
|
|
|
fade_animation_(new QTimeLine(1000, this)),
|
2019-03-25 22:00:40 +01:00
|
|
|
force_background_redraw_(false),
|
2018-02-27 18:06:05 +01:00
|
|
|
last_height_(-1),
|
|
|
|
last_width_(-1),
|
2019-03-25 22:00:40 +01:00
|
|
|
current_background_image_x_(0),
|
|
|
|
current_background_image_y_(0),
|
|
|
|
previous_background_image_x_(0),
|
|
|
|
previous_background_image_y_(0),
|
2018-02-27 18:06:05 +01:00
|
|
|
glow_enabled_(true),
|
2019-10-27 02:11:51 +01:00
|
|
|
select_track_(false),
|
2018-02-27 18:06:05 +01:00
|
|
|
currently_glowing_(false),
|
|
|
|
glow_intensity_step_(0),
|
|
|
|
inhibit_autoscroll_timer_(new QTimer(this)),
|
|
|
|
inhibit_autoscroll_(false),
|
|
|
|
currently_autoscrolling_(false),
|
|
|
|
row_height_(-1),
|
|
|
|
currenttrack_play_(":/pictures/currenttrack_play.png"),
|
|
|
|
currenttrack_pause_(":/pictures/currenttrack_pause.png"),
|
|
|
|
cached_current_row_row_(-1),
|
|
|
|
drop_indicator_row_(-1),
|
2018-11-18 23:21:12 +01:00
|
|
|
drag_over_(false) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
setHeader(header_);
|
|
|
|
header_->setSectionsMovable(true);
|
2020-04-08 22:44:39 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
header_->setFirstSectionMovable(true);
|
|
|
|
#endif
|
2018-02-27 18:06:05 +01:00
|
|
|
setStyle(style_);
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
2020-04-13 05:57:48 +02:00
|
|
|
connect(header_, SIGNAL(sectionResized(int, int, int)), SLOT(SaveGeometry()));
|
|
|
|
connect(header_, SIGNAL(sectionMoved(int, int, int)), SLOT(SaveGeometry()));
|
|
|
|
connect(header_, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), SLOT(SaveGeometry()));
|
|
|
|
connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)), SLOT(SaveGeometry()));
|
|
|
|
|
|
|
|
connect(header_, SIGNAL(sectionResized(int, int, int)), SLOT(InvalidateCachedCurrentPixmap()));
|
|
|
|
connect(header_, SIGNAL(sectionMoved(int, int, int)), SLOT(InvalidateCachedCurrentPixmap()));
|
|
|
|
connect(header_, SIGNAL(SectionVisibilityChanged(int, bool)), SLOT(InvalidateCachedCurrentPixmap()));
|
2018-02-27 18:06:05 +01:00
|
|
|
connect(header_, SIGNAL(StretchEnabledChanged(bool)), SLOT(StretchChanged(bool)));
|
|
|
|
|
|
|
|
inhibit_autoscroll_timer_->setInterval(kAutoscrollGraceTimeout * 1000);
|
|
|
|
inhibit_autoscroll_timer_->setSingleShot(true);
|
|
|
|
connect(inhibit_autoscroll_timer_, SIGNAL(timeout()), SLOT(InhibitAutoscrollTimeout()));
|
|
|
|
|
|
|
|
horizontalScrollBar()->installEventFilter(this);
|
|
|
|
verticalScrollBar()->installEventFilter(this);
|
|
|
|
|
|
|
|
setAlternatingRowColors(true);
|
|
|
|
|
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
|
|
|
|
2018-07-01 22:26:46 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2018-02-27 18:06:05 +01:00
|
|
|
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
|
|
|
#endif
|
|
|
|
// For fading
|
|
|
|
connect(fade_animation_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousBackgroundImage(qreal)));
|
|
|
|
fade_animation_->setDirection(QTimeLine::Backward); // 1.0 -> 0.0
|
|
|
|
|
2018-11-18 23:21:12 +01:00
|
|
|
initialized_ = true;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2018-10-20 22:16:22 +02:00
|
|
|
PlaylistView::~PlaylistView() {
|
|
|
|
delete style_;
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
void PlaylistView::SetApplication(Application *app) {
|
|
|
|
|
|
|
|
Q_ASSERT(app);
|
|
|
|
app_ = app;
|
2020-07-10 16:18:31 +02:00
|
|
|
|
|
|
|
SetItemDelegates();
|
|
|
|
|
2020-04-13 05:57:48 +02:00
|
|
|
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), this, SLOT(SongChanged(Song)));
|
2020-04-20 18:03:18 +02:00
|
|
|
connect(app_->current_albumcover_loader(), SIGNAL(AlbumCoverLoaded(Song, AlbumCoverLoaderResult)), SLOT(AlbumCoverLoaded(Song, AlbumCoverLoaderResult)));
|
2018-02-27 18:06:05 +01:00
|
|
|
connect(app_->player(), SIGNAL(Playing()), SLOT(StartGlowing()));
|
2019-07-30 21:32:56 +02:00
|
|
|
connect(app_->player(), SIGNAL(Paused()), SLOT(StopGlowing()));
|
|
|
|
connect(app_->player(), SIGNAL(Stopped()), SLOT(Stopped()));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-10 16:18:31 +02:00
|
|
|
void PlaylistView::SetItemDelegates() {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
setItemDelegate(new PlaylistDelegateBase(this));
|
|
|
|
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Title, new TextItemDelegate(this));
|
2020-07-10 16:18:31 +02:00
|
|
|
setItemDelegateForColumn(Playlist::Column_Album, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Album));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Artist, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Artist));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_AlbumArtist, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_AlbumArtist));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Genre, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Genre));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Composer, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Composer));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Performer, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Performer));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Grouping, new TagCompletionItemDelegate(this, app_->collection_backend(), Playlist::Column_Grouping));
|
2018-02-27 18:06:05 +01:00
|
|
|
setItemDelegateForColumn(Playlist::Column_Length, new LengthItemDelegate(this));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Filesize, new SizeItemDelegate(this));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Filetype, new FileTypeItemDelegate(this));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_DateCreated, new DateItemDelegate(this));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_DateModified, new DateItemDelegate(this));
|
|
|
|
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Samplerate, new PlaylistDelegateBase(this, ("Hz")));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Bitdepth, new PlaylistDelegateBase(this, ("Bit")));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Bitrate, new PlaylistDelegateBase(this, tr("kbps")));
|
|
|
|
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Filename, new NativeSeparatorsDelegate(this));
|
|
|
|
setItemDelegateForColumn(Playlist::Column_LastPlayed, new LastPlayedItemDelegate(this));
|
|
|
|
|
2018-09-12 22:51:10 +02:00
|
|
|
setItemDelegateForColumn(Playlist::Column_Source, new SongSourceDelegate(this));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-04-18 15:03:01 +02:00
|
|
|
#ifdef HAVE_MOODBAR
|
|
|
|
setItemDelegateForColumn(Playlist::Column_Mood, new MoodbarItemDelegate(app_, this, this));
|
|
|
|
#endif
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::SetPlaylist(Playlist *playlist) {
|
|
|
|
|
|
|
|
if (playlist_) {
|
|
|
|
disconnect(playlist_, SIGNAL(CurrentSongChanged(Song)), this, SLOT(MaybeAutoscroll()));
|
|
|
|
disconnect(playlist_, SIGNAL(destroyed()), this, SLOT(PlaylistDestroyed()));
|
|
|
|
disconnect(playlist_, SIGNAL(QueueChanged()), this, SLOT(update()));
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist_ = playlist;
|
2018-11-18 23:21:12 +01:00
|
|
|
LoadGeometry();
|
2018-02-27 18:06:05 +01:00
|
|
|
ReloadSettings();
|
|
|
|
setFocus();
|
|
|
|
read_only_settings_ = false;
|
|
|
|
JumpToLastPlayedTrack();
|
|
|
|
|
|
|
|
connect(playlist_, SIGNAL(RestoreFinished()), SLOT(JumpToLastPlayedTrack()));
|
|
|
|
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), SLOT(MaybeAutoscroll()));
|
|
|
|
connect(playlist_, SIGNAL(destroyed()), SLOT(PlaylistDestroyed()));
|
|
|
|
connect(playlist_, SIGNAL(QueueChanged()), SLOT(update()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::setModel(QAbstractItemModel *m) {
|
|
|
|
|
|
|
|
if (model()) {
|
|
|
|
disconnect(model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(InvalidateCachedCurrentPixmap()));
|
2018-10-20 22:16:22 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// When changing the model, always invalidate the current pixmap.
|
2018-05-01 00:41:33 +02:00
|
|
|
// If a remote client uses "stop after", without invaliding the stop mark would not appear.
|
2018-02-27 18:06:05 +01:00
|
|
|
InvalidateCachedCurrentPixmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeView::setModel(m);
|
|
|
|
|
|
|
|
connect(model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(InvalidateCachedCurrentPixmap()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::LoadGeometry() {
|
|
|
|
|
2019-04-28 14:14:19 +02:00
|
|
|
if (!state_loaded_) {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
|
|
|
state_ = s.value("state").toByteArray();
|
|
|
|
state_loaded_ = true;
|
|
|
|
s.endGroup();
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-04-28 14:14:19 +02:00
|
|
|
if (!header_->RestoreState(state_)) {
|
2018-02-27 18:06:05 +01:00
|
|
|
// Maybe we're upgrading from a version that persisted the state with QHeaderView.
|
2019-04-28 14:14:19 +02:00
|
|
|
if (!header_->restoreState(state_)) {
|
2018-11-19 00:18:48 +01:00
|
|
|
header_->HideSection(Playlist::Column_AlbumArtist);
|
|
|
|
header_->HideSection(Playlist::Column_Performer);
|
|
|
|
header_->HideSection(Playlist::Column_Composer);
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->HideSection(Playlist::Column_Year);
|
|
|
|
header_->HideSection(Playlist::Column_OriginalYear);
|
2018-11-19 00:18:48 +01:00
|
|
|
header_->HideSection(Playlist::Column_Disc);
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->HideSection(Playlist::Column_Genre);
|
|
|
|
header_->HideSection(Playlist::Column_Filename);
|
2018-11-19 00:18:48 +01:00
|
|
|
header_->HideSection(Playlist::Column_BaseFilename);
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->HideSection(Playlist::Column_Filesize);
|
|
|
|
header_->HideSection(Playlist::Column_DateCreated);
|
|
|
|
header_->HideSection(Playlist::Column_DateModified);
|
|
|
|
header_->HideSection(Playlist::Column_PlayCount);
|
|
|
|
header_->HideSection(Playlist::Column_SkipCount);
|
|
|
|
header_->HideSection(Playlist::Column_LastPlayed);
|
|
|
|
header_->HideSection(Playlist::Column_Comment);
|
2018-11-19 00:18:48 +01:00
|
|
|
header_->HideSection(Playlist::Column_Grouping);
|
2019-04-18 15:03:01 +02:00
|
|
|
header_->HideSection(Playlist::Column_Mood);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
header_->moveSection(header_->visualIndex(Playlist::Column_Track), 0);
|
|
|
|
setting_initial_header_layout_ = true;
|
|
|
|
}
|
|
|
|
else {
|
2018-11-18 23:21:12 +01:00
|
|
|
setting_initial_header_layout_ = true;
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure at least one column is visible
|
|
|
|
bool all_hidden = true;
|
|
|
|
for (int i = 0; i < header_->count(); ++i) {
|
|
|
|
if (!header_->isSectionHidden(i) && header_->sectionSize(i) > 0) {
|
|
|
|
all_hidden = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (all_hidden) {
|
|
|
|
header_->ShowSection(Playlist::Column_Title);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::SaveGeometry() {
|
|
|
|
|
2019-04-28 14:14:19 +02:00
|
|
|
if (!initialized_ || !state_loaded_) return;
|
|
|
|
state_ = header_->SaveState();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::ReloadBarPixmaps() {
|
|
|
|
|
|
|
|
currenttrack_bar_left_ = LoadBarPixmap(":/pictures/currenttrack_bar_left.png");
|
|
|
|
currenttrack_bar_mid_ = LoadBarPixmap(":/pictures/currenttrack_bar_mid.png");
|
|
|
|
currenttrack_bar_right_ = LoadBarPixmap(":/pictures/currenttrack_bar_right.png");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QPixmap> PlaylistView::LoadBarPixmap(const QString &filename) {
|
|
|
|
|
|
|
|
QImage image(filename);
|
|
|
|
image = image.scaledToHeight(row_height_, Qt::SmoothTransformation);
|
|
|
|
|
|
|
|
// Colour the bar with the palette colour
|
|
|
|
QPainter p(&image);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
|
|
|
p.setOpacity(0.7);
|
|
|
|
p.fillRect(image.rect(), QApplication::palette().color(QPalette::Highlight));
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
// Animation steps
|
|
|
|
QList<QPixmap> ret;
|
|
|
|
for (int i = 0; i < kGlowIntensitySteps; ++i) {
|
|
|
|
QImage step(image.copy());
|
|
|
|
p.begin(&step);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
|
|
|
p.setOpacity(0.4 - 0.6 * sin(float(i) / kGlowIntensitySteps * (M_PI / 2)));
|
|
|
|
p.fillRect(step.rect(), Qt::white);
|
|
|
|
p.end();
|
|
|
|
ret << QPixmap::fromImage(step);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::drawTree(QPainter *painter, const QRegion ®ion) const {
|
|
|
|
|
|
|
|
const_cast<PlaylistView*>(this)->current_paint_region_ = region;
|
|
|
|
QTreeView::drawTree(painter, region);
|
|
|
|
const_cast<PlaylistView*>(this)->current_paint_region_ = QRegion();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
|
|
|
|
2018-09-18 22:17:28 +02:00
|
|
|
QStyleOptionViewItem opt(option);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
bool is_current = index.data(Playlist::Role_IsCurrent).toBool();
|
|
|
|
bool is_paused = index.data(Playlist::Role_IsPaused).toBool();
|
|
|
|
|
|
|
|
if (is_current) {
|
|
|
|
const_cast<PlaylistView*>(this)->last_current_item_ = index;
|
|
|
|
const_cast<PlaylistView*>(this)->last_glow_rect_ = opt.rect;
|
|
|
|
|
|
|
|
int step = glow_intensity_step_;
|
|
|
|
if (step >= kGlowIntensitySteps)
|
|
|
|
step = 2 * (kGlowIntensitySteps - 1) - step + 1;
|
|
|
|
|
|
|
|
int row_height = opt.rect.height();
|
|
|
|
if (row_height != row_height_) {
|
|
|
|
// Recreate the pixmaps if the height changed since last time
|
|
|
|
const_cast<PlaylistView*>(this)->row_height_ = row_height;
|
|
|
|
const_cast<PlaylistView*>(this)->ReloadBarPixmaps();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect middle(opt.rect);
|
|
|
|
middle.setLeft(middle.left() + currenttrack_bar_left_[0].width());
|
|
|
|
middle.setRight(middle.right() - currenttrack_bar_right_[0].width());
|
|
|
|
|
|
|
|
// Selection
|
|
|
|
if (selectionModel()->isSelected(index))
|
|
|
|
painter->fillRect(opt.rect, opt.palette.color(QPalette::Highlight));
|
|
|
|
|
|
|
|
// Draw the bar
|
|
|
|
painter->drawPixmap(opt.rect.topLeft(), currenttrack_bar_left_[step]);
|
|
|
|
painter->drawPixmap(opt.rect.topRight() - currenttrack_bar_right_[0].rect().topRight(), currenttrack_bar_right_[step]);
|
|
|
|
painter->drawPixmap(middle, currenttrack_bar_mid_[step]);
|
|
|
|
|
|
|
|
// Draw the play icon
|
|
|
|
QPoint play_pos(currenttrack_bar_left_[0].width() / 3 * 2, (row_height - currenttrack_play_.height()) / 2);
|
|
|
|
painter->drawPixmap(opt.rect.topLeft() + play_pos, is_paused ? currenttrack_pause_ : currenttrack_play_);
|
|
|
|
|
|
|
|
// Set the font
|
|
|
|
opt.palette.setColor(QPalette::Inactive, QPalette::HighlightedText, QApplication::palette().color(QPalette::Active, QPalette::HighlightedText));
|
|
|
|
opt.palette.setColor(QPalette::Text, QApplication::palette().color(QPalette::HighlightedText));
|
|
|
|
opt.palette.setColor(QPalette::Highlight, Qt::transparent);
|
|
|
|
opt.palette.setColor(QPalette::AlternateBase, Qt::transparent);
|
|
|
|
opt.decorationSize = QSize(20, 20);
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Draw the actual row data on top. We cache this, because it's fairly expensive (1-2ms), and we do it many times per second.
|
2018-02-27 18:06:05 +01:00
|
|
|
const bool cache_dirty = cached_current_row_rect_ != opt.rect || cached_current_row_row_ != index.row() || cached_current_row_.isNull();
|
|
|
|
|
|
|
|
// We can't update the cache if we're not drawing the entire region,
|
2018-05-01 00:41:33 +02:00
|
|
|
// QTreeView clips its drawing to only the columns in the region, so it wouldn't update the whole pixmap properly.
|
2018-02-27 18:06:05 +01:00
|
|
|
const bool whole_region = current_paint_region_.boundingRect().width() == viewport()->width();
|
|
|
|
|
|
|
|
if (!cache_dirty) {
|
|
|
|
painter->drawPixmap(opt.rect, cached_current_row_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (whole_region) {
|
|
|
|
const_cast<PlaylistView*>(this)->UpdateCachedCurrentRowPixmap(opt, index);
|
|
|
|
painter->drawPixmap(opt.rect, cached_current_row_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::drawRow(painter, opt, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::drawRow(painter, opt, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-18 22:17:28 +02:00
|
|
|
void PlaylistView::UpdateCachedCurrentRowPixmap(QStyleOptionViewItem option, const QModelIndex &index) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
cached_current_row_rect_ = option.rect;
|
|
|
|
cached_current_row_row_ = index.row();
|
|
|
|
|
|
|
|
option.rect.moveTo(0, 0);
|
|
|
|
cached_current_row_ = QPixmap(option.rect.size());
|
|
|
|
cached_current_row_.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter p(&cached_current_row_);
|
|
|
|
QTreeView::drawRow(&p, option, index);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::InvalidateCachedCurrentPixmap() {
|
|
|
|
cached_current_row_ = QPixmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::timerEvent(QTimerEvent *event) {
|
|
|
|
QTreeView::timerEvent(event);
|
|
|
|
if (event->timerId() == glow_timer_.timerId()) GlowIntensityChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::GlowIntensityChanged() {
|
|
|
|
glow_intensity_step_ = (glow_intensity_step_ + 1) % (kGlowIntensitySteps * 2);
|
|
|
|
|
|
|
|
viewport()->update(last_glow_rect_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::StopGlowing() {
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
currently_glowing_ = false;
|
|
|
|
glow_timer_.stop();
|
|
|
|
glow_intensity_step_ = kGlowIntensitySteps;
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::StartGlowing() {
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
currently_glowing_ = true;
|
|
|
|
if (isVisible() && glow_enabled_)
|
|
|
|
glow_timer_.start(1500 / kGlowIntensitySteps, this);
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::hideEvent(QHideEvent *) { glow_timer_.stop(); }
|
|
|
|
|
|
|
|
void PlaylistView::showEvent(QShowEvent *) {
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (currently_glowing_ && glow_enabled_)
|
|
|
|
glow_timer_.start(1500 / kGlowIntensitySteps, this);
|
|
|
|
|
|
|
|
MaybeAutoscroll();
|
2019-07-30 21:32:56 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
namespace {
|
2018-02-27 18:06:05 +01:00
|
|
|
bool CompareSelectionRanges(const QItemSelectionRange &a, const QItemSelectionRange &b) {
|
|
|
|
return b.bottom() < a.bottom();
|
|
|
|
}
|
2020-04-23 21:08:28 +02:00
|
|
|
} // namespace
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void PlaylistView::keyPressEvent(QKeyEvent *event) {
|
|
|
|
|
|
|
|
if (!model() || state() == QAbstractItemView::EditingState) {
|
|
|
|
QTreeView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
else if (event == QKeySequence::Delete) {
|
2020-07-08 20:43:46 +02:00
|
|
|
RemoveSelected();
|
2018-02-27 18:06:05 +01:00
|
|
|
event->accept();
|
2018-07-01 22:26:46 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Backspace) {
|
2020-07-08 20:43:46 +02:00
|
|
|
RemoveSelected();
|
2018-02-27 18:06:05 +01:00
|
|
|
event->accept();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (event == QKeySequence::Copy) {
|
|
|
|
CopyCurrentSongToClipboard();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) {
|
|
|
|
if (currentIndex().isValid()) emit PlayItem(currentIndex());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else if (event->modifiers() != Qt::ControlModifier && event->key() == Qt::Key_Space) {
|
|
|
|
emit PlayPause();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Left) {
|
|
|
|
emit SeekBackward();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else if (event->key() == Qt::Key_Right) {
|
|
|
|
emit SeekForward();
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else if (event->modifiers() == Qt::NoModifier && ((event->key() >= Qt::Key_Exclam && event->key() <= Qt::Key_Z) || event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Escape)) {
|
|
|
|
emit FocusOnFilterSignal(event);
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::contextMenuEvent(QContextMenuEvent *e) {
|
|
|
|
emit RightClicked(e->globalPos(), indexAt(e->pos()));
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
2020-07-08 20:43:46 +02:00
|
|
|
void PlaylistView::RemoveSelected() {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
int rows_removed = 0;
|
|
|
|
QItemSelection selection(selectionModel()->selection());
|
|
|
|
|
|
|
|
if (selection.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the last selected row, which is the last in the list
|
|
|
|
int last_row = selection.last().top();
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Sort the selection so we remove the items at the *bottom* first, ensuring we don't have to mess around with changing row numbers
|
2018-10-19 20:18:46 +02:00
|
|
|
std::sort(selection.begin(), selection.end(), CompareSelectionRanges);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
for (const QItemSelectionRange &range : selection) {
|
|
|
|
if (range.top() < last_row) rows_removed += range.height();
|
2020-07-08 20:43:46 +02:00
|
|
|
model()->removeRows(range.top(), range.height(), range.parent());
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int new_row = last_row - rows_removed;
|
|
|
|
// Index of the first column for the row to select
|
|
|
|
QModelIndex new_index = model()->index(new_row, 0);
|
|
|
|
|
|
|
|
// Select the new current item, we want always the item after the last selected
|
|
|
|
if (new_index.isValid()) {
|
2018-05-01 00:41:33 +02:00
|
|
|
// Workaround to update keyboard selected row, if it's not the first row (this also triggers selection)
|
2018-02-27 18:06:05 +01:00
|
|
|
if (new_row != 0)
|
|
|
|
keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
|
|
|
|
// Update visual selection with the entire row
|
|
|
|
selectionModel()->select(new_index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We're removing the last item, select the new last row
|
|
|
|
selectionModel()->select(model()->index(model()->rowCount() - 1, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> PlaylistView::GetEditableColumns() {
|
|
|
|
|
|
|
|
QList<int> columns;
|
|
|
|
QHeaderView *h = header();
|
|
|
|
for (int col = 0; col < h->count(); col++) {
|
|
|
|
if (h->isSectionHidden(col)) continue;
|
|
|
|
QModelIndex index = model()->index(0, col);
|
|
|
|
if (index.flags() & Qt::ItemIsEditable) columns << h->visualIndex(col);
|
|
|
|
}
|
2018-10-19 20:18:46 +02:00
|
|
|
std::sort(columns.begin(), columns.end());
|
2018-02-27 18:06:05 +01:00
|
|
|
return columns;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PlaylistView::NextEditableIndex(const QModelIndex ¤t) {
|
|
|
|
|
|
|
|
QList<int> columns = GetEditableColumns();
|
|
|
|
QHeaderView *h = header();
|
|
|
|
int index = columns.indexOf(h->visualIndex(current.column()));
|
|
|
|
|
|
|
|
if (index + 1 >= columns.size())
|
|
|
|
return model()->index(current.row() + 1, h->logicalIndex(columns.first()));
|
|
|
|
|
|
|
|
return model()->index(current.row(), h->logicalIndex(columns[index + 1]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex ¤t) {
|
|
|
|
|
|
|
|
QList<int> columns = GetEditableColumns();
|
|
|
|
QHeaderView *h = header();
|
|
|
|
int index = columns.indexOf(h->visualIndex(current.column()));
|
|
|
|
|
|
|
|
if (index - 1 < 0)
|
|
|
|
return model()->index(current.row() - 1, h->logicalIndex(columns.last()));
|
|
|
|
|
|
|
|
return model()->index(current.row(), h->logicalIndex(columns[index - 1]));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:41:46 +01:00
|
|
|
bool PlaylistView::edit(const QModelIndex &index, QAbstractItemView::EditTrigger trigger, QEvent *event) {
|
|
|
|
|
|
|
|
bool result = QAbstractItemView::edit(index, trigger, event);
|
|
|
|
if (result && trigger == QAbstractItemView::AllEditTriggers && !event) {
|
|
|
|
playlist_->set_editing(index.row());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
void PlaylistView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) {
|
|
|
|
|
|
|
|
if (hint == QAbstractItemDelegate::NoHint) {
|
|
|
|
QTreeView::closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
|
|
|
}
|
|
|
|
else if (hint == QAbstractItemDelegate::EditNextItem || hint == QAbstractItemDelegate::EditPreviousItem) {
|
|
|
|
|
|
|
|
QModelIndex index;
|
|
|
|
if (hint == QAbstractItemDelegate::EditNextItem)
|
|
|
|
index = NextEditableIndex(currentIndex());
|
|
|
|
else
|
|
|
|
index = PrevEditableIndex(currentIndex());
|
|
|
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
QTreeView::closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::closeEditor(editor, QAbstractItemDelegate::NoHint);
|
|
|
|
setCurrentIndex(index);
|
2020-01-28 19:41:46 +01:00
|
|
|
QAbstractItemView::edit(index);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::closeEditor(editor, hint);
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:41:46 +01:00
|
|
|
playlist_->set_editing(-1);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::mouseMoveEvent(QMouseEvent *event) {
|
|
|
|
|
|
|
|
if (!drag_over_) {
|
|
|
|
QTreeView::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::leaveEvent(QEvent *e) {
|
|
|
|
|
|
|
|
QTreeView::leaveEvent(e);
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::mousePressEvent(QMouseEvent *event) {
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (editTriggers() & QAbstractItemView::NoEditTriggers) {
|
|
|
|
QTreeView::mousePressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2019-04-20 14:26:30 +02:00
|
|
|
QModelIndex idx = indexAt(event->pos());
|
|
|
|
if (event->button() == Qt::XButton1 && idx.isValid()) {
|
|
|
|
app_->player()->Previous();
|
|
|
|
}
|
|
|
|
else if (event->button() == Qt::XButton2 && idx.isValid()) {
|
|
|
|
app_->player()->Next();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QTreeView::mousePressEvent(event);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
inhibit_autoscroll_ = true;
|
|
|
|
inhibit_autoscroll_timer_->start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::scrollContentsBy(int dx, int dy) {
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (dx) {
|
|
|
|
InvalidateCachedCurrentPixmap();
|
|
|
|
}
|
|
|
|
cached_tree_ = QPixmap();
|
|
|
|
|
|
|
|
QTreeView::scrollContentsBy(dx, dy);
|
|
|
|
|
|
|
|
if (!currently_autoscrolling_) {
|
|
|
|
// We only want to do this if the scroll was initiated by the user
|
|
|
|
inhibit_autoscroll_ = true;
|
|
|
|
inhibit_autoscroll_timer_->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::InhibitAutoscrollTimeout() {
|
2018-05-01 00:41:33 +02:00
|
|
|
// For 30 seconds after the user clicks on or scrolls the playlist we promise not to automatically scroll the view to keep up with a track change.
|
2018-02-27 18:06:05 +01:00
|
|
|
inhibit_autoscroll_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::MaybeAutoscroll() {
|
|
|
|
if (!inhibit_autoscroll_) JumpToCurrentlyPlayingTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::JumpToCurrentlyPlayingTrack() {
|
|
|
|
|
|
|
|
Q_ASSERT(playlist_);
|
|
|
|
|
|
|
|
// Usage of the "Jump to the currently playing track" action shall enable autoscroll
|
|
|
|
inhibit_autoscroll_ = false;
|
|
|
|
|
|
|
|
if (playlist_->current_row() == -1) return;
|
|
|
|
|
|
|
|
QModelIndex current = playlist_->proxy()->mapFromSource(playlist_->index(playlist_->current_row(), 0));
|
|
|
|
if (!current.isValid()) return;
|
|
|
|
|
|
|
|
currently_autoscrolling_ = true;
|
|
|
|
|
|
|
|
// Scroll to the item
|
|
|
|
scrollTo(current, QAbstractItemView::PositionAtCenter);
|
|
|
|
|
|
|
|
currently_autoscrolling_ = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::JumpToLastPlayedTrack() {
|
|
|
|
|
|
|
|
Q_ASSERT(playlist_);
|
|
|
|
|
|
|
|
if (playlist_->last_played_row() == -1) return;
|
|
|
|
|
|
|
|
QModelIndex last_played = playlist_->proxy()->mapFromSource(playlist_->index(playlist_->last_played_row(), 0));
|
|
|
|
if (!last_played.isValid()) return;
|
|
|
|
|
|
|
|
// Select last played song
|
|
|
|
last_current_item_ = last_played;
|
|
|
|
setCurrentIndex(last_current_item_);
|
|
|
|
|
|
|
|
currently_autoscrolling_ = true;
|
|
|
|
|
|
|
|
// Scroll to the item
|
|
|
|
scrollTo(last_played, QAbstractItemView::PositionAtCenter);
|
|
|
|
|
|
|
|
currently_autoscrolling_ = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::paintEvent(QPaintEvent *event) {
|
|
|
|
|
|
|
|
// Reimplemented to draw the background image.
|
|
|
|
// Reimplemented also to draw the drop indicator
|
2018-05-01 00:41:33 +02:00
|
|
|
// When the user is dragging some stuff over the playlist paintEvent gets called for the entire viewport every time the user moves the mouse.
|
|
|
|
// The drawTree is kinda expensive, so we cache the result and draw from the cache while the user is dragging.
|
|
|
|
// The cached pixmap gets invalidated in dragLeaveEvent, dropEvent and scrollContentsBy.
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Draw background
|
2019-03-25 22:00:40 +01:00
|
|
|
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Custom || background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Album) {
|
2018-02-27 18:06:05 +01:00
|
|
|
if (!background_image_.isNull() || !previous_background_image_.isNull()) {
|
|
|
|
QPainter background_painter(viewport());
|
|
|
|
|
2019-06-30 19:37:05 +02:00
|
|
|
int pb_height = height() - header_->height();
|
|
|
|
int pb_width = verticalScrollBar()->isVisible() ? width() - style()->pixelMetric(QStyle::PM_ScrollBarExtent) : width();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Check if we should recompute the background image
|
2019-06-30 19:37:05 +02:00
|
|
|
if (pb_height != last_height_ || pb_width != last_width_ || force_background_redraw_) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (background_image_.isNull()) {
|
|
|
|
cached_scaled_background_image_ = QPixmap();
|
|
|
|
}
|
|
|
|
else {
|
2019-03-25 22:00:40 +01:00
|
|
|
if (background_image_stretch_) {
|
|
|
|
if (background_image_keep_aspect_ratio_) {
|
2019-06-30 19:37:05 +02:00
|
|
|
if (background_image_do_not_cut_){
|
|
|
|
cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaled(pb_width, pb_height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (pb_height >= pb_width){
|
|
|
|
cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaledToHeight(pb_height, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaledToWidth(pb_width, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-06-30 19:37:05 +02:00
|
|
|
cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaled(pb_width, pb_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
2019-03-25 22:00:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-06-30 19:37:05 +02:00
|
|
|
int resize_width = qMin(qMin(background_image_.size().width(), pb_width), background_image_maxsize_);
|
|
|
|
int resize_height = qMin(qMin(background_image_.size().height(), pb_height), background_image_maxsize_);
|
2019-03-25 22:00:40 +01:00
|
|
|
cached_scaled_background_image_ = QPixmap::fromImage(background_image_.scaled(resize_width, resize_height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-30 19:37:05 +02:00
|
|
|
last_height_ = pb_height;
|
|
|
|
last_width_ = pb_width;
|
2018-02-27 18:06:05 +01:00
|
|
|
force_background_redraw_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually draw the background image
|
|
|
|
if (!cached_scaled_background_image_.isNull()) {
|
|
|
|
// Set opactiy only if needed, as this deactivate hardware acceleration
|
|
|
|
if (!qFuzzyCompare(previous_background_image_opacity_, qreal(0.0))) {
|
|
|
|
background_painter.setOpacity(1.0 - previous_background_image_opacity_);
|
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
switch (background_image_position_) {
|
|
|
|
case AppearanceSettingsPage::BackgroundImagePosition_UpperLeft:
|
|
|
|
current_background_image_x_ = 0;
|
|
|
|
current_background_image_y_ = 0;
|
|
|
|
break;
|
|
|
|
case AppearanceSettingsPage::BackgroundImagePosition_UpperRight:
|
2019-06-30 19:37:05 +02:00
|
|
|
current_background_image_x_ = (pb_width - cached_scaled_background_image_.width());
|
2019-03-25 22:00:40 +01:00
|
|
|
current_background_image_y_ = 0;
|
|
|
|
break;
|
|
|
|
case AppearanceSettingsPage::BackgroundImagePosition_Middle:
|
2019-06-30 19:37:05 +02:00
|
|
|
current_background_image_x_ = ((pb_width - cached_scaled_background_image_.width()) / 2);
|
|
|
|
current_background_image_y_ = ((pb_height - cached_scaled_background_image_.height()) / 2);
|
2019-03-25 22:00:40 +01:00
|
|
|
break;
|
|
|
|
case AppearanceSettingsPage::BackgroundImagePosition_BottomLeft:
|
|
|
|
current_background_image_x_ = 0;
|
2019-06-30 19:37:05 +02:00
|
|
|
current_background_image_y_ = (pb_height - cached_scaled_background_image_.height());
|
2019-03-25 22:00:40 +01:00
|
|
|
break;
|
|
|
|
case AppearanceSettingsPage::BackgroundImagePosition_BottomRight:
|
|
|
|
default:
|
2019-06-30 19:37:05 +02:00
|
|
|
current_background_image_x_ = (pb_width - cached_scaled_background_image_.width());
|
|
|
|
current_background_image_y_ = (pb_height - cached_scaled_background_image_.height());
|
2019-03-25 22:00:40 +01:00
|
|
|
}
|
|
|
|
background_painter.drawPixmap(current_background_image_x_, current_background_image_y_, cached_scaled_background_image_);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
// Draw the previous background image if we're fading
|
|
|
|
if (!previous_background_image_.isNull()) {
|
|
|
|
background_painter.setOpacity(previous_background_image_opacity_);
|
2019-03-25 22:00:40 +01:00
|
|
|
background_painter.drawPixmap(previous_background_image_x_, previous_background_image_y_, previous_background_image_);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainter p(viewport());
|
|
|
|
|
|
|
|
if (drop_indicator_row_ != -1) {
|
|
|
|
if (cached_tree_.isNull()) {
|
|
|
|
cached_tree_ = QPixmap(size());
|
|
|
|
cached_tree_.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter cache_painter(&cached_tree_);
|
|
|
|
drawTree(&cache_painter, event->region());
|
|
|
|
}
|
|
|
|
|
|
|
|
p.drawPixmap(0, 0, cached_tree_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
drawTree(&p, event->region());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int first_column = header_->logicalIndex(0);
|
|
|
|
|
|
|
|
// Find the y position of the drop indicator
|
|
|
|
QModelIndex drop_index = model()->index(drop_indicator_row_, first_column);
|
|
|
|
int drop_pos = -1;
|
|
|
|
switch (dropIndicatorPosition()) {
|
|
|
|
case QAbstractItemView::OnItem:
|
|
|
|
return; // Don't draw anything
|
|
|
|
|
|
|
|
case QAbstractItemView::AboveItem:
|
|
|
|
drop_pos = visualRect(drop_index).top();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QAbstractItemView::BelowItem:
|
|
|
|
drop_pos = visualRect(drop_index).bottom() + 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QAbstractItemView::OnViewport:
|
|
|
|
if (model()->rowCount() == 0)
|
|
|
|
drop_pos = 1;
|
|
|
|
else
|
|
|
|
drop_pos = 1 + visualRect(model()->index(model()->rowCount() - 1, first_column)).bottom();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a nice gradient first
|
|
|
|
QColor line_color(QApplication::palette().color(QPalette::Highlight));
|
|
|
|
QColor shadow_color(line_color.lighter(140));
|
|
|
|
QColor shadow_fadeout_color(shadow_color);
|
|
|
|
shadow_color.setAlpha(255);
|
|
|
|
shadow_fadeout_color.setAlpha(0);
|
|
|
|
|
|
|
|
QLinearGradient gradient(QPoint(0, drop_pos - kDropIndicatorGradientWidth), QPoint(0, drop_pos + kDropIndicatorGradientWidth));
|
|
|
|
gradient.setColorAt(0.0, shadow_fadeout_color);
|
|
|
|
gradient.setColorAt(0.5, shadow_color);
|
|
|
|
gradient.setColorAt(1.0, shadow_fadeout_color);
|
|
|
|
QPen gradient_pen(QBrush(gradient), kDropIndicatorGradientWidth * 2);
|
|
|
|
p.setPen(gradient_pen);
|
|
|
|
p.drawLine(QPoint(0, drop_pos), QPoint(width(), drop_pos));
|
|
|
|
|
|
|
|
// Now draw the line on top
|
|
|
|
QPen line_pen(line_color, kDropIndicatorWidth);
|
|
|
|
p.setPen(line_pen);
|
|
|
|
p.drawLine(QPoint(0, drop_pos), QPoint(width(), drop_pos));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::dragMoveEvent(QDragMoveEvent *event) {
|
|
|
|
|
|
|
|
QTreeView::dragMoveEvent(event);
|
|
|
|
|
|
|
|
QModelIndex index(indexAt(event->pos()));
|
|
|
|
drop_indicator_row_ = index.isValid() ? index.row() : 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::dragEnterEvent(QDragEnterEvent *event) {
|
|
|
|
QTreeView::dragEnterEvent(event);
|
|
|
|
cached_tree_ = QPixmap();
|
|
|
|
drag_over_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::dragLeaveEvent(QDragLeaveEvent *event) {
|
|
|
|
QTreeView::dragLeaveEvent(event);
|
|
|
|
cached_tree_ = QPixmap();
|
|
|
|
drag_over_ = false;
|
|
|
|
drop_indicator_row_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::dropEvent(QDropEvent *event) {
|
|
|
|
QTreeView::dropEvent(event);
|
|
|
|
cached_tree_ = QPixmap();
|
|
|
|
drop_indicator_row_ = -1;
|
|
|
|
drag_over_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::PlaylistDestroyed() {
|
|
|
|
playlist_ = nullptr;
|
|
|
|
// We'll get a SetPlaylist() soon
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::ReloadSettings() {
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
|
2018-10-31 19:44:24 +01:00
|
|
|
s.beginGroup(PlaylistSettingsPage::kSettingsGroup);
|
2019-08-17 00:00:12 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
bool glow_effect = false;
|
|
|
|
#else
|
|
|
|
bool glow_effect = true;
|
|
|
|
#endif
|
|
|
|
glow_enabled_ = s.value("glow_effect", glow_effect).toBool();
|
2019-03-25 22:00:40 +01:00
|
|
|
bool editmetadatainline = s.value("editmetadatainline", false).toBool();
|
2019-10-27 02:11:51 +01:00
|
|
|
select_track_ = s.value("select_track", false).toBool();
|
2018-02-27 18:06:05 +01:00
|
|
|
s.endGroup();
|
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
|
|
|
bool stretch = s.value("stretch", true).toBool();
|
|
|
|
column_alignment_ = s.value("column_alignments").value<ColumnAlignmentMap>();
|
|
|
|
s.endGroup();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
|
|
|
|
QVariant background_image_type_var = s.value(AppearanceSettingsPage::kBackgroundImageType);
|
|
|
|
QVariant background_image_position_var = s.value(AppearanceSettingsPage::kBackgroundImagePosition);
|
|
|
|
int background_image_maxsize = s.value(AppearanceSettingsPage::kBackgroundImageMaxSize).toInt();
|
|
|
|
if (background_image_maxsize <= 10) background_image_maxsize = 9000;
|
|
|
|
QString background_image_filename = s.value(AppearanceSettingsPage::kBackgroundImageFilename).toString();
|
|
|
|
bool background_image_stretch = s.value(AppearanceSettingsPage::kBackgroundImageStretch, false).toBool();
|
2019-06-30 19:37:05 +02:00
|
|
|
bool background_image_do_not_cut = s.value(AppearanceSettingsPage::kBackgroundImageDoNotCut, true).toBool();
|
2019-03-25 22:00:40 +01:00
|
|
|
bool background_image_keep_aspect_ratio = s.value(AppearanceSettingsPage::kBackgroundImageKeepAspectRatio, true).toBool();
|
|
|
|
int blur_radius = s.value(AppearanceSettingsPage::kBlurRadius, AppearanceSettingsPage::kDefaultBlurRadius).toInt();
|
|
|
|
int opacity_level = s.value(AppearanceSettingsPage::kOpacityLevel, AppearanceSettingsPage::kDefaultOpacityLevel).toInt();
|
|
|
|
s.endGroup();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (setting_initial_header_layout_) {
|
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
header_->SetStretchEnabled(stretch);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Track, 0.02);
|
|
|
|
header_->SetColumnWidth(Playlist::Column_Title, 0.16);
|
2018-08-29 21:42:24 +02:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Artist, 0.12);
|
|
|
|
header_->SetColumnWidth(Playlist::Column_Album, 0.12);
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Length, 0.03);
|
2018-08-09 18:10:03 +02:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Samplerate, 0.07);
|
|
|
|
header_->SetColumnWidth(Playlist::Column_Bitdepth, 0.07);
|
2018-08-29 21:42:24 +02:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Bitrate, 0.07);
|
2018-02-27 18:06:05 +01:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Filetype, 0.06);
|
2018-08-29 21:42:24 +02:00
|
|
|
header_->SetColumnWidth(Playlist::Column_Source, 0.06);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
setting_initial_header_layout_ = false;
|
2019-03-25 22:00:40 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
if (currently_glowing_ && glow_enabled_ && isVisible()) StartGlowing();
|
|
|
|
if (!glow_enabled_) StopGlowing();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (column_alignment_.isEmpty()) {
|
|
|
|
column_alignment_ = DefaultColumnAlignment();
|
|
|
|
}
|
|
|
|
emit ColumnAlignmentChanged(column_alignment_);
|
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Background:
|
2019-03-25 22:00:40 +01:00
|
|
|
AppearanceSettingsPage::BackgroundImageType background_image_type(AppearanceSettingsPage::BackgroundImageType_Default);
|
|
|
|
if (background_image_type_var.isValid()) {
|
|
|
|
background_image_type = static_cast<AppearanceSettingsPage::BackgroundImageType>(background_image_type_var.toInt());
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
else {
|
|
|
|
background_image_type = AppearanceSettingsPage::BackgroundImageType_Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppearanceSettingsPage::BackgroundImagePosition background_image_position(AppearanceSettingsPage::BackgroundImagePosition_BottomRight);
|
|
|
|
if (background_image_position_var.isValid()) {
|
|
|
|
background_image_position = static_cast<AppearanceSettingsPage::BackgroundImagePosition>(background_image_position_var.toInt());
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_position = AppearanceSettingsPage::BackgroundImagePosition_BottomRight;
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Check if background properties have changed.
|
2018-05-01 00:41:33 +02:00
|
|
|
// We change properties only if they have actually changed, to avoid to call set_background_image when it is not needed,
|
|
|
|
// as this will cause the fading animation to start again.
|
|
|
|
// This also avoid to do useless "force_background_redraw".
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
if (
|
|
|
|
!background_initialized_ ||
|
|
|
|
background_image_type != background_image_type_ ||
|
|
|
|
background_image_filename != background_image_filename_ ||
|
|
|
|
background_image_position != background_image_position_ ||
|
|
|
|
background_image_maxsize != background_image_maxsize_ ||
|
|
|
|
background_image_stretch != background_image_stretch_ ||
|
2019-06-30 19:37:05 +02:00
|
|
|
background_image_do_not_cut != background_image_do_not_cut_ ||
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_keep_aspect_ratio != background_image_keep_aspect_ratio_ ||
|
|
|
|
blur_radius_ != blur_radius ||
|
|
|
|
opacity_level_ != opacity_level
|
|
|
|
) {
|
|
|
|
|
2018-03-17 14:39:06 +01:00
|
|
|
background_initialized_ = true;
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_type_ = background_image_type;
|
2018-02-27 18:06:05 +01:00
|
|
|
background_image_filename_ = background_image_filename;
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_position_ = background_image_position;
|
|
|
|
background_image_maxsize_ = background_image_maxsize;
|
|
|
|
background_image_stretch_ = background_image_stretch;
|
2019-06-30 19:37:05 +02:00
|
|
|
background_image_do_not_cut_ = background_image_do_not_cut;
|
2019-03-25 22:00:40 +01:00
|
|
|
background_image_keep_aspect_ratio_ = background_image_keep_aspect_ratio;
|
2018-02-27 18:06:05 +01:00
|
|
|
blur_radius_ = blur_radius;
|
|
|
|
opacity_level_ = opacity_level;
|
2019-03-25 22:00:40 +01:00
|
|
|
|
|
|
|
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Custom) {
|
2018-02-27 18:06:05 +01:00
|
|
|
set_background_image(QImage(background_image_filename));
|
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
else if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Album) {
|
2018-02-27 18:06:05 +01:00
|
|
|
set_background_image(current_song_cover_art_);
|
|
|
|
}
|
|
|
|
else {
|
2018-05-01 00:41:33 +02:00
|
|
|
// User changed background image type to something that will not be painted through paintEvent: reset all background images.
|
|
|
|
// This avoid to use old (deprecated) images for fading when selecting Album or Custom background image type later.
|
2018-02-27 18:06:05 +01:00
|
|
|
set_background_image(QImage());
|
|
|
|
cached_scaled_background_image_ = QPixmap();
|
|
|
|
previous_background_image_ = QPixmap();
|
|
|
|
}
|
2019-03-25 22:00:40 +01:00
|
|
|
setProperty("default_background_enabled", background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Default);
|
2020-07-07 23:02:24 +02:00
|
|
|
setProperty("strawbs_background_enabled", background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Strawbs);
|
2018-02-27 18:06:05 +01:00
|
|
|
emit BackgroundPropertyChanged();
|
|
|
|
force_background_redraw_ = true;
|
|
|
|
}
|
|
|
|
|
2019-03-25 22:00:40 +01:00
|
|
|
if (editmetadatainline)
|
2018-02-27 18:06:05 +01:00
|
|
|
setEditTriggers(editTriggers() | QAbstractItemView::SelectedClicked);
|
2019-03-25 22:00:40 +01:00
|
|
|
else
|
|
|
|
setEditTriggers(editTriggers() & ~QAbstractItemView::SelectedClicked);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::SaveSettings() {
|
|
|
|
|
2018-11-18 23:21:12 +01:00
|
|
|
if (!initialized_ || read_only_settings_) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
2019-04-28 14:14:19 +02:00
|
|
|
s.setValue("state", header_->SaveState());
|
2020-07-18 18:18:34 +02:00
|
|
|
s.setValue("column_alignments", QVariant::fromValue<ColumnAlignmentMap>(column_alignment_));
|
2018-02-27 18:06:05 +01:00
|
|
|
s.endGroup();
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::StretchChanged(bool stretch) {
|
2019-03-25 22:00:40 +01:00
|
|
|
|
2018-11-18 23:21:12 +01:00
|
|
|
if (!initialized_) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
setHorizontalScrollBarPolicy(stretch ? Qt::ScrollBarAlwaysOff : Qt::ScrollBarAsNeeded);
|
2019-04-28 14:14:19 +02:00
|
|
|
SaveGeometry();
|
2019-03-25 22:00:40 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PlaylistView::eventFilter(QObject *object, QEvent *event) {
|
|
|
|
|
|
|
|
if (event->type() == QEvent::Enter && (object == horizontalScrollBar() || object == verticalScrollBar())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return QObject::eventFilter(object, event);
|
2018-09-08 12:38:02 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::rowsInserted(const QModelIndex &parent, int start, int end) {
|
|
|
|
|
|
|
|
const bool at_end = end == model()->rowCount(parent) - 1;
|
|
|
|
|
|
|
|
QTreeView::rowsInserted(parent, start, end);
|
|
|
|
|
|
|
|
if (at_end) {
|
2018-05-01 00:41:33 +02:00
|
|
|
// If the rows were inserted at the end of the playlist then let's scroll the view so the user can see.
|
2018-02-27 18:06:05 +01:00
|
|
|
scrollTo(model()->index(start, 0, parent), QAbstractItemView::PositionAtTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnAlignmentMap PlaylistView::DefaultColumnAlignment() {
|
|
|
|
|
|
|
|
ColumnAlignmentMap ret;
|
|
|
|
|
2018-11-18 23:21:12 +01:00
|
|
|
ret[Playlist::Column_Year] =
|
|
|
|
ret[Playlist::Column_OriginalYear] =
|
2018-02-27 18:06:05 +01:00
|
|
|
ret[Playlist::Column_Track] =
|
|
|
|
ret[Playlist::Column_Disc] =
|
2018-11-18 23:21:12 +01:00
|
|
|
ret[Playlist::Column_Length] =
|
2018-02-27 18:06:05 +01:00
|
|
|
ret[Playlist::Column_Samplerate] =
|
|
|
|
ret[Playlist::Column_Bitdepth] =
|
2018-11-18 23:21:12 +01:00
|
|
|
ret[Playlist::Column_Bitrate] =
|
2018-02-27 18:06:05 +01:00
|
|
|
ret[Playlist::Column_Filesize] =
|
|
|
|
ret[Playlist::Column_PlayCount] =
|
|
|
|
ret[Playlist::Column_SkipCount] =
|
|
|
|
(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::SetColumnAlignment(int section, Qt::Alignment alignment) {
|
|
|
|
|
|
|
|
if (section < 0) return;
|
|
|
|
|
|
|
|
column_alignment_[section] = alignment;
|
|
|
|
emit ColumnAlignmentChanged(column_alignment_);
|
|
|
|
SaveSettings();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Alignment PlaylistView::column_alignment(int section) const {
|
|
|
|
return column_alignment_.value(section, Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::CopyCurrentSongToClipboard() const {
|
|
|
|
|
|
|
|
// Get the display text of all visible columns.
|
|
|
|
QStringList columns;
|
|
|
|
|
|
|
|
for (int i = 0; i < header()->count(); ++i) {
|
|
|
|
if (header()->isSectionHidden(i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:08:28 +02:00
|
|
|
const QVariant var_data = model()->data(currentIndex().sibling(currentIndex().row(), i));
|
|
|
|
if (var_data.type() == QVariant::String) {
|
|
|
|
columns << var_data.toString();
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the song's URL
|
|
|
|
const QUrl url = model()->data(currentIndex().sibling(currentIndex().row(), Playlist::Column_Filename)).toUrl();
|
|
|
|
|
|
|
|
QMimeData *mime_data = new QMimeData;
|
|
|
|
mime_data->setUrls(QList<QUrl>() << url);
|
|
|
|
mime_data->setText(columns.join(" - "));
|
|
|
|
|
|
|
|
QApplication::clipboard()->setMimeData(mime_data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-30 21:32:56 +02:00
|
|
|
void PlaylistView::SongChanged(const Song &song) {
|
2019-10-27 02:11:51 +01:00
|
|
|
|
2019-07-30 21:32:56 +02:00
|
|
|
song_playing_ = song;
|
2019-10-27 02:11:51 +01:00
|
|
|
|
|
|
|
if (select_track_ && playlist_) {
|
|
|
|
clearSelection();
|
|
|
|
QItemSelection selection(playlist_->index(playlist_->current_row(), 0), playlist_->index(playlist_->current_row(), playlist_->ColumnCount - 1));
|
|
|
|
selectionModel()->select(selection, QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
|
2019-07-30 21:32:56 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-30 21:32:56 +02:00
|
|
|
void PlaylistView::Playing() {}
|
|
|
|
|
|
|
|
void PlaylistView::Stopped() {
|
|
|
|
|
|
|
|
if (song_playing_ == Song()) return;
|
|
|
|
song_playing_ = Song();
|
|
|
|
StopGlowing();
|
2020-04-20 18:03:18 +02:00
|
|
|
AlbumCoverLoaded(Song());
|
2019-07-30 21:32:56 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:03:18 +02:00
|
|
|
void PlaylistView::AlbumCoverLoaded(const Song &song, AlbumCoverLoaderResult result) {
|
2019-09-15 20:27:32 +02:00
|
|
|
|
2020-04-20 18:03:18 +02:00
|
|
|
if ((song != Song() && song_playing_ == Song()) || result.image_original == current_song_cover_art_) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-20 18:03:18 +02:00
|
|
|
current_song_cover_art_ = result.image_original;
|
2019-03-25 22:00:40 +01:00
|
|
|
if (background_image_type_ == AppearanceSettingsPage::BackgroundImageType_Album) {
|
2018-02-27 18:06:05 +01:00
|
|
|
if (song.art_automatic().isEmpty() && song.art_manual().isEmpty()) {
|
|
|
|
set_background_image(QImage());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_background_image(current_song_cover_art_);
|
|
|
|
}
|
|
|
|
force_background_redraw_ = true;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::set_background_image(const QImage &image) {
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Save previous image, for fading
|
|
|
|
previous_background_image_ = cached_scaled_background_image_;
|
2019-03-25 22:00:40 +01:00
|
|
|
previous_background_image_x_ = current_background_image_x_;
|
|
|
|
previous_background_image_y_ = current_background_image_y_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (image.isNull() || image.format() == QImage::Format_ARGB32) {
|
|
|
|
background_image_ = image;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
background_image_ = image.convertToFormat(QImage::Format_ARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!background_image_.isNull()) {
|
|
|
|
// Apply opacity filter
|
|
|
|
uchar *bits = background_image_.bits();
|
|
|
|
for (int i = 0 ; i < background_image_.height() * background_image_.bytesPerLine() ; i += 4) {
|
|
|
|
bits[i + 3] = (opacity_level_ / 100.0) * 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (blur_radius_ != 0) {
|
|
|
|
QImage blurred(background_image_.size(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
blurred.fill(Qt::transparent);
|
|
|
|
QPainter blur_painter(&blurred);
|
|
|
|
qt_blurImage(&blur_painter, background_image_, blur_radius_, true, false);
|
|
|
|
blur_painter.end();
|
|
|
|
|
|
|
|
background_image_ = blurred;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVisible()) {
|
|
|
|
previous_background_image_opacity_ = 1.0;
|
2019-07-07 21:14:24 +02:00
|
|
|
if (fade_animation_->state() == QTimeLine::Running) fade_animation_->stop();
|
2018-02-27 18:06:05 +01:00
|
|
|
fade_animation_->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::FadePreviousBackgroundImage(qreal value) {
|
|
|
|
|
|
|
|
previous_background_image_opacity_ = value;
|
|
|
|
if (qFuzzyCompare(previous_background_image_opacity_, qreal(0.0))) {
|
|
|
|
previous_background_image_ = QPixmap();
|
|
|
|
previous_background_image_opacity_ = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistView::focusInEvent(QFocusEvent *event) {
|
|
|
|
|
|
|
|
QTreeView::focusInEvent(event);
|
|
|
|
|
2018-08-09 18:10:03 +02:00
|
|
|
if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
|
2018-05-01 00:41:33 +02:00
|
|
|
// If there's a current item but no selection it probably means the list was filtered, and the selected item does not match the filter.
|
|
|
|
// If there's only 1 item in the view it is now impossible to select that item without using the mouse.
|
2018-02-27 18:06:05 +01:00
|
|
|
const QModelIndex ¤t = selectionModel()->currentIndex();
|
|
|
|
if (current.isValid() && selectionModel()->selectedIndexes().isEmpty()) {
|
|
|
|
QItemSelection new_selection(current.sibling(current.row(), 0), current.sibling(current.row(), current.model()->columnCount(current.parent()) - 1));
|
|
|
|
selectionModel()->select(new_selection, QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-11-19 00:18:48 +01:00
|
|
|
|
|
|
|
void PlaylistView::ResetColumns() {
|
|
|
|
|
2019-04-27 22:32:39 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(Playlist::kSettingsGroup);
|
|
|
|
s.remove("state");
|
|
|
|
s.endGroup();
|
2019-04-28 14:14:19 +02:00
|
|
|
state_loaded_ = false;
|
|
|
|
read_only_settings_ = true;
|
|
|
|
setting_initial_header_layout_ = true;
|
2018-11-19 00:18:48 +01:00
|
|
|
ReloadSettings();
|
|
|
|
LoadGeometry();
|
|
|
|
read_only_settings_ = false;
|
|
|
|
SetPlaylist(playlist_);
|
|
|
|
|
|
|
|
}
|