From 5a0da4a523abba31a53a3822fcab4eb0d9328f7b Mon Sep 17 00:00:00 2001 From: adamsjensen Date: Sat, 3 Mar 2018 18:14:31 +0300 Subject: [PATCH] added image provider --- SoundBand/app.cpp | 2 ++ SoundBand/app.h | 3 +++ SoundBand/imageprovider.cpp | 24 ++++++++++++++---------- SoundBand/imageprovider.h | 6 +++++- SoundBand/syncengine.cpp | 16 ++++------------ SoundBand/syncengine.h | 35 +++++++++++++++-------------------- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/SoundBand/app.cpp b/SoundBand/app.cpp index c723979..13901b2 100644 --- a/SoundBand/app.cpp +++ b/SoundBand/app.cpp @@ -1,12 +1,14 @@ #include "app.h" #include #include "syncengine.h" +#include "imageprovider.h" App::App(QObject* ptr): QObject(ptr) { qmlEngine = new QQmlApplicationEngine(); syncEngine = new SyncEngine(); + imageProvider = new ImageProvider(syncEngine); } bool App::run(){ diff --git a/SoundBand/app.h b/SoundBand/app.h index 5304801..75e3787 100644 --- a/SoundBand/app.h +++ b/SoundBand/app.h @@ -6,6 +6,7 @@ class SyncEngine; class QQmlApplicationEngine; +class ImageProvider; /** * @brief The App class @@ -16,6 +17,8 @@ class App : public QObject private: SyncEngine *syncEngine; QQmlApplicationEngine *qmlEngine; + ImageProvider *imageProvider; + public: explicit App(QObject *ptr = nullptr); diff --git a/SoundBand/imageprovider.cpp b/SoundBand/imageprovider.cpp index 9a05dbf..0349094 100644 --- a/SoundBand/imageprovider.cpp +++ b/SoundBand/imageprovider.cpp @@ -1,20 +1,24 @@ #include "imageprovider.h" +#include "syncengine.h" -ImageProvider::ImageProvider(): +ImageProvider::ImageProvider(SyncEngine *engine): QQuickImageProvider(QQuickImageProvider::Pixmap) { - + syncEngine = engine; } QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize){ -// int width = 100; -// int height = 50; + short width = 100; + short height = 50; -// if (size) -// *size = QSize(width, height); -// QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width, -// requestedSize.height() > 0 ? requestedSize.height() : height); -// pixmap.fill(QColor(id).rgba()); + QPixmap result; - return QPixmap(); + if (size) + *size = QSize(width, height); + if(!syncEngine->songImageByName(id, result)){ + return QPixmap(1,1); + } + + return result.scaled(requestedSize); } + diff --git a/SoundBand/imageprovider.h b/SoundBand/imageprovider.h index e80fee6..f77106a 100644 --- a/SoundBand/imageprovider.h +++ b/SoundBand/imageprovider.h @@ -3,10 +3,14 @@ #include #include +class SyncEngine; + class ImageProvider: public QQuickImageProvider { +private: + SyncEngine *syncEngine; public: - explicit ImageProvider(); + explicit ImageProvider(SyncEngine * engine); QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); }; diff --git a/SoundBand/syncengine.cpp b/SoundBand/syncengine.cpp index 9b12b7e..052c68d 100644 --- a/SoundBand/syncengine.cpp +++ b/SoundBand/syncengine.cpp @@ -56,28 +56,20 @@ QStringList SyncEngine::allPlayLists(){ return result; } -QPixmap SyncEngine::curentSongImage() { +bool SyncEngine::songImageById(int id , QPixmap & image) { _lastError = tr("This option not supported."); emit error(); - return QPixmap(1, 1); + return false; } -QPixmap SyncEngine::songImageById(int ) { +bool SyncEngine::songImageByName(const QString& name, QPixmap &image) { _lastError = tr("This option not supported."); emit error(); - return QPixmap(1, 1); -} - -QPixmap SyncEngine::songImageByName(const QString& name) { - - _lastError = tr("This option not supported."); - emit error(); - - return QPixmap(1, 1); + return false; } bool SyncEngine::play(){ diff --git a/SoundBand/syncengine.h b/SoundBand/syncengine.h index 8ce8aa2..ac999b2 100644 --- a/SoundBand/syncengine.h +++ b/SoundBand/syncengine.h @@ -25,6 +25,21 @@ private: Repeat _repeat; public: SyncEngine(); + + /** + * @brief songImageById + * @param id - id of playingSong; + * @return true if all done + */ + bool songImageById(int id , QPixmap& image); + + /** + * @brief songImageById + * @param name - name of Song; + * @return image of song + */ + bool songImageByName(const QString & name, QPixmap &image); + ~SyncEngine(); public slots: @@ -65,26 +80,6 @@ public slots: */ QStringList allPlayLists(); - /** - * @brief curentSongImage - * @return Image of curent song - */ - QPixmap curentSongImage(); - - /** - * @brief songImageById - * @param id - id of playingSong; - * @return - */ - QPixmap songImageById(int id); - - /** - * @brief songImageById - * @param name - name of Song; - * @return image of song - */ - QPixmap songImageByName(const QString & name); - /** * @brief play - play curent music * @return true if all done.