strawberry-audio-player-win.../src/covermanager/albumcoversearcher.h

118 lines
3.0 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 ALBUMCOVERSEARCHER_H
#define ALBUMCOVERSEARCHER_H
#include "config.h"
#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>
#include <QMap>
#include <QByteArray>
#include <QString>
#include <QImage>
2018-02-27 18:06:05 +01:00
#include <QIcon>
#include "albumcoverfetcher.h"
#include "albumcoverloaderoptions.h"
#include "albumcoverloaderresult.h"
#include "albumcoverimageresult.h"
2020-02-09 02:29:35 +01:00
class QWidget;
class QStandardItem;
class QStandardItemModel;
class QPainter;
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,
Role_ImageData,
Role_Image,
Role_ImageDimensions,
2018-02-27 18:06:05 +01:00
Role_ImageSize,
};
void Init(AlbumCoverFetcher *fetcher);
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();
void SearchFinished(const quint64 id, const CoverProviderSearchResults &results);
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