Qt.labs.sharedimage: Make plugin optional
This moves the sharedimage types into a new library and is meant to make them availabe to the QML compiler at some point in the future. Task-number: QTBUG-90487 Change-Id: If79425a43cb8c1831422631791d35c1f329c7e80 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
9eda73354c
commit
cd8ae755c2
|
@ -9,19 +9,13 @@ qt_internal_add_qml_module(sharedimageplugin
|
|||
VERSION "${CMAKE_PROJECT_VERSION}"
|
||||
CLASSNAME QtQuickSharedImagePlugin
|
||||
SKIP_TYPE_REGISTRATION
|
||||
GENERATE_QMLTYPES
|
||||
INSTALL_QMLTYPES
|
||||
PLUGIN_OPTIONAL
|
||||
SOURCES
|
||||
plugin.cpp
|
||||
qsharedimageloader.cpp qsharedimageloader_p.h
|
||||
sharedimageprovider.cpp sharedimageprovider.h
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Core
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::GuiPrivate
|
||||
Qt::Qml
|
||||
Qt::QuickPrivate
|
||||
Qt::LabsSharedImagePrivate
|
||||
)
|
||||
|
||||
#### Keys ignored in scope 1:.:.:sharedimage.pro:<TRUE>:
|
||||
|
|
|
@ -37,10 +37,11 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtLabsSharedImage/private/qtlabssharedimageglobal_p.h>
|
||||
#include <QtLabsSharedImage/private/qsharedimageprovider_p.h>
|
||||
|
||||
#include <qqmlextensionplugin.h>
|
||||
#include <qqmlengine.h>
|
||||
#include <sharedimageprovider.h>
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmodule Qt.labs.sharedimage 1
|
||||
|
@ -99,8 +100,6 @@
|
|||
The shared image module does not provide any directly usable QML types.
|
||||
*/
|
||||
|
||||
extern void qml_register_types_Qt_labs_sharedimage();
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QtQuickSharedImagePlugin : public QQmlEngineExtensionPlugin
|
||||
|
|
|
@ -12,3 +12,7 @@ endif()
|
|||
if(QT_FEATURE_quick_shadereffect AND TARGET Qt::Quick)
|
||||
add_subdirectory(wavefrontmesh)
|
||||
endif()
|
||||
|
||||
if(QT_FEATURE_systemsemaphore AND TARGET Qt::Quick)
|
||||
add_subdirectory(sharedimage)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
qt_internal_add_module(LabsSharedImage
|
||||
GENERATE_METATYPES
|
||||
SOURCES
|
||||
qsharedimageloader.cpp qsharedimageloader_p.h
|
||||
qsharedimageprovider.cpp qsharedimageprovider_p.h
|
||||
qtlabssharedimageglobal_p.h
|
||||
DEFINES
|
||||
QT_BUILD_LABSSHAREDIMAGE_LIB
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::GuiPrivate
|
||||
Qt::QuickPrivate
|
||||
)
|
||||
|
||||
|
||||
set_target_properties(LabsSharedImage PROPERTIES
|
||||
QT_QML_MODULE_INSTALL_QMLTYPES TRUE
|
||||
QT_QML_MODULE_VERSION ${CMAKE_PROJECT_VERSION}
|
||||
QT_QML_MODULE_URI Qt.labs.sharedimage
|
||||
QT_QMLTYPES_FILENAME plugins.qmltypes
|
||||
QT_QML_MODULE_INSTALL_DIR "${INSTALL_QMLDIR}/Qt/labs/sharedimage"
|
||||
)
|
||||
|
||||
qt6_qml_type_registration(LabsSharedImage)
|
|
@ -40,6 +40,19 @@
|
|||
#ifndef QSHAREDIMAGELOADER_H
|
||||
#define QSHAREDIMAGELOADER_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qtlabssharedimageglobal_p.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QVariant>
|
||||
#include <QLoggingCategory>
|
||||
|
@ -51,7 +64,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcSharedImage);
|
|||
|
||||
class QSharedImageLoaderPrivate;
|
||||
|
||||
class QSharedImageLoader : public QObject
|
||||
class Q_LABSSHAREDIMAGE_PRIVATE_EXPORT QSharedImageLoader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DECLARE_PRIVATE(QSharedImageLoader)
|
|
@ -37,8 +37,7 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <sharedimageprovider.h>
|
||||
#include <qsharedimageloader_p.h>
|
||||
#include <qsharedimageprovider_p.h>
|
||||
#include <private/qquickpixmapcache_p.h>
|
||||
#include <private/qimage_p.h>
|
||||
#include <QImageReader>
|
||||
|
@ -47,80 +46,62 @@
|
|||
|
||||
Q_DECLARE_METATYPE(QQuickImageProviderOptions)
|
||||
|
||||
class QuickSharedImageLoader : public QSharedImageLoader
|
||||
|
||||
QuickSharedImageLoader::QuickSharedImageLoader(QObject *parent) : QSharedImageLoader(parent) {}
|
||||
|
||||
QImage QuickSharedImageLoader::loadFile(const QString &path, ImageParameters *params)
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SharedImageProvider;
|
||||
|
||||
public:
|
||||
enum ImageParameter {
|
||||
OriginalSize = 0,
|
||||
RequestedSize,
|
||||
ProviderOptions,
|
||||
NumImageParameters
|
||||
};
|
||||
|
||||
QuickSharedImageLoader(QObject *parent = nullptr)
|
||||
: QSharedImageLoader(parent)
|
||||
{
|
||||
QImageReader imgio(path);
|
||||
QSize realSize = imgio.size();
|
||||
QSize requestSize;
|
||||
QQuickImageProviderOptions options;
|
||||
if (params) {
|
||||
requestSize = params->value(RequestedSize).toSize();
|
||||
options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
|
||||
}
|
||||
|
||||
protected:
|
||||
QImage loadFile(const QString &path, ImageParameters *params) override
|
||||
{
|
||||
QImageReader imgio(path);
|
||||
QSize realSize = imgio.size();
|
||||
QSize requestSize;
|
||||
QQuickImageProviderOptions options;
|
||||
if (params) {
|
||||
requestSize = params->value(RequestedSize).toSize();
|
||||
options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
|
||||
QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
|
||||
|
||||
if (scSize.isValid())
|
||||
imgio.setScaledSize(scSize);
|
||||
|
||||
QImage image;
|
||||
if (imgio.read(&image)) {
|
||||
if (realSize.isEmpty())
|
||||
realSize = image.size();
|
||||
// Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
|
||||
// This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
|
||||
if (image.format() != QImage::Format_RGB32 && image.format() != QImage::Format_ARGB32_Premultiplied) {
|
||||
QImage::Format newFmt = QImage::Format_RGB32;
|
||||
if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
|
||||
newFmt = QImage::Format_ARGB32_Premultiplied;
|
||||
qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
|
||||
image = image.convertToFormat(newFmt);
|
||||
}
|
||||
|
||||
QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
|
||||
|
||||
if (scSize.isValid())
|
||||
imgio.setScaledSize(scSize);
|
||||
|
||||
QImage image;
|
||||
if (imgio.read(&image)) {
|
||||
if (realSize.isEmpty())
|
||||
realSize = image.size();
|
||||
// Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
|
||||
// This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
|
||||
if (image.format() != QImage::Format_RGB32 && image.format() != QImage::Format_ARGB32_Premultiplied) {
|
||||
QImage::Format newFmt = QImage::Format_RGB32;
|
||||
if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
|
||||
newFmt = QImage::Format_ARGB32_Premultiplied;
|
||||
qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
|
||||
image = image.convertToFormat(newFmt);
|
||||
}
|
||||
}
|
||||
|
||||
if (params && params->count() > OriginalSize)
|
||||
params->replace(OriginalSize, realSize);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
QString key(const QString &path, ImageParameters *params) override
|
||||
{
|
||||
QSize reqSz;
|
||||
QQuickImageProviderOptions opts;
|
||||
if (params) {
|
||||
reqSz = params->value(RequestedSize).toSize();
|
||||
opts = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
|
||||
}
|
||||
if (!reqSz.isValid())
|
||||
return path;
|
||||
int aspect = opts.preserveAspectRatioCrop() || opts.preserveAspectRatioFit() ? 1 : 0;
|
||||
if (params && params->count() > OriginalSize)
|
||||
params->replace(OriginalSize, realSize);
|
||||
|
||||
QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
|
||||
qCDebug(lcSharedImage) << "KEY:" << key;
|
||||
return key;
|
||||
return image;
|
||||
}
|
||||
|
||||
QString QuickSharedImageLoader::key(const QString &path, ImageParameters *params)
|
||||
{
|
||||
QSize reqSz;
|
||||
QQuickImageProviderOptions opts;
|
||||
if (params) {
|
||||
reqSz = params->value(RequestedSize).toSize();
|
||||
opts = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
|
||||
}
|
||||
};
|
||||
if (!reqSz.isValid())
|
||||
return path;
|
||||
int aspect = opts.preserveAspectRatioCrop() || opts.preserveAspectRatioFit() ? 1 : 0;
|
||||
|
||||
QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
|
||||
qCDebug(lcSharedImage) << "KEY:" << key;
|
||||
return key;
|
||||
}
|
||||
|
||||
SharedImageProvider::SharedImageProvider()
|
||||
: QQuickImageProviderWithOptions(QQuickImageProvider::Image), loader(new QuickSharedImageLoader)
|
||||
|
@ -156,5 +137,3 @@ QImage SharedImageProvider::requestImage(const QString &id, QSize *size, const Q
|
|||
|
||||
return img;
|
||||
}
|
||||
|
||||
#include "sharedimageprovider.moc"
|
|
@ -37,16 +37,50 @@
|
|||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef SHAREDIMAGEPROVIDER_H
|
||||
#define SHAREDIMAGEPROVIDER_H
|
||||
#ifndef QSHAREDIMAGEPROVIDER_H
|
||||
#define QSHAREDIMAGEPROVIDER_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include "qtlabssharedimageglobal_p.h"
|
||||
|
||||
#include <QQuickImageProvider>
|
||||
#include <private/qquickpixmapcache_p.h>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class QuickSharedImageLoader;
|
||||
#include "qsharedimageloader_p.h"
|
||||
|
||||
class SharedImageProvider : public QQuickImageProviderWithOptions
|
||||
class SharedImageProvider;
|
||||
|
||||
class QuickSharedImageLoader : public QSharedImageLoader
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SharedImageProvider;
|
||||
|
||||
public:
|
||||
enum ImageParameter {
|
||||
OriginalSize = 0,
|
||||
RequestedSize,
|
||||
ProviderOptions,
|
||||
NumImageParameters
|
||||
};
|
||||
|
||||
QuickSharedImageLoader(QObject *parent = nullptr);
|
||||
protected:
|
||||
QImage loadFile(const QString &path, ImageParameters *params) override;
|
||||
QString key(const QString &path, ImageParameters *params) override;
|
||||
};
|
||||
|
||||
class Q_LABSSHAREDIMAGE_PRIVATE_EXPORT SharedImageProvider : public QQuickImageProviderWithOptions
|
||||
{
|
||||
public:
|
||||
SharedImageProvider();
|
||||
|
@ -56,4 +90,4 @@ public:
|
|||
protected:
|
||||
QScopedPointer<QuickSharedImageLoader> loader;
|
||||
};
|
||||
#endif // SHAREDIMAGEPROVIDER_H
|
||||
#endif // QSHAREDIMAGEPROVIDER_H
|
|
@ -0,0 +1,73 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtQml module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 3 requirements
|
||||
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 2.0 or (at your option) the GNU General
|
||||
** Public license version 3 or any later version approved by the KDE Free
|
||||
** Qt Foundation. The licenses are as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
||||
** https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QTLABSSHAREDIMAGEGLOBAL_P_H
|
||||
#define QTLABSSHAREDIMAGEGLOBAL_P_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if !defined(QT_STATIC)
|
||||
# if defined(QT_BUILD_LABSSHAREDIMAGE_LIB)
|
||||
# define Q_LABSSHAREDIMAGE_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define Q_LABSSHAREDIMAGE_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define Q_LABSSHAREDIMAGE_EXPORT
|
||||
#endif
|
||||
#define Q_LABSSHAREDIMAGE_PRIVATE_EXPORT Q_LABSSHAREDIMAGE_EXPORT
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
void Q_LABSSHAREDIMAGE_PRIVATE_EXPORT qml_register_types_Qt_labs_sharedimage();
|
||||
|
||||
#endif // QTLABSSHAREDIMAGEGLOBAL_P_H
|
|
@ -17,7 +17,8 @@
|
|||
"QtLabsFolderListModel" => "$basedir/src/labs/folderlistmodel",
|
||||
"QtLabsAnimation" => "$basedir/src/labs/animation",
|
||||
"QtLabsWavefrontMesh" => "$basedir/src/labs/wavefrontmesh",
|
||||
"QtLabsQmlModels" => "$basedir/src/labs/models"
|
||||
"QtLabsQmlModels" => "$basedir/src/labs/models",
|
||||
"QtLabsSharedImage" => "$basedir/src/labs/sharedimage"
|
||||
);
|
||||
%inject_headers = (
|
||||
"$basedir/src/qml" => [ "^qqmljsgrammar_p.h", "^qqmljsparser_p.h", "^qml_compile_hash_p.h" ],
|
||||
|
|
Loading…
Reference in New Issue