Sat, 17 Mar 2018 23:59:15 +0200
Added vertex object editing dialog
--- a/CMakeLists.txt Sat Mar 17 20:47:35 2018 +0200 +++ b/CMakeLists.txt Sat Mar 17 23:59:15 2018 +0200 @@ -89,6 +89,7 @@ src/toolsets/viewtoolset.cpp src/types/matrix.cpp src/widgets/headeredit.cpp + src/widgets/vertexobjecteditor.cpp ) set (LDFORGE_HEADERS @@ -161,6 +162,7 @@ src/toolsets/viewtoolset.h src/types/matrix.h src/widgets/headeredit.h + src/widgets/vertexobjecteditor.h ) set (LDFORGE_FORMS @@ -185,6 +187,7 @@ src/toolsets/fixroundingerrors.ui src/mainwindow.ui src/partdownloader.ui + src/widgets/vertexobjecteditor.ui src/widgets/headeredit.ui )
--- a/src/dialogs/colorselector.cpp Sat Mar 17 20:47:35 2018 +0200 +++ b/src/dialogs/colorselector.cpp Sat Mar 17 23:59:15 2018 +0200 @@ -33,8 +33,7 @@ * Constructs a color selection dialog. */ ColorSelector::ColorSelector(QWidget* parent, LDColor defaultColor) : - QDialog {parent}, - HierarchyElement {parent}, + QDialog {parent}, ui {*new Ui_ColorSelUi}, m_selectedColor {LDColor::nullColor} { @@ -55,14 +54,14 @@ if (color == MainColor) { - faceColor = m_config->mainColor(); - faceColor.setAlphaF(m_config->mainColorAlpha()); + faceColor = ::config->mainColor(); + faceColor.setAlphaF(::config->mainColorAlpha()); } QString edgeColor = luma(faceColor) < 80 ? "white" : "black"; button->setAutoFillBackground(true); button->setStyleSheet(format( - "background-color: #%1; color: %2;", + "background-color: %1; color: %2; border:none;", faceColor.name(QColor::HexArgb), edgeColor ));
--- a/src/dialogs/colorselector.h Sat Mar 17 20:47:35 2018 +0200 +++ b/src/dialogs/colorselector.h Sat Mar 17 23:59:15 2018 +0200 @@ -20,12 +20,11 @@ #include <QDialog> #include "../main.h" #include "../colors.h" -#include "../hierarchyelement.h" /* * Implements a dialog that asks the user to choose an LDraw color from a grid of available colors. Direct colors are also supported. */ -class ColorSelector : public QDialog, public HierarchyElement +class ColorSelector : public QDialog { Q_OBJECT
--- a/src/editmodes/selectMode.cpp Sat Mar 17 20:47:35 2018 +0200 +++ b/src/editmodes/selectMode.cpp Sat Mar 17 23:59:15 2018 +0200 @@ -21,6 +21,7 @@ #include "../canvas.h" #include "../mainwindow.h" #include "../lddocument.h" +#include "../widgets/vertexobjecteditor.h" SelectMode::SelectMode (Canvas* canvas) : Super (canvas), @@ -134,6 +135,9 @@ if (index.isValid()) { // TODO: + LDObject* object = currentDocument()->lookup(index); + VertexObjectEditor editor {object}; + editor.exec(); m_window->endAction(); return true; }
--- a/src/toolsets/basictoolset.cpp Sat Mar 17 20:47:35 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Sat Mar 17 23:59:15 2018 +0200 @@ -25,11 +25,16 @@ #include "../canvas.h" #include "../lddocument.h" #include "../linetypes/modelobject.h" +#include "../linetypes/triangle.h" +#include "../linetypes/quadrilateral.h" +#include "../linetypes/edgeline.h" +#include "../linetypes/conditionaledge.h" #include "../ldobjectiterator.h" #include "../mainwindow.h" #include "../dialogs/colorselector.h" #include "../grid.h" #include "../parser.h" +#include "../widgets/vertexobjecteditor.h" #include "basictoolset.h" BasicToolset::BasicToolset (MainWindow *parent) : @@ -286,6 +291,14 @@ } } +template<typename T> +void createBasicObject(MainWindow* window) +{ + LDObject* object = window->currentDocument()->emplaceAt<T>(window->suggestInsertPoint()); + VertexObjectEditor editor {object}; + editor.exec(); +} + void BasicToolset::newSubfile() { // TODO: @@ -293,22 +306,22 @@ void BasicToolset::newLine() { - // TODO: + createBasicObject<LDEdgeLine>(this->m_window); } void BasicToolset::newTriangle() { - // TODO: + createBasicObject<LDTriangle>(this->m_window); } void BasicToolset::newQuadrilateral() { - // TODO: + createBasicObject<LDQuadrilateral>(this->m_window); } void BasicToolset::newConditionalLine() { - // TODO: + createBasicObject<LDConditionalEdge>(this->m_window); } void BasicToolset::newComment() @@ -326,7 +339,11 @@ if (countof(selectedObjects()) == 1) { LDObject* obj = *selectedObjects().begin(); - // TODO: + if (obj->numVertices() > 0) + { + VertexObjectEditor editor {obj}; + editor.exec(); + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/vertexobjecteditor.cpp Sat Mar 17 23:59:15 2018 +0200 @@ -0,0 +1,97 @@ +#include <QDoubleSpinBox> +#include "../linetypes/modelobject.h" +#include "vertexobjecteditor.h" +#include "ui_vertexobjecteditor.h" +#include "../dialogs/colorselector.h" + +VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) : + QDialog {parent}, + object {object}, + ui {*new Ui_VertexObjectEditor}, + vertexGrid {new QGridLayout} +{ + this->ui.setupUi(this); + this->ui.verticesContainer->setLayout(this->vertexGrid); + connect( + this->ui.color, + &QPushButton::clicked, + [&]() + { + ColorSelector::selectColor(this, this->currentColor, this->currentColor); + this->setColorButton(this->currentColor); + } + ); + + for (int i : range(0, 1, object->numVertices() - 1)) + { + for (Axis axis : {X, Y, Z}) + { + QDoubleSpinBox* spinbox = new QDoubleSpinBox; + spinbox->setMinimum(-1e6); + spinbox->setMaximum(1e6); + spinbox->setDecimals(5); + this->vertexGrid->addWidget(spinbox, i, axis); + } + } + + for (int i : range(0, 1, object->numVertices() - 1)) + { + for (Axis axis : {X, Y, Z}) + { + QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); + + if (spinbox) + spinbox->setValue(this->object->vertex(i)[axis]); + } + } + + this->currentColor = this->object->color(); + this->setColorButton(this->object->color()); +} + +VertexObjectEditor::~VertexObjectEditor() +{ + delete &this->ui; +} + +void VertexObjectEditor::setColorButton(LDColor color) +{ + if (color.isValid()) + { + this->ui.color->setText(color.name()); + this->ui.color->setStyleSheet(format("background-color: %1", color.hexcode())); + this->ui.color->setStyleSheet(format("color: %1", color.edgeColor().name())); + } + else + { + this->ui.color->setText(""); + this->ui.color->setStyleSheet(""); + } +} + +QDoubleSpinBox* VertexObjectEditor::spinboxAt(int i, Axis axis) +{ + QWidget* widget = this->vertexGrid->itemAtPosition(i, axis)->widget(); + return qobject_cast<QDoubleSpinBox*>(widget); +} + +void VertexObjectEditor::accept() +{ + for (int i : range(0, 1, object->numVertices() - 1)) + { + Vertex vertex; + + for (Axis axis : {X, Y, Z}) + { + QDoubleSpinBox* spinbox = this->spinboxAt(i, axis); + + if (spinbox) + vertex.setCoordinate(axis, spinbox->value()); + } + + this->object->setVertex(i, vertex); + } + + this->object->setColor(this->currentColor); + QDialog::accept(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/vertexobjecteditor.h Sat Mar 17 23:59:15 2018 +0200 @@ -0,0 +1,23 @@ +#pragma once +#include <QDialog> +#include "../main.h" + +class VertexObjectEditor : public QDialog +{ + Q_OBJECT + +public: + VertexObjectEditor(LDObject* object = nullptr, QWidget* parent = nullptr); + ~VertexObjectEditor(); + + void accept() override; + +private: + class QDoubleSpinBox* spinboxAt(int i, Axis axis); + void setColorButton(LDColor color); + + class Ui_VertexObjectEditor& ui; + class QGridLayout* vertexGrid; + LDObject* const object; + LDColor currentColor; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/vertexobjecteditor.ui Sat Mar 17 23:59:15 2018 +0200 @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>VertexObjectEditor</class> + <widget class="QDialog" name="VertexObjectEditor"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>295</width> + <height>230</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="verticesContainer"> + <property name="title"> + <string>Vertices</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> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Colour:</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="color"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>VertexObjectEditor</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>VertexObjectEditor</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>