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

103 lines
2.5 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"
#include "ModelerCameras.h"
2014-09-09 15:56:52 +00:00
#include "RenderPreviewProvider.h"
#include "RenderProcess.h"
#include "RenderConfig.h"
#include <QQmlEngine>
2015-07-22 16:05:24 +00:00
#include <QGuiApplication>
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();
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
cameras = new ModelerCameras(this);
2014-08-28 13:09:47 +00:00
atmosphere = new AtmosphereModeler(this);
water = new WaterModeler(this);
render_process = new RenderProcess(this, render_preview_provider);
2014-08-28 08:29:12 +00:00
}
MainModelerWindow::~MainModelerWindow()
{
2014-08-28 13:09:47 +00:00
delete atmosphere;
delete water;
delete cameras;
2014-08-28 13:09:47 +00:00
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::setQmlProperty(const QString &objectName, const QString &propertyName, const QVariant &value)
{
QObject *item = findQmlObject(objectName);
if (item)
{
item->setProperty(propertyName.toLocal8Bit(), value);
}
}
void MainModelerWindow::setState(const QString &stateName)
{
rootObject()->setProperty("state", stateName);
}
2014-09-09 15:56:52 +00:00
void MainModelerWindow::keyReleaseEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_F5)
{
// Start render in a thread
2015-07-22 17:23:22 +00:00
if (event->modifiers() & Qt::ControlModifier)
{
render_process->startFinalRender();
2015-07-22 17:23:22 +00:00
}
else
{
render_process->startQuickRender();
2015-07-22 17:23:22 +00:00
}
}
else if (event->key() == Qt::Key_F6)
{
render_process->showPreviousRender();
2014-09-09 15:56:52 +00:00
}
else if (event->key() == Qt::Key_Escape)
{
render_process->stopRender();
rootObject()->setProperty("state", QString("Init"));
}
2015-07-22 16:05:24 +00:00
else if (event->key() == Qt::Key_Q)
{
if (event->modifiers() & Qt::ControlModifier)
{
QGuiApplication::instance()->exit();
}
}
2014-09-09 15:56:52 +00:00
}