Merge branch 'imageProvider' into listViewModels

This commit is contained in:
Andrei Yankovich 2018-03-04 20:34:37 +03:00
commit c31e1042c0
8 changed files with 137 additions and 39 deletions

View File

@ -28,6 +28,8 @@ SOURCES += main.cpp \
../sync/sync.cpp \ ../sync/sync.cpp \
../sync/Log.cpp\ ../sync/Log.cpp\
../sync/exaptions.cpp \ ../sync/exaptions.cpp \
imageprovider.cpp \
app.cpp \
playlistmodel.cpp \ playlistmodel.cpp \
serverlistmodel.cpp \ serverlistmodel.cpp \
playlistsmodel.cpp playlistsmodel.cpp
@ -61,6 +63,8 @@ HEADERS += \
../sync/song.h \ ../sync/song.h \
../sync/sync.h \ ../sync/sync.h \
../sync/Log.h \ ../sync/Log.h \
imageprovider.h \
app.h \
playlistmodel.h \ playlistmodel.h \
serverlistmodel.h \ serverlistmodel.h \
playlistsmodel.h playlistsmodel.h

28
SoundBand/app.cpp Normal file
View File

@ -0,0 +1,28 @@
#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(){
qmlRegisterType<SyncEngine>("SyncEngine",1,0,"SyncEngine");
qmlEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
if (qmlEngine->rootObjects().isEmpty())
return false;
return true;
}
App::~App(){
delete syncEngine;
delete qmlEngine;
}

33
SoundBand/app.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef APP_H
#define APP_H
#include <QObject>
#include "syncengine.h"
class SyncEngine;
class QQmlApplicationEngine;
class ImageProvider;
/**
* @brief The App class
* general application object
*/
class App : public QObject
{
private:
SyncEngine *syncEngine;
QQmlApplicationEngine *qmlEngine;
ImageProvider *imageProvider;
public:
explicit App(QObject *ptr = nullptr);
/**
* @brief run app
* @return false if app not running, true if all done
*/
bool run();
~App();
};
#endif // APP_H

View File

@ -0,0 +1,31 @@
#include "imageprovider.h"
#include "syncengine.h"
ImageProvider::ImageProvider(SyncEngine *engine):
QQuickImageProvider(QQuickImageProvider::Pixmap)
{
syncEngine = engine;
}
QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize){
short width = 100;
short height = 50;
QPixmap result;
if (size)
*size = QSize(width, height);
bool ok;
int songId = id.toShort(&ok);
if(!ok)
return QPixmap(1,1);
if(!syncEngine->songImageById(songId, result)){
return QPixmap(1,1);
}
return result.scaled(requestedSize);
}

18
SoundBand/imageprovider.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef IMAGEPROVIDER_H
#define IMAGEPROVIDER_H
#include <QPixmap>
#include <QQuickImageProvider>
class SyncEngine;
class ImageProvider: public QQuickImageProvider
{
private:
SyncEngine *syncEngine;
public:
explicit ImageProvider(SyncEngine * engine);
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
};
#endif // IMAGEPROVIDER_H

View File

@ -1,6 +1,6 @@
#include <QApplication> #include <QApplication>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "syncengine.h" #include "app.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -9,12 +9,9 @@ int main(int argc, char *argv[])
#endif #endif
QApplication app(argc, argv); QApplication app(argc, argv);
App soundBand;
QQmlApplicationEngine engine; if(!soundBand.run())
qmlRegisterType<SyncEngine>("SyncEngine",1,0,"SyncEngine");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1; return -1;
return app.exec(); return app.exec();
} }

View File

@ -56,28 +56,20 @@ QStringList SyncEngine::allPlayLists(){
return result; return result;
} }
QPixmap SyncEngine::curentSongImage() { bool SyncEngine::songImageById(int id , QPixmap & image) {
_lastError = tr("This option not supported."); _lastError = tr("This option not supported.");
emit error(); 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."); _lastError = tr("This option not supported.");
emit error(); emit error();
return QPixmap(1, 1); return false;
}
QPixmap SyncEngine::songImageByName(const QString& name) {
_lastError = tr("This option not supported.");
emit error();
return QPixmap(1, 1);
} }
bool SyncEngine::play(){ bool SyncEngine::play(){

View File

@ -25,6 +25,21 @@ private:
Repeat _repeat; Repeat _repeat;
public: public:
SyncEngine(); 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(); ~SyncEngine();
public slots: public slots:
@ -65,26 +80,6 @@ public slots:
*/ */
QStringList allPlayLists(); 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 * @brief play - play curent music
* @return true if all done. * @return true if all done.