2013-05-09 17:13:04 +00:00
|
|
|
#include "freeformhelper.h"
|
|
|
|
|
2013-06-20 20:21:09 +00:00
|
|
|
#include <cmath>
|
2013-05-09 17:13:04 +00:00
|
|
|
#include <QDialog>
|
2013-05-09 20:33:37 +00:00
|
|
|
#include <QVariant>
|
2013-06-02 17:24:26 +00:00
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QPushButton>
|
2013-06-20 20:21:09 +00:00
|
|
|
#include <QWidget>
|
2013-08-21 21:22:13 +00:00
|
|
|
#include <QInputDialog>
|
2013-11-12 22:15:35 +00:00
|
|
|
#include <QLabel>
|
2013-06-20 20:21:09 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-14 20:32:56 +00:00
|
|
|
#include "dialogrender.h"
|
|
|
|
#include "dialogexplorer.h"
|
2014-06-18 20:10:46 +00:00
|
|
|
#include "RenderConfig.h"
|
2013-12-10 21:32:58 +00:00
|
|
|
#include "DesktopScenery.h"
|
2013-11-12 22:15:35 +00:00
|
|
|
#include "BasePreview.h"
|
2014-06-12 15:45:59 +00:00
|
|
|
#include "SoftwareCanvasRenderer.h"
|
2013-11-14 17:47:03 +00:00
|
|
|
#include "CameraDefinition.h"
|
2013-06-02 17:24:26 +00:00
|
|
|
#include "tools.h"
|
2013-05-09 17:13:04 +00:00
|
|
|
|
2013-05-09 20:33:37 +00:00
|
|
|
Q_DECLARE_METATYPE(double*)
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
FreeFormHelper::FreeFormHelper(QWidget* form_widget)
|
|
|
|
:QObject()
|
|
|
|
{
|
|
|
|
_form_widget = form_widget;
|
|
|
|
_data_changed = false;
|
|
|
|
|
|
|
|
_button_apply = NULL;
|
|
|
|
_button_revert = NULL;
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_presets = NULL;
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FreeFormHelper::~FreeFormHelper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-02 17:24:26 +00:00
|
|
|
bool FreeFormHelper::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::Resize && object == _form_widget)
|
|
|
|
{
|
|
|
|
QSize form_size = ((QResizeEvent*) event)->size();
|
|
|
|
QSize preview_size;
|
|
|
|
|
|
|
|
if (form_size.width() > 1400 && form_size.height() > 900)
|
|
|
|
{
|
2013-08-17 16:08:37 +00:00
|
|
|
preview_size = QSize(320, 320);
|
2013-06-02 17:24:26 +00:00
|
|
|
}
|
2013-08-23 22:51:27 +00:00
|
|
|
else if (form_size.width() < 1100 || form_size.height() < 750)
|
2013-06-02 17:24:26 +00:00
|
|
|
{
|
2013-08-17 16:08:37 +00:00
|
|
|
preview_size = QSize(200, 200);
|
2013-06-02 17:24:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-17 16:08:37 +00:00
|
|
|
preview_size = QSize(260, 260);
|
2013-06-02 17:24:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < _previews.size(); i++)
|
|
|
|
{
|
|
|
|
if (_previews[i]->size() != preview_size)
|
|
|
|
{
|
|
|
|
_previews[i]->setMinimumSize(preview_size);
|
|
|
|
_previews[i]->setMaximumSize(preview_size);
|
|
|
|
_previews[i]->resize(preview_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
void FreeFormHelper::startManaging()
|
|
|
|
{
|
2013-06-02 17:24:26 +00:00
|
|
|
_form_widget->installEventFilter(this);
|
2013-06-20 21:18:15 +00:00
|
|
|
connect(MainWindow::instance(), SIGNAL(refreshed()), this, SLOT(processGlobalRefresh()));
|
2013-06-02 17:24:26 +00:00
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
connect(this, SIGNAL(needLocalRefreshing()), _form_widget, SLOT(refreshFromLocalData()));
|
|
|
|
connect(this, SIGNAL(needGlobalRefreshing()), _form_widget, SLOT(refreshFromFellowData()));
|
|
|
|
connect(this, SIGNAL(needReverting()), _form_widget, SLOT(updateLocalDataFromScenery()));
|
|
|
|
connect(this, SIGNAL(needCommitting()), _form_widget, SLOT(commitLocalDataToScenery()));
|
2013-12-10 21:32:58 +00:00
|
|
|
connect(this, SIGNAL(needAlterRenderer(SoftwareRenderer*)), _form_widget, SLOT(alterRenderer(SoftwareRenderer*)));
|
2013-05-09 17:13:04 +00:00
|
|
|
|
2013-06-20 21:18:15 +00:00
|
|
|
processGlobalRefresh();
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 22:15:35 +00:00
|
|
|
void FreeFormHelper::addPreview(BasePreview* preview, Base2dPreviewRenderer* renderer)
|
2013-05-09 17:13:04 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_previews.append(preview);
|
|
|
|
preview->setRenderer(renderer);
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 20:33:37 +00:00
|
|
|
void FreeFormHelper::addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min, double max, double small_step, double large_step)
|
2013-05-09 17:13:04 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_inputs_decimal.append(slider);
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
slider->setDecimalRange(min, max, small_step, large_step);
|
|
|
|
slider->setDecimalValue(*value);
|
2013-05-09 20:33:37 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
slider->setProperty("data_pointer", QVariant::fromValue<double*>(value));
|
2013-05-09 17:13:04 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
connect(slider, SIGNAL(decimalValueChanged(double)), this, SLOT(processDecimalChange(double)));
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FreeFormHelper::setApplyButton(QPushButton* button)
|
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_apply = button;
|
|
|
|
button->setEnabled(_data_changed);
|
2013-05-09 17:13:04 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(processApplyClicked()));
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FreeFormHelper::setRevertButton(QPushButton* button)
|
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_revert = button;
|
|
|
|
button->setEnabled(_data_changed);
|
2013-05-09 17:13:04 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(processRevertClicked()));
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
void FreeFormHelper::setExploreButton(QPushButton* button)
|
2013-05-09 17:13:04 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_explore = button;
|
|
|
|
|
|
|
|
button->setToolTip(tr("Explore the scenery in 3D, with current changes applied"));
|
|
|
|
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(processExploreClicked()));
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
void FreeFormHelper::setRenderButton(QPushButton* button)
|
2013-05-14 20:32:56 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_render = button;
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
button->setToolTip(tr("Quick render preview, with current changes applied"));
|
2013-08-17 15:04:48 +00:00
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(processRenderClicked()));
|
2013-05-14 20:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
void FreeFormHelper::setLabelText(QLabel* label, QString text)
|
2013-05-14 20:32:56 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
label->setText(text);
|
2013-05-14 20:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
void FreeFormHelper::addPreset(const QString& name)
|
2013-05-14 20:32:56 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_presets << name;
|
2013-05-14 20:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 21:22:13 +00:00
|
|
|
void FreeFormHelper::setPresetButton(QPushButton* button)
|
2013-05-14 20:32:56 +00:00
|
|
|
{
|
2013-08-21 21:22:13 +00:00
|
|
|
_button_presets = button;
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(processPresetClicked()));
|
2013-05-14 20:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
void FreeFormHelper::openDialog(QDialog* dialog)
|
|
|
|
{
|
|
|
|
if (dialog->exec())
|
|
|
|
{
|
|
|
|
processDataChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 20:21:09 +00:00
|
|
|
void FreeFormHelper::gotoMainTab(int position)
|
|
|
|
{
|
2013-06-20 21:18:15 +00:00
|
|
|
MainWindow::instance()->openTab(position);
|
2013-06-20 20:21:09 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
void FreeFormHelper::processDataChange()
|
|
|
|
{
|
|
|
|
_data_changed = true;
|
|
|
|
if (_button_apply)
|
|
|
|
{
|
|
|
|
_button_apply->setEnabled(true);
|
|
|
|
}
|
|
|
|
if (_button_revert)
|
|
|
|
{
|
|
|
|
_button_revert->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < _previews.size(); i++)
|
|
|
|
{
|
|
|
|
_previews[i]->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit needLocalRefreshing();
|
|
|
|
}
|
|
|
|
|
2013-06-20 21:18:15 +00:00
|
|
|
void FreeFormHelper::processGlobalRefresh()
|
|
|
|
{
|
|
|
|
emit needGlobalRefreshing();
|
|
|
|
|
|
|
|
processRevertClicked();
|
|
|
|
}
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
void FreeFormHelper::processRevertClicked()
|
|
|
|
{
|
|
|
|
emit needReverting();
|
|
|
|
|
2013-05-14 20:32:56 +00:00
|
|
|
for (int i = 0; i < _previews.size(); i++)
|
|
|
|
{
|
|
|
|
_previews[i]->redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < _inputs_decimal.size(); i++)
|
|
|
|
{
|
|
|
|
WidgetSliderDecimal* slider = _inputs_decimal.at(i);
|
|
|
|
double* pointer = slider->property("data_pointer").value<double*>();
|
|
|
|
|
|
|
|
if (pointer)
|
|
|
|
{
|
|
|
|
slider->setDecimalValue(*pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 17:13:04 +00:00
|
|
|
_data_changed = false;
|
|
|
|
if (_button_apply)
|
|
|
|
{
|
|
|
|
_button_apply->setEnabled(false);
|
|
|
|
}
|
|
|
|
if (_button_revert)
|
|
|
|
{
|
|
|
|
_button_revert->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
emit needLocalRefreshing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeFormHelper::processApplyClicked()
|
|
|
|
{
|
|
|
|
emit needCommitting();
|
|
|
|
|
2013-06-20 21:18:15 +00:00
|
|
|
MainWindow::instance()->refreshAll();
|
2013-05-09 17:13:04 +00:00
|
|
|
}
|
2013-05-09 20:33:37 +00:00
|
|
|
|
2013-05-14 20:32:56 +00:00
|
|
|
void FreeFormHelper::processExploreClicked()
|
|
|
|
{
|
2013-12-10 21:32:58 +00:00
|
|
|
SoftwareRenderer renderer(DesktopScenery::getCurrent());
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-11-13 22:03:02 +00:00
|
|
|
emit needAlterRenderer(&renderer);
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-11-14 17:47:03 +00:00
|
|
|
CameraDefinition camera;
|
2013-12-10 21:32:58 +00:00
|
|
|
DesktopScenery::getCurrent()->getCamera(&camera);
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-12-10 22:06:57 +00:00
|
|
|
DialogExplorer* dialog = new DialogExplorer(_form_widget, &camera, false, renderer.getScenery());
|
2013-05-14 20:32:56 +00:00
|
|
|
dialog->exec();
|
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeFormHelper::processRenderClicked()
|
|
|
|
{
|
2014-08-20 12:23:35 +00:00
|
|
|
RenderConfig params(400, 300, 1, 3);
|
|
|
|
|
2014-06-12 15:45:59 +00:00
|
|
|
SoftwareCanvasRenderer renderer;
|
2014-08-20 12:23:35 +00:00
|
|
|
renderer.setConfig(params);
|
2014-06-12 15:45:59 +00:00
|
|
|
renderer.setScenery(DesktopScenery::getCurrent());
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2013-11-13 22:03:02 +00:00
|
|
|
emit needAlterRenderer(&renderer);
|
2013-05-14 20:32:56 +00:00
|
|
|
|
2014-08-20 12:23:35 +00:00
|
|
|
DialogRender dialog(_form_widget, &renderer);
|
|
|
|
dialog.startRender();
|
2013-05-14 20:32:56 +00:00
|
|
|
}
|
|
|
|
|
2013-05-09 20:33:37 +00:00
|
|
|
void FreeFormHelper::processDecimalChange(double value)
|
|
|
|
{
|
|
|
|
QObject* signal_sender = sender();
|
|
|
|
|
|
|
|
if (signal_sender && signal_sender->inherits("WidgetSliderDecimal"))
|
|
|
|
{
|
|
|
|
WidgetSliderDecimal* slider = (WidgetSliderDecimal*)signal_sender;
|
|
|
|
double* pointer = slider->property("data_pointer").value<double*>();
|
|
|
|
|
|
|
|
if (pointer)
|
|
|
|
{
|
|
|
|
*pointer = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
processDataChange();
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 14:03:22 +00:00
|
|
|
|
|
|
|
void FreeFormHelper::processPresetClicked()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
QString item = QInputDialog::getItem(_form_widget, tr("Choose a preset"), tr("Preset settings : "), _presets, 0, false, &ok);
|
|
|
|
|
|
|
|
if (ok && !item.isEmpty())
|
|
|
|
{
|
|
|
|
int preset = _presets.indexOf(item);
|
|
|
|
if (preset >= 0)
|
|
|
|
{
|
|
|
|
emit presetSelected(preset);
|
|
|
|
processDataChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|