-
Notifications
You must be signed in to change notification settings - Fork 4
/
julia_display.cpp
65 lines (57 loc) · 1.32 KB
/
julia_display.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <QDebug>
#include <QPainter>
#include <QQuickWindow>
#include "julia_display.hpp"
namespace qmlwrap
{
JuliaDisplay::JuliaDisplay(QQuickItem *parent) : QQuickPaintedItem(parent)
{
}
void JuliaDisplay::paint(QPainter *painter)
{
if(!m_pixmap.isNull())
{
painter->drawPixmap(0,0,m_pixmap);
}
else if(m_svg_renderer != nullptr)
{
const qreal dpr = this->window()->effectiveDevicePixelRatio();
m_svg_renderer->render(painter, QRectF(QPointF(0,0),QSizeF(painter->device()->width()/dpr,painter->device()->height()/dpr)));
}
}
void JuliaDisplay::load_png(jlcxx::ArrayRef<unsigned char> data)
{
if(m_svg_renderer != nullptr)
{
delete m_svg_renderer;
m_svg_renderer = nullptr;
}
if(m_pixmap.isNull())
{
clear();
}
if(!m_pixmap.loadFromData(data.data(), data.size(), "PNG"))
{
qWarning() << "Failed to load PNG data";
clear();
}
update();
}
void JuliaDisplay::load_svg(jlcxx::ArrayRef<unsigned char> data)
{
if(m_svg_renderer == nullptr)
{
m_svg_renderer = new QSvgRenderer(this);
}
if(!m_svg_renderer->load(QByteArray(reinterpret_cast<char*>(data.data()), data.size())))
{
qWarning() << "Failed to load SVG data";
}
update();
}
void JuliaDisplay::clear()
{
m_pixmap = QPixmap(width(), height());
m_pixmap.fill(Qt::transparent);
}
} // namespace qmlwrap