-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QML: Add custom image provider to for showing cover art
- Loading branch information
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "skin/qml/asyncimageprovider.h" | ||
|
||
#include "library/coverartcache.h" | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
|
||
AsyncImageResponse::AsyncImageResponse(const QString& id, const QSize& requestedSize) | ||
: m_id(id), m_requestedSize(requestedSize) { | ||
setAutoDelete(false); | ||
} | ||
|
||
QQuickTextureFactory* AsyncImageResponse::textureFactory() const { | ||
return QQuickTextureFactory::textureFactoryForImage(m_image); | ||
} | ||
|
||
void AsyncImageResponse::run() { | ||
if (m_id.startsWith(QStringLiteral("coverart/"))) { | ||
QString trackLocation = QString::fromUtf8(QByteArray::fromBase64( | ||
m_id.mid(9).toLatin1(), QByteArray::Base64UrlEncoding)); | ||
|
||
// TODO: This code does not allow to override embedded cover art with | ||
// a custom image, which is possible in Mixxx. We need to access the | ||
// actual CoverInfo of the track instead of constructing a default | ||
// instance on the fly. | ||
CoverInfo coverInfo(CoverInfoRelative(), trackLocation); | ||
coverInfo.type = CoverInfoRelative::METADATA; | ||
CoverInfo::LoadedImage loadedImage = coverInfo.loadImage(); | ||
if (loadedImage.result != CoverInfo::LoadedImage::Result::Ok) { | ||
coverInfo.type = CoverInfoRelative::FILE; | ||
loadedImage = coverInfo.loadImage(); | ||
} | ||
m_image = loadedImage.image; | ||
} else { | ||
qWarning() << "ImageProvider: Unknown ID " << m_id; | ||
} | ||
|
||
if (!m_image.isNull() && m_requestedSize.isValid()) { | ||
m_image = m_image.scaled(m_requestedSize); | ||
} | ||
|
||
emit finished(); | ||
} | ||
|
||
QQuickImageResponse* AsyncImageProvider::requestImageResponse( | ||
const QString& id, const QSize& requestedSize) { | ||
AsyncImageResponse* response = new AsyncImageResponse(id, requestedSize); | ||
pool.start(response); | ||
return response; | ||
} | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <QImage> | ||
#include <QQuickAsyncImageProvider> | ||
#include <QRunnable> | ||
#include <QSize> | ||
#include <QString> | ||
#include <QThreadPool> | ||
|
||
#include "library/coverart.h" | ||
|
||
namespace mixxx { | ||
namespace skin { | ||
namespace qml { | ||
|
||
class AsyncImageResponse : public QQuickImageResponse, public QRunnable { | ||
public: | ||
AsyncImageResponse(const QString& id, const QSize& requestedSize); | ||
QQuickTextureFactory* textureFactory() const override; | ||
void run() override; | ||
|
||
QString m_id; | ||
QSize m_requestedSize; | ||
QImage m_image; | ||
}; | ||
|
||
class AsyncImageProvider : public QQuickAsyncImageProvider { | ||
public: | ||
QQuickImageResponse* requestImageResponse( | ||
const QString& id, const QSize& requestedSize) override; | ||
|
||
private: | ||
QThreadPool pool; | ||
}; | ||
|
||
} // namespace qml | ||
} // namespace skin | ||
} // namespace mixxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters