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