Finished Planet editing GUI
This commit is contained in:
parent
6248f70bb7
commit
526ab00c33
|
@ -7,7 +7,7 @@ cmake_minimum_required (VERSION 3.8)
|
|||
add_executable (GraviSim
|
||||
"main.cpp"
|
||||
"MainWindow.cpp"
|
||||
"Screen.hpp" "Screen.cpp" "Planet.hpp" "Planet.cpp" "PlanetConfig.cpp")
|
||||
"Screen.hpp" "Screen.cpp" "Planet.hpp" "Planet.cpp" "PlanetConfig.cpp" )
|
||||
|
||||
target_link_libraries(GraviSim
|
||||
Qt5::Widgets
|
||||
|
|
|
@ -31,8 +31,9 @@ void MainWindow::OpenPlanetDialog(Planet* planet)
|
|||
activePlanet = nullptr;
|
||||
|
||||
ui.config->Enable();
|
||||
ui.config->SetTitle("Planets don't have names yet");
|
||||
ui.config->SetTitle(planet->name);
|
||||
ui.config->SetRadius(planet->radius);
|
||||
ui.config->SetColor(planet->GetColor());
|
||||
ui.config->SetX(planet->position.rx());
|
||||
ui.config->SetY(planet->position.ry());
|
||||
|
||||
|
@ -45,17 +46,30 @@ void MainWindow::ClosePlanetDialog()
|
|||
|
||||
ui.config->SetTitle("No planet selected");
|
||||
ui.config->Disable();
|
||||
ui.config->SetColor(QColor(0, 0, 0, 0));
|
||||
ui.config->SetRadius(0.f);
|
||||
ui.config->SetX(0.f);
|
||||
ui.config->SetY(0.f);
|
||||
}
|
||||
|
||||
void MainWindow::OnNameChanged(const QString& name)
|
||||
{
|
||||
if (activePlanet != nullptr)
|
||||
activePlanet->name = name;
|
||||
}
|
||||
|
||||
void MainWindow::OnRadiusChanged(double radius)
|
||||
{
|
||||
if(activePlanet != nullptr)
|
||||
activePlanet->radius = radius;
|
||||
}
|
||||
|
||||
void MainWindow::OnColourChanged(const QColor& color)
|
||||
{
|
||||
if (activePlanet != nullptr)
|
||||
activePlanet->SetColor(color);
|
||||
}
|
||||
|
||||
void MainWindow::OnXChanged(double x)
|
||||
{
|
||||
if (activePlanet != nullptr)
|
||||
|
@ -67,3 +81,9 @@ void MainWindow::OnYChanged(double y)
|
|||
if (activePlanet != nullptr)
|
||||
activePlanet->position.ry() = y;
|
||||
}
|
||||
|
||||
void MainWindow::OnToggle()
|
||||
{
|
||||
isSimulating = !isSimulating;
|
||||
ui.config->SetButtonLabel((isSimulating) ? "Stop Simulation" : "Start Simulation");
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@ public:
|
|||
void ClosePlanetDialog();
|
||||
|
||||
public slots:
|
||||
void OnNameChanged(const QString& name);
|
||||
void OnRadiusChanged(double radius);
|
||||
void OnColourChanged(const QColor& color);
|
||||
void OnXChanged(double x);
|
||||
void OnYChanged(double y);
|
||||
void OnToggle();
|
||||
|
||||
private:
|
||||
MainWindow();
|
||||
|
@ -29,6 +32,8 @@ private:
|
|||
private:
|
||||
Ui::MainWindow ui;
|
||||
|
||||
bool isSimulating = false;
|
||||
|
||||
Planet* activePlanet;
|
||||
static MainWindow* instance;
|
||||
};
|
||||
|
|
|
@ -20,6 +20,17 @@ void Planet::Select(bool select)
|
|||
outline.setColor(Qt::transparent);
|
||||
}
|
||||
|
||||
void Planet::SetColor(const QColor& color)
|
||||
{
|
||||
circle = QBrush(color);
|
||||
outline = QPen(Qt::transparent);
|
||||
outline.setWidthF(4.f);
|
||||
|
||||
int h, s, v, a;
|
||||
color.getHsv(&h, &s, &v, &a);
|
||||
selectionColor = QColor::fromHsv((h + 180) % 360, s, v, a);
|
||||
}
|
||||
|
||||
void Planet::Draw(QPainter* painter)
|
||||
{
|
||||
painter->setBrush(circle);
|
||||
|
@ -35,11 +46,6 @@ bool Planet::IsInside(QPointF point) const
|
|||
|
||||
void Planet::Initialize(QColor color)
|
||||
{
|
||||
circle = QBrush(color);
|
||||
outline = QPen(Qt::transparent);
|
||||
outline.setWidthF(4.f);
|
||||
|
||||
int h, s, v, a;
|
||||
color.getHsv(&h, &s, &v, &a);
|
||||
selectionColor = QColor::fromHsv((h + 180) % 360, s, v, a);
|
||||
name = "Unnamed";
|
||||
SetColor(color);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ public:
|
|||
void Resize(float newRadius) { radius = newRadius; }
|
||||
void Select(bool select);
|
||||
|
||||
void SetColor(const QColor& color);
|
||||
const QColor& GetColor() { return circle.color(); }
|
||||
|
||||
void Draw(QPainter* painter);
|
||||
|
||||
bool IsInside(QPointF point) const;
|
||||
|
@ -22,6 +25,7 @@ private:
|
|||
|
||||
public:
|
||||
QPointF position;
|
||||
QString name;
|
||||
float radius;
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,31 +1,41 @@
|
|||
#include "PlanetConfig.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <qcolordialog.h>
|
||||
#include "MainWindow.hpp"
|
||||
|
||||
PlanetConfig::PlanetConfig(QWidget* parent) :
|
||||
QWidget(parent)
|
||||
QWidget(parent), temp(nullptr)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.color = new QColorDialog(this);
|
||||
|
||||
MainWindow* instance = MainWindow::Instance();
|
||||
|
||||
connect(ui.name, SIGNAL(returnPressed()),
|
||||
this, SLOT(TextBoxSlot()));
|
||||
|
||||
connect(ui.radius, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
instance, [instance](double d) { instance->OnRadiusChanged(d); });
|
||||
|
||||
connect(ui.colour, SIGNAL(returnPressed()),
|
||||
this, SLOT(ColourTBSlot()));
|
||||
|
||||
connect(ui.xPos, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
instance, [instance](double d) { instance->OnXChanged(d); });
|
||||
|
||||
connect(ui.yPos, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
||||
instance, [instance](double d) { instance->OnYChanged(d); });
|
||||
|
||||
connect(ui.toggle, SIGNAL(clicked()),
|
||||
instance, SLOT(OnToggle()));
|
||||
|
||||
}
|
||||
|
||||
void PlanetConfig::Disable()
|
||||
{
|
||||
ui.radius->setDisabled(true);
|
||||
ui.colour->setDisabled(true);
|
||||
ui.xPos->setDisabled(true);
|
||||
ui.yPos->setDisabled(true);
|
||||
}
|
||||
|
@ -33,6 +43,7 @@ void PlanetConfig::Disable()
|
|||
void PlanetConfig::Enable()
|
||||
{
|
||||
ui.radius->setDisabled(false);
|
||||
ui.colour->setDisabled(false);
|
||||
ui.xPos->setDisabled(false);
|
||||
ui.yPos->setDisabled(false);
|
||||
}
|
||||
|
@ -47,6 +58,11 @@ void PlanetConfig::SetRadius(double radius)
|
|||
ui.radius->setValue(radius);
|
||||
}
|
||||
|
||||
void PlanetConfig::SetColor(const QColor& color)
|
||||
{
|
||||
ui.colour->setText(QString::number(color.rgb() << 8, 16));
|
||||
}
|
||||
|
||||
void PlanetConfig::SetX(double x)
|
||||
{
|
||||
ui.xPos->setValue(x);
|
||||
|
@ -56,3 +72,19 @@ void PlanetConfig::SetY(double y)
|
|||
{
|
||||
ui.yPos->setValue(y);
|
||||
}
|
||||
|
||||
void PlanetConfig::SetButtonLabel(const QString& label)
|
||||
{
|
||||
ui.toggle->setText(label);
|
||||
}
|
||||
|
||||
void PlanetConfig::ColourTBSlot()
|
||||
{
|
||||
// std::cout << ui.colour->text().toStdString() << std::endl;
|
||||
MainWindow::Instance()->OnColourChanged(QColor::fromRgb(ui.colour->text().toUInt(NULL, 16)));
|
||||
}
|
||||
|
||||
void PlanetConfig::TextBoxSlot()
|
||||
{
|
||||
MainWindow::Instance()->OnNameChanged(ui.name->text());
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
class PlanetConfig : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlanetConfig(QWidget* parent);
|
||||
|
||||
|
@ -14,9 +16,17 @@ public:
|
|||
|
||||
void SetTitle(const QString& title);
|
||||
void SetRadius(double radius);
|
||||
void SetColor(const QColor& color);
|
||||
void SetX(double x);
|
||||
void SetY(double y);
|
||||
|
||||
void SetButtonLabel(const QString& label);
|
||||
|
||||
public slots:
|
||||
void TextBoxSlot();
|
||||
void ColourTBSlot();
|
||||
|
||||
private:
|
||||
Ui::Form ui;
|
||||
QWidget* temp;
|
||||
};
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>436</width>
|
||||
<height>567</height>
|
||||
<width>308</width>
|
||||
<height>380</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -17,38 +17,32 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(222, 222, 222);</string>
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>12</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetNoConstraint</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="QLineEdit" name="name">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Arial</family>
|
||||
<pointsize>12</pointsize>
|
||||
<family>Courier New</family>
|
||||
<pointsize>10</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::AutoText</enum>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignHCenter|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
<property name="maxLength">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -72,20 +66,23 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="radius">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
|
@ -101,25 +98,45 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="color" native="true"/>
|
||||
<widget class="QLineEdit" name="colour">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="inputMask">
|
||||
<string>Hhhhhh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="yPos">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
<property name="singleStep">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="xPos">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(255, 255, 255);</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.989999999999782</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -139,28 +156,31 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="xPos">
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier New</family>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="yPos">
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="toggle">
|
||||
<property name="text">
|
||||
<string>Start Simulation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in a new issue