Wed, 22 Jun 2022 16:13:15 +0300
Done some work on object editor
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/model.h | file | annotate | diff | comparison | revisions | |
src/ui/objecteditor.cpp | file | annotate | diff | comparison | revisions | |
src/ui/objecteditor.h | file | annotate | diff | comparison | revisions | |
src/ui/objecteditor.ui | file | annotate | diff | comparison | revisions |
--- a/src/main.cpp Wed Jun 22 16:13:01 2022 +0300 +++ b/src/main.cpp Wed Jun 22 16:13:15 2022 +0300 @@ -17,6 +17,7 @@ #include "settings.h" #include "ui/circletooloptionswidget.h" #include "messagelog.h" +#include "ui/objecteditor.h" static const QDir LOCALE_DIR {":/locale"}; @@ -290,6 +291,7 @@ void initializeTools(Ui_MainWindow* ui, DocumentManager* documents, QWidget* parent) { CircleToolOptionsWidget* circleToolOptions = new CircleToolOptionsWidget{parent}; + ObjectEditor* objectEditor = new ObjectEditor{parent}; const struct { QString name, tooltip; @@ -300,7 +302,7 @@ .name = QObject::tr("Select"), .tooltip = QObject::tr("Select elements from the model."), .icon = {":/icons/navigate-outline.png"}, - //.widget = this->objectEditor, + .widget = objectEditor, }, { .name = QObject::tr("Draw"),
--- a/src/model.h Wed Jun 22 16:13:01 2022 +0300 +++ b/src/model.h Wed Jun 22 16:13:15 2022 +0300 @@ -76,6 +76,7 @@ static constexpr int NUM_TYPES = Chord + 1; CircularFraction fraction; glm::mat4 transformation; + bool inverted = false; }; constexpr char circularPrimitiveStems[CircularPrimitive::NUM_TYPES][5] = {
--- a/src/ui/objecteditor.cpp Wed Jun 22 16:13:01 2022 +0300 +++ b/src/ui/objecteditor.cpp Wed Jun 22 16:13:15 2022 +0300 @@ -8,14 +8,14 @@ #include "widgets/vec3editor.h" #include "ui_objecteditor.h" -using PropertyValue = std::variant< - const glm::vec3*, - const glm::mat4*, - const QString*, - ldraw::Color, - const CircularFraction*>; +using PropertyPointer = std::variant< + glm::vec3*, + glm::mat4*, + QString*, + ldraw::Color*, + CircularFraction*>; -enum PropertyKey +enum class PropertyKey { Point1, Point2, @@ -31,52 +31,102 @@ Fraction, }; -std::map<PropertyKey, PropertyValue> getProperties(const ModelElement& element) +constexpr std::size_t NUM_PROPERTIES = static_cast<int>(PropertyKey::Fraction) + 1; + +static QString propertyName(PropertyKey key) { - std::map<PropertyKey, PropertyValue> result; + switch (key) { + case PropertyKey::Point1: + return ObjectEditor::tr("Vertex 1"); + case PropertyKey::Point2: + return ObjectEditor::tr("Vertex 2"); + case PropertyKey::Point3: + return ObjectEditor::tr("Vertex 3"); + case PropertyKey::Point4: + return ObjectEditor::tr("Vertex 4"); + case PropertyKey::Control1: + return ObjectEditor::tr("Control point 1"); + case PropertyKey::Control2: + return ObjectEditor::tr("Control point 2"); + case PropertyKey::Color: + return ObjectEditor::tr("Colour"); + case PropertyKey::Transformation: + return ObjectEditor::tr("Transformation"); + case PropertyKey::Name: + return ObjectEditor::tr("Name"); + case PropertyKey::Text: + return ObjectEditor::tr("Text"); + case PropertyKey::Code: + return ObjectEditor::tr("Code"); + case PropertyKey::Fraction: + return ObjectEditor::tr("Fraction"); + } + return ""; +} + +static std::map<PropertyKey, PropertyPointer> collectProperties(ModelElement& element) +{ + std::map<PropertyKey, PropertyPointer> result; std::visit<void>(overloaded{ - [&](const Colored<LineSegment>& edge) { - result[Point1] = &edge.p1; - result[Point2] = &edge.p2; - result[Color] = edge.color; - }, - [&](const Colored<Triangle>& tri) { - result[Point1] = &tri.p1; - result[Point2] = &tri.p2; - result[Point3] = &tri.p3; - result[Color] = tri.color; + [&](Colored<LineSegment>& edge) { + result[PropertyKey::Point1] = &edge.p1; + result[PropertyKey::Point2] = &edge.p2; + result[PropertyKey::Color] = &edge.color; }, - [&](const Colored<Quadrilateral>& quad) { - result[Point1] = &quad.p1; - result[Point2] = &quad.p2; - result[Point3] = &quad.p3; - result[Point4] = &quad.p4; - result[Color] = quad.color; + [&](Colored<Triangle>& tri) { + result[PropertyKey::Point1] = &tri.p1; + result[PropertyKey::Point2] = &tri.p2; + result[PropertyKey::Point3] = &tri.p3; + result[PropertyKey::Color] = &tri.color; + }, + [&](Colored<Quadrilateral>& quad) { + result[PropertyKey::Point1] = &quad.p1; + result[PropertyKey::Point2] = &quad.p2; + result[PropertyKey::Point3] = &quad.p3; + result[PropertyKey::Point4] = &quad.p4; + result[PropertyKey::Color] = &quad.color; }, - [&](const Colored<ConditionalEdge>& cedge) { - result[Point1] = &cedge.p1; - result[Point2] = &cedge.p2; - result[Control1] = &cedge.c1; - result[Control2] = &cedge.c2; - result[Color] = cedge.color; + [&](Colored<ConditionalEdge>& cedge) { + result[PropertyKey::Point1] = &cedge.p1; + result[PropertyKey::Point2] = &cedge.p2; + result[PropertyKey::Control1] = &cedge.c1; + result[PropertyKey::Control2] = &cedge.c2; + result[PropertyKey::Color] = &cedge.color; }, - [&](const Colored<SubfileReference>& ref) { - result[Transformation] = &ref.transformation; - result[Name] = &ref.name; - result[Color] = ref.color; + [&](Colored<SubfileReference>& ref) { + result[PropertyKey::Transformation] = &ref.transformation; + result[PropertyKey::Name] = &ref.name; + result[PropertyKey::Color] = &ref.color; }, - [&](const Colored<CircularPrimitive>& circ) { - result[Transformation] = &circ.transformation; - result[Fraction] = &circ.fraction; - result[Color] = circ.color; + [&](Colored<CircularPrimitive>& circ) { + result[PropertyKey::Transformation] = &circ.transformation; + result[PropertyKey::Fraction] = &circ.fraction; + result[PropertyKey::Color] = &circ.color; }, [&](Empty) {}, - [&](const Comment& comment) { - result[Text] = &comment.text; + [&](Comment& comment) { + result[PropertyKey::Text] = &comment.text; }, - [&](const ParseError& parseError) { - result[Code] = &parseError.code; + [&](ParseError& parseError) { + result[PropertyKey::Code] = &parseError.code; }, }, element); return result; } + + +ObjectEditor::ObjectEditor(QWidget* parent) : + QWidget{parent} +{ + this->ui.setupUi(this); + this->editorwidgets.resize(NUM_PROPERTIES); + QFormLayout* layout = new QFormLayout{this}; + for (std::size_t i = 0; i < NUM_PROPERTIES; ++i) { + const auto key = static_cast<PropertyKey>(i); + QLabel* const label = new QLabel{propertyName(key), this}; + QWidget* const field = new QWidget{this}; + this->editorwidgets[i] = field; + layout->addRow(label, field); + } + this->ui.properties->setLayout(layout); +}
--- a/src/ui/objecteditor.h Wed Jun 22 16:13:01 2022 +0300 +++ b/src/ui/objecteditor.h Wed Jun 22 16:13:15 2022 +0300 @@ -2,3 +2,13 @@ #include <QWidget> #include "../basics.h" #include "../model.h" +#include "ui_objecteditor.h" + +class ObjectEditor final : public QWidget +{ + Q_OBJECT + Ui_ObjectEditor ui; + std::vector<QWidget*> editorwidgets; +public: + ObjectEditor(QWidget* parent); +};
--- a/src/ui/objecteditor.ui Wed Jun 22 16:13:01 2022 +0300 +++ b/src/ui/objecteditor.ui Wed Jun 22 16:13:15 2022 +0300 @@ -6,71 +6,90 @@ <rect> <x>0</x> <y>0</y> - <width>664</width> - <height>468</height> + <width>492</width> + <height>336</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout_2"> + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> + <widget class="QScrollArea" name="scrollArea"> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>472</width> + <height>316</height> + </rect> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> - <widget class="QLabel" name="typeIconLabel"> - <property name="text"> - <string><icon></string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="typeIconLabel"> + <property name="text"> + <string><icon></string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="typeNameLabel"> + <property name="styleSheet"> + <string notr="true">font-weight: bold</string> + </property> + <property name="text"> + <string>Object</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="properties"> + <property name="title"> + <string>Properties</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> </item> <item> - <widget class="QLabel" name="typeNameLabel"> - <property name="styleSheet"> - <string notr="true">font-weight: bold</string> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> </property> - <property name="text"> - <string>Object</string> + <property name="sizeHint" stdset="0"> + <size> + <width>508</width> + <height>20</height> + </size> </property> - </widget> + </spacer> </item> </layout> - </item> - <item> - <widget class="QGroupBox" name="properties"> - <property name="title"> - <string>Properties</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>508</width> - <height>20</height> - </size> - </property> - </spacer> + </widget> + </widget> </item> </layout> </widget>