GraviSim/src/MainWindow.cpp

96 lines
1.7 KiB
C++
Raw Normal View History

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();
2020-09-25 18:57:44 +02:00
ui.config->SetTitle(planet->name);
2020-09-25 13:55:35 +02:00
ui.config->SetRadius(planet->radius);
2020-09-25 18:57:44 +02:00
ui.config->SetColor(planet->GetColor());
2020-09-25 13:55:35 +02:00
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();
2020-09-25 18:57:44 +02:00
ui.config->SetColor(QColor(0, 0, 0, 0));
2020-09-25 13:55:35 +02:00
ui.config->SetRadius(0.f);
ui.config->SetX(0.f);
ui.config->SetY(0.f);
}
2020-09-25 18:57:44 +02:00
void MainWindow::OnNameChanged(const QString& name)
{
if (activePlanet != nullptr)
activePlanet->name = name;
}
2020-09-25 13:55:35 +02:00
void MainWindow::OnRadiusChanged(double radius)
{
if(activePlanet != nullptr)
activePlanet->radius = radius;
}
2020-09-25 18:57:44 +02:00
void MainWindow::OnColourChanged(const QColor& color)
{
if (activePlanet != nullptr)
activePlanet->SetColor(color);
}
2020-09-25 13:55:35 +02:00
void MainWindow::OnXChanged(double x)
{
if (activePlanet != nullptr)
activePlanet->position.rx() = x;
}
void MainWindow::OnYChanged(double y)
{
if (activePlanet != nullptr)
activePlanet->position.ry() = y;
}
2020-09-25 18:57:44 +02:00
2020-09-26 01:15:54 +02:00
void MainWindow::OnDelete()
{
ui.screen->DeletePlanet(activePlanet);
ClosePlanetDialog();
}
2020-09-25 18:57:44 +02:00
void MainWindow::OnToggle()
{
isSimulating = !isSimulating;
ui.config->SetButtonLabel((isSimulating) ? "Stop Simulation" : "Start Simulation");
}