ArchitectureColoredPainting/UnitTest/ElementRendererTest.h

41 lines
1.3 KiB
C++

#pragma once
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QPainter>
#include "Renderer/Preview/ElementRenderer.h"
#include "Editor/ThirdPartyLib/qquick/qquicksvgparser_p.h"
#include "Editor/util/PainterPathUtil.h"
#include "Renderer/Painting/MaterialStyleStroke.h"
#include "Renderer/Painting/ElementStyle.h"
namespace UnitTest
{
class TestGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
private:
Renderer::ElementRenderer& renderer;
Renderer::ElementStyle& style;
QPainterPath& path;
public:
TestGLWidget(Renderer::ElementStyle& style, QPainterPath& path, QWidget* parent = nullptr)
: QOpenGLWidget(parent), renderer(*Renderer::ElementRenderer::instance()), style(style), path(path) {};
void initializeGL() override
{
initializeOpenGLFunctions();
};
void paintGL() override
{
glClearColor(219 / 255., 78 / 255., 32 / 255., 1.0);
glClear(GL_COLOR_BUFFER_BIT);
float pixelRatio = devicePixelRatioF();
auto [img, pos] = renderer.drawElement(path, style, pixelRatio);
QPainter painter(this);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.drawImage(QRectF(QPointF(0, 0), img.size() / pixelRatio), img);
};
void resizeGL(int w, int h) override {};
};
}