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 ALBUMCOVERSEARCHER_H
|
|
|
|
#define ALBUMCOVERSEARCHER_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QDialog>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QStyleOption>
|
|
|
|
#include <QStyledItemDelegate>
|
|
|
|
#include <QStyleOptionViewItem>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QMap>
|
2021-02-26 21:03:51 +01:00
|
|
|
#include <QByteArray>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QString>
|
|
|
|
#include <QImage>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QIcon>
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "albumcoverfetcher.h"
|
|
|
|
#include "albumcoverloaderoptions.h"
|
2020-04-20 18:03:18 +02:00
|
|
|
#include "albumcoverloaderresult.h"
|
2021-02-26 21:03:51 +01:00
|
|
|
#include "albumcoverimageresult.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
class QWidget;
|
|
|
|
class QStandardItem;
|
|
|
|
class QStandardItemModel;
|
|
|
|
class QPainter;
|
2018-05-01 00:41:33 +02:00
|
|
|
class QModelIndex;
|
2020-02-09 02:29:35 +01:00
|
|
|
class QKeyEvent;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class Application;
|
|
|
|
class Ui_AlbumCoverSearcher;
|
|
|
|
|
|
|
|
class SizeOverlayDelegate : public QStyledItemDelegate {
|
2021-07-11 09:49:38 +02:00
|
|
|
Q_OBJECT
|
2021-06-20 19:04:08 +02:00
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
public:
|
2018-02-27 18:06:05 +01:00
|
|
|
static const int kMargin;
|
|
|
|
static const int kPaddingX;
|
|
|
|
static const int kPaddingY;
|
|
|
|
static const qreal kBorder;
|
|
|
|
static const qreal kFontPointSize;
|
|
|
|
static const int kBorderAlpha;
|
|
|
|
static const int kBackgroundAlpha;
|
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
explicit SizeOverlayDelegate(QObject *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &idx) const override;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// This is a dialog that lets the user search for album covers
|
|
|
|
class AlbumCoverSearcher : public QDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
public:
|
|
|
|
explicit AlbumCoverSearcher(const QIcon &no_cover_icon, Application *app, QWidget *parent);
|
2020-06-15 21:55:05 +02:00
|
|
|
~AlbumCoverSearcher() override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
enum Role {
|
|
|
|
Role_ImageURL = Qt::UserRole + 1,
|
|
|
|
Role_ImageRequestId,
|
|
|
|
Role_ImageFetchFinished,
|
2021-02-26 21:03:51 +01:00
|
|
|
Role_ImageData,
|
|
|
|
Role_Image,
|
|
|
|
Role_ImageDimensions,
|
2018-02-27 18:06:05 +01:00
|
|
|
Role_ImageSize,
|
|
|
|
};
|
|
|
|
|
|
|
|
void Init(AlbumCoverFetcher *fetcher);
|
|
|
|
|
2021-02-26 21:03:51 +01:00
|
|
|
AlbumCoverImageResult Exec(const QString &artist, const QString &album);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
protected:
|
2020-06-15 21:55:05 +02:00
|
|
|
void keyPressEvent(QKeyEvent*) override;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
private slots:
|
2018-02-27 18:06:05 +01:00
|
|
|
void Search();
|
2021-02-26 21:03:51 +01:00
|
|
|
void SearchFinished(const quint64 id, const CoverProviderSearchResults &results);
|
2020-04-20 18:03:18 +02:00
|
|
|
void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
void CoverDoubleClicked(const QModelIndex &idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-04-07 16:49:15 +02:00
|
|
|
private:
|
2018-02-27 18:06:05 +01:00
|
|
|
Ui_AlbumCoverSearcher *ui_;
|
|
|
|
|
|
|
|
Application *app_;
|
|
|
|
QStandardItemModel *model_;
|
|
|
|
|
|
|
|
QIcon no_cover_icon_;
|
|
|
|
AlbumCoverLoaderOptions options_;
|
|
|
|
AlbumCoverFetcher *fetcher_;
|
|
|
|
|
|
|
|
quint64 id_;
|
|
|
|
QMap<quint64, QStandardItem*> cover_loading_tasks_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ALBUMCOVERSEARCHER_H
|