1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00
ScreenPlay/ScreenPlayWorkshop/src/steamqmlimageprovider.h
2023-01-19 10:33:49 +01:00

49 lines
1.2 KiB
C++

// SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
#pragma once
#include <QImage>
#include <QQuickItem>
#include <QQuickWindow>
#include <QSGNode>
#include <QSGSimpleTextureNode>
#include <QSGTexture>
#include <QtQml>
namespace ScreenPlayWorkshop {
class SteamQMLImageProvider : public QQuickItem {
Q_OBJECT
QML_NAMED_ELEMENT(SteamImage)
public:
SteamQMLImageProvider(QQuickItem* parent);
SteamQMLImageProvider() { setFlag(QQuickItem::ItemHasContents); }
~SteamQMLImageProvider()
{
if (m_texture)
m_texture->deleteLater();
}
QSGNode* updatePaintNode(QSGNode* oldNode, QQuickItem::UpdatePaintNodeData*)
{
QSGSimpleTextureNode* node = static_cast<QSGSimpleTextureNode*>(oldNode);
if (!node) {
node = new QSGSimpleTextureNode();
}
m_texture = window()->createTextureFromImage(m_image);
node->setTexture(m_texture);
node->setRect(boundingRect());
return node;
}
public slots:
void setImage(QImage image)
{
m_image = image.scaledToWidth(boundingRect().width(), Qt::TransformationMode::SmoothTransformation);
update();
}
private:
QImage m_image;
QSGTexture* m_texture = nullptr;
};
}