diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7d88fa7..0730a45 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -82,6 +82,12 @@ void MainWindow::OnYChanged(double y) activePlanet->position.ry() = y; } +void MainWindow::OnDelete() +{ + ui.screen->DeletePlanet(activePlanet); + ClosePlanetDialog(); +} + void MainWindow::OnToggle() { isSimulating = !isSimulating; diff --git a/src/MainWindow.hpp b/src/MainWindow.hpp index 55af7c0..f705e5a 100644 --- a/src/MainWindow.hpp +++ b/src/MainWindow.hpp @@ -23,6 +23,7 @@ public slots: void OnColourChanged(const QColor& color); void OnXChanged(double x); void OnYChanged(double y); + void OnDelete(); void OnToggle(); private: diff --git a/src/PlanetConfig.cpp b/src/PlanetConfig.cpp index e9e043c..fde0551 100644 --- a/src/PlanetConfig.cpp +++ b/src/PlanetConfig.cpp @@ -27,6 +27,9 @@ PlanetConfig::PlanetConfig(QWidget* parent) : connect(ui.yPos, QOverload::of(&QDoubleSpinBox::valueChanged), instance, [instance](double d) { instance->OnYChanged(d); }); + connect(ui.remove, SIGNAL(clicked()), + instance, SLOT(OnDelete())); + connect(ui.toggle, SIGNAL(clicked()), instance, SLOT(OnToggle())); @@ -38,6 +41,7 @@ void PlanetConfig::Disable() ui.colour->setDisabled(true); ui.xPos->setDisabled(true); ui.yPos->setDisabled(true); + ui.remove->setDisabled(true); } void PlanetConfig::Enable() @@ -46,6 +50,7 @@ void PlanetConfig::Enable() ui.colour->setDisabled(false); ui.xPos->setDisabled(false); ui.yPos->setDisabled(false); + ui.remove->setDisabled(false); } void PlanetConfig::SetTitle(const QString& title) diff --git a/src/Screen.cpp b/src/Screen.cpp index 829b381..0a56524 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -45,7 +45,7 @@ void Screen::mouseMoveEvent(QMouseEvent* event) { if (planets[i]->IsInside(event->localPos())) { - setCursor(Qt::OpenHandCursor); + setCursor(Qt::PointingHandCursor); BIND_LMB(lmb_SelectPlanet); hovered = planets[i]; break; @@ -84,6 +84,21 @@ void Screen::mouseReleaseEvent(QMouseEvent* event) mouseDown = false; } +void Screen::DeletePlanet(Planet* planet) +{ + for (std::vector::iterator it = planets.begin(); it != planets.end(); it++) + { + if ((*it) == planet) + { + planets.erase(it); + delete planet; + hovered = nullptr; + selected = nullptr; + break; + } + } +} + void Screen::Render() { update(); diff --git a/src/Screen.hpp b/src/Screen.hpp index 2729bea..50b5dad 100644 --- a/src/Screen.hpp +++ b/src/Screen.hpp @@ -18,6 +18,8 @@ public: void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; + void DeletePlanet(Planet* planet); + private slots: void Render(); diff --git a/ui/PlanetConfig.ui b/ui/PlanetConfig.ui index 8b87d8e..eedd0ac 100644 --- a/ui/PlanetConfig.ui +++ b/ui/PlanetConfig.ui @@ -75,6 +75,9 @@ 1.000000000000000 + + QAbstractSpinBox::AdaptiveDecimalStepType + @@ -125,6 +128,9 @@ 1.000000000000000 + + QAbstractSpinBox::AdaptiveDecimalStepType + @@ -138,6 +144,9 @@ 1.000000000000000 + + QAbstractSpinBox::AdaptiveDecimalStepType + @@ -175,14 +184,30 @@ - + + + + 75 + true + + + + background-color: rgb(255, 58, 58); + - Start Simulation + Delete + + + + Start Simulation + + +