strawberry-audio-player-win.../src/playlist/playlistdelegates.h

251 lines
7.7 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, 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:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef PLAYLISTDELEGATES_H
#define PLAYLISTDELEGATES_H
#include "config.h"
#include <QObject>
#include <QWidget>
2019-03-22 23:23:50 +01:00
#include <QAbstractItemView>
#include <QStyledItemDelegate>
#include <QStyleOptionViewItem>
#include <QTreeView>
2018-02-27 18:06:05 +01:00
#include <QCompleter>
#include <QLocale>
#include <QVariant>
#include <QUrl>
#include <QPixmap>
#include <QPainter>
#include <QRect>
#include <QColor>
2020-02-08 15:03:11 +01:00
#include <QRgb>
#include <QSize>
#include <QFont>
#include <QString>
2018-02-27 18:06:05 +01:00
#include <QStringListModel>
#include <QStyleOption>
#include <QHelpEvent>
#include <QLineEdit>
2018-02-27 18:06:05 +01:00
#include "playlist.h"
2020-02-08 15:03:11 +01:00
#include "core/song.h"
#include "widgets/ratingwidget.h"
2018-02-27 18:06:05 +01:00
class CollectionBackend;
2018-02-27 18:06:05 +01:00
class Player;
class QueuedItemDelegate : public QStyledItemDelegate {
2021-07-11 09:49:38 +02:00
Q_OBJECT
2021-06-20 19:04:08 +02:00
public:
2020-06-26 22:41:38 +02:00
explicit QueuedItemDelegate(QObject *parent, int indicator_column = Playlist::Column_Title);
2020-06-15 21:55:05 +02:00
2021-01-26 16:48:04 +01:00
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2021-07-11 09:49:38 +02:00
static void DrawBox(QPainter *painter, const QRect line_rect, const QFont &font, const QString &text, int width = -1, const float opacity = 1.0);
2018-02-27 18:06:05 +01:00
2021-01-26 16:48:04 +01:00
int queue_indicator_size(const QModelIndex &idx) const;
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
private:
2018-02-27 18:06:05 +01:00
static const int kQueueBoxBorder;
static const int kQueueBoxCornerRadius;
static const int kQueueBoxLength;
static const QRgb kQueueBoxGradientColor1;
static const QRgb kQueueBoxGradientColor2;
static const int kQueueOpacitySteps;
static const float kQueueOpacityLowerBound;
int indicator_column_;
};
class PlaylistDelegateBase : public QueuedItemDelegate {
Q_OBJECT
2020-06-15 21:55:05 +02:00
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit PlaylistDelegateBase(QObject *parent, const QString &suffix = QString());
2020-06-15 21:55:05 +02:00
2021-01-26 16:48:04 +01:00
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2021-01-26 16:48:04 +01:00
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
2021-01-26 16:48:04 +01:00
QStyleOptionViewItem Adjusted(const QStyleOptionViewItem &option, const QModelIndex &idx) const;
2018-02-27 18:06:05 +01:00
static const int kMinHeight;
public slots:
2021-01-26 16:48:04 +01:00
bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &idx) override;
2018-02-27 18:06:05 +01:00
protected:
QTreeView *view_;
QString suffix_;
};
class LengthItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit LengthItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class SizeItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit SizeItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class DateItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit DateItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class LastPlayedItemDelegate : public PlaylistDelegateBase {
2021-07-11 09:49:38 +02:00
Q_OBJECT
2021-06-20 19:04:08 +02:00
2020-06-15 21:55:05 +02:00
public:
2020-06-26 22:41:38 +02:00
explicit LastPlayedItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class FileTypeItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-06-26 22:41:38 +02:00
explicit FileTypeItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class TextItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit TextItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
};
class TagCompletionModel : public QStringListModel {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2020-06-15 21:55:05 +02:00
public:
explicit TagCompletionModel(SharedPtr<CollectionBackend> backend, const Playlist::Column column, QObject *parent = nullptr);
2018-02-27 18:06:05 +01:00
2020-06-15 21:55:05 +02:00
private:
2018-02-27 18:06:05 +01:00
static QString database_column(Playlist::Column column);
};
class TagCompleter : public QCompleter {
Q_OBJECT
public:
explicit TagCompleter(SharedPtr<CollectionBackend> backend, Playlist::Column column, QLineEdit *editor);
2020-06-15 21:55:05 +02:00
~TagCompleter() override;
2018-02-27 18:06:05 +01:00
private slots:
2021-01-30 21:53:53 +01:00
void ModelReady();
2018-02-27 18:06:05 +01:00
private:
2018-02-27 18:06:05 +01:00
QLineEdit *editor_;
};
class TagCompletionItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
explicit TagCompletionItemDelegate(QObject *parent, SharedPtr<CollectionBackend> backend, Playlist::Column column) : PlaylistDelegateBase(parent), backend_(backend), column_(column) {};
2018-02-27 18:06:05 +01:00
2021-01-26 16:48:04 +01:00
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
private:
SharedPtr<CollectionBackend> backend_;
2018-02-27 18:06:05 +01:00
Playlist::Column column_;
};
class NativeSeparatorsDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit NativeSeparatorsDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
2018-02-27 18:06:05 +01:00
};
class SongSourceDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
2018-02-27 18:06:05 +01:00
public:
2020-04-07 16:49:15 +02:00
explicit SongSourceDelegate(QObject *parent);
2020-06-15 21:55:05 +02:00
QString displayText(const QVariant &value, const QLocale &locale) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
2018-02-27 18:06:05 +01:00
private:
QPixmap LookupPixmap(const Song::Source source, const QSize size, const qreal device_pixel_ratio) const;
2018-02-27 18:06:05 +01:00
};
class RatingItemDelegate : public PlaylistDelegateBase {
2021-06-20 19:04:08 +02:00
Q_OBJECT
public:
RatingItemDelegate(QObject *parent);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
QString displayText(const QVariant &value, const QLocale &locale) const override;
2021-06-20 19:04:08 +02:00
void set_mouse_over(const QModelIndex &idx, const QModelIndexList &selected_indexes, const QPoint pos) {
mouse_over_index_ = idx;
selected_indexes_ = selected_indexes;
mouse_over_pos_ = pos;
}
void set_mouse_out() { mouse_over_index_ = QModelIndex(); }
bool is_mouse_over() const { return mouse_over_index_.isValid(); }
QModelIndex mouse_over_index() const { return mouse_over_index_; }
private:
RatingPainter painter_;
QModelIndex mouse_over_index_;
QPoint mouse_over_pos_;
QModelIndexList selected_indexes_;
};
class Ebur128LoudnessLUFSItemDelegate : public PlaylistDelegateBase {
Q_OBJECT
public:
explicit Ebur128LoudnessLUFSItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
QString displayText(const QVariant &value, const QLocale &locale) const override;
};
class Ebur128LoudnessRangeLUItemDelegate : public PlaylistDelegateBase {
Q_OBJECT
public:
explicit Ebur128LoudnessRangeLUItemDelegate(QObject *parent) : PlaylistDelegateBase(parent) {}
QString displayText(const QVariant &value, const QLocale &locale) const override;
};
2021-01-26 16:48:04 +01:00
#endif // PLAYLISTDELEGATES_H