paysages3d/src/interface/modeler/quickapp/MainModelerWindow.cpp

74 lines
2 KiB
C++
Raw Normal View History

2014-08-28 08:29:12 +00:00
#include "MainModelerWindow.h"
#include "OpenGLView.h"
#include "Scenery.h"
#include "OpenGLRenderer.h"
2014-08-28 13:09:47 +00:00
#include "AtmosphereModeler.h"
#include "WaterModeler.h"
2014-09-09 15:56:52 +00:00
#include "RenderPreviewProvider.h"
#include "RenderProcess.h"
#include "RenderConfig.h"
#include <QQmlEngine>
2014-08-28 08:29:12 +00:00
MainModelerWindow::MainModelerWindow()
{
scenery = new Scenery();
scenery->autoPreset();
renderer = new OpenGLRenderer(scenery);
2014-09-09 15:56:52 +00:00
render_preview_provider = new RenderPreviewProvider();
render_process = new RenderProcess(render_preview_provider);
2014-08-28 08:29:12 +00:00
qmlRegisterType<OpenGLView>("Paysages", 1, 0, "OpenGLView");
2014-09-09 15:56:52 +00:00
engine()->addImageProvider("renderpreviewprovider", render_preview_provider);
2014-08-28 08:29:12 +00:00
2014-09-09 15:56:52 +00:00
setMinimumSize(QSize(1000, 800));
2014-08-28 08:29:12 +00:00
setTitle(QObject::tr("Paysages 3D"));
setResizeMode(QQuickView::SizeRootObjectToView);
setSource(QUrl("qrc:///main.qml"));
2014-08-28 13:09:47 +00:00
atmosphere = new AtmosphereModeler(this);
water = new WaterModeler(this);
2014-08-28 08:29:12 +00:00
}
MainModelerWindow::~MainModelerWindow()
{
2014-08-28 13:09:47 +00:00
delete atmosphere;
delete water;
2014-09-09 15:56:52 +00:00
delete render_preview_provider;
delete render_process;
2014-08-28 08:29:12 +00:00
delete renderer;
delete scenery;
}
2014-08-28 13:09:47 +00:00
QObject *MainModelerWindow::findQmlObject(const QString &objectName)
{
return rootObject()->findChild<QObject *>(objectName);
}
2014-09-09 15:56:52 +00:00
void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_F5)
{
// Start render in a thread
render_process->startRender(scenery, RenderConfig(400, 300, 1, 3));
// Resize preview
QSize preview_size = render_process->getPreviewSize();
findQmlObject("preview_image")->setProperty("width", preview_size.width());
findQmlObject("preview_image")->setProperty("height", preview_size.height());
// Show render dialog
rootObject()->setProperty("state", QString("Render Dialog"));
}
else if (event->key() == Qt::Key_Escape)
{
render_process->stopRender();
rootObject()->setProperty("state", QString("Init"));
}
}