1
0
Fork 0
flightgear/utils/fgqcanvas/fgcanvaswidget.cpp
James Turner bd5a266e9f Qt-based remote canvas application.
Work-in-progress, currently performance is sub-optimal (software
rendering via QPainter API).
2016-12-17 14:24:28 +00:00

51 lines
1.1 KiB
C++

#include "fgcanvaswidget.h"
#include <QDebug>
#include <QPainter>
#include "localprop.h"
#include "fgcanvasgroup.h"
#include "fgcanvaspaintcontext.h"
FGCanvasWidget::FGCanvasWidget(QWidget *parent) :
QWidget(parent)
{
}
void FGCanvasWidget::setRootProperty(LocalProp* root)
{
_canvasRoot = root;
_rootElement = new FGCanvasGroup(nullptr, root);
update();
}
FGCanvasGroup *FGCanvasWidget::rootElement()
{
return _rootElement;
}
void FGCanvasWidget::paintEvent(QPaintEvent *pe)
{
if (!_rootElement) {
return;
}
QPainter painter(this);
painter.fillRect(rect(), Qt::black);
painter.setRenderHint(QPainter::Antialiasing, true);
QSizeF sz(_canvasRoot->value("size[0]", 512).toInt(),
_canvasRoot->value("size[1]", 512).toInt());
FGCanvasPaintContext context(&painter);
// set scaling by canvas size
const double verticalScaling = height() / sz.height();
const double horizontalScaling = width() / sz.width();
const double usedScale = std::min(verticalScaling, horizontalScaling);
painter.scale(usedScale, usedScale);
_rootElement->paint(&context);
}