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

110 lines
2.8 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>
*
* 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>
#include <QWidget>
2018-02-27 18:06:05 +01:00
#include <QDialog>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QMap>
#include <QString>
#include <QImage>
2018-02-27 18:06:05 +01:00
#include <QIcon>
#include <QPainter>
#include <QStyleOption>
2018-02-27 18:06:05 +01:00
#include <QStyledItemDelegate>
#include <QStyleOptionViewItem>
#include <QtEvents>
2018-02-27 18:06:05 +01:00
#include "albumcoverfetcher.h"
#include "albumcoverloaderoptions.h"
class QModelIndex;
2018-02-27 18:06:05 +01:00
class Application;
class Ui_AlbumCoverSearcher;
class SizeOverlayDelegate : public QStyledItemDelegate {
public:
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;
SizeOverlayDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
// This is a dialog that lets the user search for album covers
class AlbumCoverSearcher : public QDialog {
Q_OBJECT
public:
AlbumCoverSearcher(const QIcon &no_cover_icon, Application *app, QWidget *parent);
~AlbumCoverSearcher();
enum Role {
Role_ImageURL = Qt::UserRole + 1,
Role_ImageRequestId,
Role_ImageFetchFinished,
Role_ImageDimensions, // width * height
Role_ImageSize,
};
void Init(AlbumCoverFetcher *fetcher);
QImage Exec(const QString &artist, const QString &album);
protected:
void keyPressEvent(QKeyEvent *);
private slots:
void Search();
void SearchFinished(const quint64 id, const CoverSearchResults &results);
void ImageLoaded(const quint64 id, const QUrl &cover_url, const QImage &image);
2018-02-27 18:06:05 +01:00
void CoverDoubleClicked(const QModelIndex &index);
private:
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