added image provider

This commit is contained in:
adamsjensen 2018-03-03 18:14:31 +03:00
parent f2b7935f53
commit 5a0da4a523
6 changed files with 43 additions and 43 deletions

View File

@ -1,12 +1,14 @@
#include "app.h"
#include <QQmlApplicationEngine>
#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(){

View File

@ -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);

View File

@ -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);
}

View File

@ -3,10 +3,14 @@
#include <QPixmap>
#include <QQuickImageProvider>
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);
};

View File

@ -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(){

View File

@ -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.