2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2017 The Qt Company Ltd.
|
2024-02-22 14:51:16 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2015-01-15 12:38:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <qqmlextensionplugin.h>
|
|
|
|
|
|
|
|
#include <qqmlengine.h>
|
|
|
|
#include <qquickimageprovider.h>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
2016-05-20 14:17:59 +00:00
|
|
|
#include <QDebug>
|
2015-01-15 12:38:40 +00:00
|
|
|
|
|
|
|
class ColorImageProvider : public QQuickImageProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ColorImageProvider()
|
|
|
|
: QQuickImageProvider(QQuickImageProvider::Pixmap)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
|
|
|
|
{
|
|
|
|
int width = 50;
|
|
|
|
int height = 50;
|
|
|
|
|
|
|
|
QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width,
|
|
|
|
requestedSize.height() > 0 ? requestedSize.height() : height);
|
|
|
|
if (size)
|
|
|
|
*size = QSize(pixmap.width(), pixmap.height());
|
|
|
|
pixmap.fill(QColor(id).rgba());
|
|
|
|
|
|
|
|
// draw lines on even y offsets
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
for (int y = 0; y < pixmap.height(); y+=2) {
|
|
|
|
p.drawLine(0, y, pixmap.width(), y);
|
|
|
|
}
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ImageProviderExtensionPlugin : public QQmlExtensionPlugin
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-03-24 11:09:31 +00:00
|
|
|
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
2015-01-15 12:38:40 +00:00
|
|
|
public:
|
|
|
|
void registerTypes(const char *uri)
|
|
|
|
{
|
|
|
|
Q_UNUSED(uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initializeEngine(QQmlEngine *engine, const char *uri)
|
|
|
|
{
|
|
|
|
Q_UNUSED(uri);
|
|
|
|
engine->addImageProvider("colors", new ColorImageProvider);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#include "imageprovider.moc"
|