2020-09-24 19:06:57 +02:00
|
|
|
#include "MainWindow.hpp"
|
|
|
|
|
|
|
|
#include "Screen.hpp"
|
|
|
|
|
2020-09-25 13:55:35 +02:00
|
|
|
MainWindow* MainWindow::instance = nullptr;
|
|
|
|
|
|
|
|
MainWindow* MainWindow::Instance()
|
|
|
|
{
|
|
|
|
if (instance == nullptr)
|
|
|
|
{
|
|
|
|
instance = new MainWindow();
|
|
|
|
instance->Setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MainWindow() :
|
|
|
|
QMainWindow(Q_NULLPTR), activePlanet(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::Setup()
|
2020-09-24 19:06:57 +02:00
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
2020-09-25 13:55:35 +02:00
|
|
|
ClosePlanetDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OpenPlanetDialog(Planet* planet)
|
|
|
|
{
|
|
|
|
activePlanet = nullptr;
|
|
|
|
|
|
|
|
ui.config->Enable();
|
|
|
|
ui.config->SetTitle("Planets don't have names yet");
|
|
|
|
ui.config->SetRadius(planet->radius);
|
|
|
|
ui.config->SetX(planet->position.rx());
|
|
|
|
ui.config->SetY(planet->position.ry());
|
2020-09-24 19:06:57 +02:00
|
|
|
|
2020-09-25 13:55:35 +02:00
|
|
|
activePlanet = planet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ClosePlanetDialog()
|
|
|
|
{
|
|
|
|
activePlanet = nullptr;
|
|
|
|
|
|
|
|
ui.config->SetTitle("No planet selected");
|
|
|
|
ui.config->Disable();
|
|
|
|
ui.config->SetRadius(0.f);
|
|
|
|
ui.config->SetX(0.f);
|
|
|
|
ui.config->SetY(0.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnRadiusChanged(double radius)
|
|
|
|
{
|
|
|
|
if(activePlanet != nullptr)
|
|
|
|
activePlanet->radius = radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnXChanged(double x)
|
|
|
|
{
|
|
|
|
if (activePlanet != nullptr)
|
|
|
|
activePlanet->position.rx() = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::OnYChanged(double y)
|
|
|
|
{
|
|
|
|
if (activePlanet != nullptr)
|
|
|
|
activePlanet->position.ry() = y;
|
|
|
|
}
|