diff --git a/CMakeLists.txt b/CMakeLists.txt index bafe3457a..5bff63082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ set(SOURCES src/app/logger/Logger.cpp src/app/paths/Paths.cpp src/app/providers/AvatarProvider.cpp + src/app/providers/ImageProvider.cpp src/app/providers/ThumbnailProvider.cpp src/app/translator/DefaultTranslator.cpp src/components/assistant/AssistantModel.cpp @@ -149,6 +150,7 @@ set(HEADERS src/app/logger/Logger.hpp src/app/paths/Paths.hpp src/app/providers/AvatarProvider.hpp + src/app/providers/ImageProvider.hpp src/app/providers/ThumbnailProvider.hpp src/app/translator/DefaultTranslator.hpp src/components/assistant/AssistantModel.hpp diff --git a/src/app/App.cpp b/src/app/App.cpp index 03deab320..2620f89c4 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -38,6 +38,7 @@ #include "logger/Logger.hpp" #include "paths/Paths.hpp" #include "providers/AvatarProvider.hpp" +#include "providers/ImageProvider.hpp" #include "providers/ThumbnailProvider.hpp" #include "translator/DefaultTranslator.hpp" @@ -172,6 +173,7 @@ void App::initContentApp () { // Provide avatars/thumbnails providers. mEngine->addImageProvider(AvatarProvider::PROVIDER_ID, new AvatarProvider()); + mEngine->addImageProvider(ImageProvider::PROVIDER_ID, new ImageProvider()); mEngine->addImageProvider(ThumbnailProvider::PROVIDER_ID, new ThumbnailProvider()); registerTypes(); diff --git a/src/app/providers/ImageProvider.cpp b/src/app/providers/ImageProvider.cpp new file mode 100644 index 000000000..4676d4c5a --- /dev/null +++ b/src/app/providers/ImageProvider.cpp @@ -0,0 +1,58 @@ +/* + * ImageProvider.cpp + * Copyright (C) 2017 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 19, 2017 + * Author: Ronan Abhamon + */ + +#include +#include +#include + +#include "ImageProvider.hpp" + +// ============================================================================= + +const QString ImageProvider::PROVIDER_ID = "internal"; + +ImageProvider::ImageProvider () : QQuickImageProvider( + QQmlImageProviderBase::Image, + QQmlImageProviderBase::ForceAsynchronousImageLoading + ) {} + +QImage ImageProvider::requestImage (const QString &id, QSize *, const QSize &) { + const QString path = QStringLiteral(":/assets/images/%1").arg(id); + + // 1. Build svg renderer. + QSvgRenderer renderer(path); + if (!renderer.isValid()) + return QImage(path); // Not a svg file? + + // 2. Create en empty image. + const QRectF viewBox = renderer.viewBoxF(); + QImage image(static_cast(viewBox.width()), static_cast(viewBox.height()), QImage::Format_ARGB32); + if (image.isNull()) + return QImage(); // Memory cannot be allocated. + image.fill(0x00000000); + + // 3. Paint! + QPainter painter(&image); + renderer.render(&painter); + + return image; +} diff --git a/src/app/providers/ImageProvider.hpp b/src/app/providers/ImageProvider.hpp new file mode 100644 index 000000000..edf87d492 --- /dev/null +++ b/src/app/providers/ImageProvider.hpp @@ -0,0 +1,42 @@ +/* + * ImageProvider.hpp + * Copyright (C) 2017 Belledonne Communications, Grenoble, France + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: June 19, 2017 + * Author: Ronan Abhamon + */ + +#ifndef IMAGE_PROVIDER_H_ +#define IMAGE_PROVIDER_H_ + +#include + +// ============================================================================= + +class ImageProvider : public QQuickImageProvider { +public: + ImageProvider (); + ~ImageProvider () = default; + + QImage requestImage (const QString &id, QSize *size, const QSize &requestedSize) override; + + static const QString PROVIDER_ID; + +private: +}; + +#endif // IMAGE_PROVIDER_H_ diff --git a/ui/modules/Common/Constants/Constants.qml b/ui/modules/Common/Constants/Constants.qml index 6095d45c9..884d48b5e 100644 --- a/ui/modules/Common/Constants/Constants.qml +++ b/ui/modules/Common/Constants/Constants.qml @@ -9,5 +9,5 @@ QtObject { property int sizeMax: 999999 property string imagesFormat: '.svg' - property string imagesPath: 'qrc:/assets/images/' + property string imagesPath: 'image://internal/' }