mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-07 02:05:00 +00:00
Added initial support for QQuickImageProvider
This commit is contained in:
parent
ff1d7e13d1
commit
fbe5fd93cc
@ -40,6 +40,7 @@ set(SRC_LIST
|
||||
src/DOtherSideTypesCpp.cpp
|
||||
src/DosQObjectImpl.cpp
|
||||
src/DosQAbstractItemModel.cpp
|
||||
src/DosQQuickImageProvider.cpp
|
||||
)
|
||||
|
||||
include_directories(include include/Qt)
|
||||
|
@ -111,12 +111,46 @@ DOS_API void DOS_CALL dos_qqmlapplicationengine_add_import_path(DosQQmlApplicati
|
||||
/// the engine and so it should die with the engine.
|
||||
DOS_API DosQQmlContext *DOS_CALL dos_qqmlapplicationengine_context(DosQQmlApplicationEngine *vptr);
|
||||
|
||||
/// \brief Calls the QQMLApplicationengine::addImageProvider
|
||||
/// \param vptr The QQmlApplicationEngine
|
||||
/// \param vptr_i A QQuickImageProvider, the QQmlApplicationEngine takes ownership of this pointer
|
||||
DOS_API void DOS_CALL dos_qqmlapplicationengine_addImageProvider(DosQQmlApplicationEngine *vptr, const char* name, DosQQuickImageProvider *vptr_i);
|
||||
|
||||
/// \brief Free the memory allocated for the given QQmlApplicationEngine
|
||||
/// \param vptr The QQmlApplicationEngine
|
||||
DOS_API void DOS_CALL dos_qqmlapplicationengine_delete(DosQQmlApplicationEngine *vptr);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \defgroup QQuickImageProvider QQuickImageProvider
|
||||
/// \brief Functions related to the QQuickImageProvider class
|
||||
/// @{
|
||||
|
||||
/// \brief Create a new QQuickImageProvider
|
||||
/// \return A new QQuickImageProvider
|
||||
/// \note The returned QQuickImageProvider should be freed by using dos_qquickimageprovider_delete(DosQQuickImageProvider*) unless the QQuickImageProvider has been bound to a QQmlApplicationEngine
|
||||
DOS_API DosQQuickImageProvider *DOS_CALL dos_qquickimageprovider_create(PixmapCallback callback);
|
||||
/// \breif Frees a QQuickImageProvider
|
||||
DOS_API void DOS_CALL dos_qquickimageprovider_delete(DosQQuickImageProvider *vptr);
|
||||
/// @}
|
||||
|
||||
/// \defgroup QPixmap QPixmap
|
||||
/// \brief Functions related to the QPixmap class
|
||||
/// @{
|
||||
|
||||
/// \brief Create a new QPixmap
|
||||
DOS_API DosPixmap *DOS_CALL dos_qpixmap_create(int width, int height);
|
||||
/// \brief Frees a QPixmap
|
||||
DOS_API void DOS_CALL dos_qpixmap_delete(DosPixmap *vptr);
|
||||
/// \brief Load image data into a QPixmap from an image file
|
||||
DOS_API void DOS_CALL dos_qpixmap_load(DosPixmap *vptr, const char* filepath, const char* format);
|
||||
/// \brief Load image data into a QPixmap from a buffer
|
||||
DOS_API void DOS_CALL dos_qpixmap_loadFromData(DosPixmap *vptr, const unsigned char* data, unsigned int len);
|
||||
/// \brief Fill a QPixmap with a single color
|
||||
DOS_API void DOS_CALL dos_qpixmap_fill(DosPixmap *vptr, unsigned char r, unsigned char g, unsigned char b, unsigned char a);
|
||||
/// @}
|
||||
|
||||
|
||||
/// \defgroup QQuickStyle QQuickStyle
|
||||
/// \brief Functions related to the QQuickStyle class
|
||||
/// @{
|
||||
@ -130,6 +164,7 @@ DOS_API void DOS_CALL dos_qquickstyle_set_fallback_style(const char *style);
|
||||
/// @}
|
||||
|
||||
|
||||
|
||||
/// \defgroup QQuickView QQuickView
|
||||
/// \brief Functions related to the QQuickView class
|
||||
/// @{
|
||||
|
@ -61,6 +61,22 @@ typedef void DosQMetaObject;
|
||||
/// A pointer to a QObject
|
||||
typedef void DosQObject;
|
||||
|
||||
/// A pointer to a QQuickImageProvider
|
||||
typedef void DosQQuickImageProvider;
|
||||
|
||||
/// A pointer to a QPixmap
|
||||
typedef void DosPixmap;
|
||||
|
||||
/// A pixmap callback to be supplied to an image provider
|
||||
/// \param id Image source id
|
||||
/// \param width pointer to the width of the image
|
||||
/// \param height pointer to the height of the image
|
||||
/// \param requestedHeight sourceSize.height attribute
|
||||
/// \param requestedWidth sourcesSize.width attribute
|
||||
/// \note \p id is the trailing part of an image source url for example "image://<provider_id>/<id>
|
||||
typedef DosPixmap* (*PixmapCallback)(const char *id, int *width, int *height, int requestedWidth, int requestedHeight);
|
||||
|
||||
|
||||
/// Called when a property is readed/written or a slot should be executed
|
||||
/// \param self The pointer of QObject in the binded language
|
||||
/// \param slotName The slotName as DosQVariant
|
||||
|
@ -152,5 +152,4 @@ struct QmlRegisterType {
|
||||
DeleteDObject deleteDObject;
|
||||
};
|
||||
|
||||
|
||||
} // namespace DOS
|
||||
|
20
lib/include/DOtherSide/DosQQuickImageProvider.h
Normal file
20
lib/include/DOtherSide/DosQQuickImageProvider.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
// std
|
||||
#include <iostream>
|
||||
|
||||
// Qt
|
||||
#include <QPixmap>
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
#include "DOtherSideTypes.h"
|
||||
|
||||
class DosImageProvider : public QQuickImageProvider
|
||||
{
|
||||
public:
|
||||
DosImageProvider(PixmapCallback callback);
|
||||
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize);
|
||||
|
||||
private:
|
||||
PixmapCallback m_pixmap_callback;
|
||||
};
|
@ -11,6 +11,7 @@
|
||||
#include <QtQml/QQmlContext>
|
||||
#include <QtQml/QQmlApplicationEngine>
|
||||
#include <QtQuick/QQuickView>
|
||||
#include <QQuickImageProvider>
|
||||
#ifdef QT_QUICKCONTROLS2_LIB
|
||||
#include <QtQuickControls2/QQuickStyle>
|
||||
#endif
|
||||
@ -23,6 +24,7 @@
|
||||
#include "DOtherSide/DosQObjectImpl.h"
|
||||
#include "DOtherSide/DosQAbstractItemModel.h"
|
||||
#include "DOtherSide/DosQDeclarative.h"
|
||||
#include "DOtherSide/DosQQuickImageProvider.h"
|
||||
|
||||
namespace {
|
||||
void register_meta_types()
|
||||
@ -135,12 +137,60 @@ void dos_qqmlapplicationengine_add_import_path(::DosQQmlApplicationEngine *vptr,
|
||||
return engine->rootContext();
|
||||
}
|
||||
|
||||
void dos_qqmlapplicationengine_addImageProvider(DosQQmlApplicationEngine *vptr, const char* name, DosQQuickImageProvider *vptr_i)
|
||||
{
|
||||
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||
auto provider = static_cast<DosImageProvider *>(vptr_i);
|
||||
engine->addImageProvider(QString(name), provider);
|
||||
}
|
||||
|
||||
void dos_qqmlapplicationengine_delete(::DosQQmlApplicationEngine *vptr)
|
||||
{
|
||||
auto engine = static_cast<QQmlApplicationEngine *>(vptr);
|
||||
delete engine;
|
||||
}
|
||||
|
||||
|
||||
::DosQQuickImageProvider *dos_qquickimageprovider_create(PixmapCallback callback)
|
||||
{
|
||||
return new DosImageProvider(callback);
|
||||
}
|
||||
|
||||
void dos_qquickimageprovider_delete(::DosQQuickImageProvider *vptr)
|
||||
{
|
||||
auto provider = static_cast<DosImageProvider *>(vptr);
|
||||
delete provider;
|
||||
}
|
||||
|
||||
::DosPixmap *dos_qpixmap_create(int width, int height)
|
||||
{
|
||||
return new QPixmap(width, height);
|
||||
}
|
||||
|
||||
void dos_qpixmap_delete(DosPixmap *vptr)
|
||||
{
|
||||
auto pixmap = static_cast<QPixmap *>(vptr);
|
||||
delete pixmap;
|
||||
}
|
||||
|
||||
void dos_qpixmap_load(DosPixmap *vptr, const char* filepath, const char* format)
|
||||
{
|
||||
auto pixmap = static_cast<QPixmap *>(vptr);
|
||||
pixmap->load(QString(filepath), format);
|
||||
}
|
||||
|
||||
void dos_qpixmap_loadFromData(DosPixmap *vptr, const unsigned char* data, unsigned int len)
|
||||
{
|
||||
auto pixmap = static_cast<QPixmap *>(vptr);
|
||||
pixmap->loadFromData(data, len);
|
||||
}
|
||||
|
||||
void dos_qpixmap_fill(DosPixmap *vptr, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
|
||||
{
|
||||
auto pixmap = static_cast<QPixmap *>(vptr);
|
||||
pixmap->fill(QColor(r, g, b, a));
|
||||
}
|
||||
|
||||
::DosQQuickView *dos_qquickview_create()
|
||||
{
|
||||
return new QQuickView();
|
||||
|
14
lib/src/DosQQuickImageProvider.cpp
Normal file
14
lib/src/DosQQuickImageProvider.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "DOtherSide/DosQQuickImageProvider.h"
|
||||
|
||||
DosImageProvider::DosImageProvider(PixmapCallback callback) : QQuickImageProvider(QQuickImageProvider::Pixmap),
|
||||
m_pixmap_callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap DosImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
{
|
||||
auto pixmap = m_pixmap_callback(id.toLatin1().data(), &size->rwidth(), &size->rheight(), size->width(), size->height());
|
||||
auto pixmap_copy = *(static_cast<QPixmap*>(pixmap));
|
||||
delete (static_cast<QPixmap*>(pixmap));
|
||||
return pixmap_copy;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user