4
0
mirror of https://github.com/QuasarApp/SoundBand.git synced 2025-05-07 04:29:34 +00:00

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

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

28
SoundBand/app.cpp Normal 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

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

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

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

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

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

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