# HG changeset patch # User Teemu Piippo # Date 1521323955 -7200 # Node ID aee618d087ffb5f1c9e8718962a67a0835237525 # Parent ac8f0297885b7b005404d794d42cab2ed0ce6eb0 Added vertex object editing dialog diff -r ac8f0297885b -r aee618d087ff CMakeLists.txt --- 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 ) diff -r ac8f0297885b -r aee618d087ff src/dialogs/colorselector.cpp --- 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 )); diff -r ac8f0297885b -r aee618d087ff src/dialogs/colorselector.h --- 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 #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 diff -r ac8f0297885b -r aee618d087ff src/editmodes/selectMode.cpp --- 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; } diff -r ac8f0297885b -r aee618d087ff src/toolsets/basictoolset.cpp --- 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 +void createBasicObject(MainWindow* window) +{ + LDObject* object = window->currentDocument()->emplaceAt(window->suggestInsertPoint()); + VertexObjectEditor editor {object}; + editor.exec(); +} + void BasicToolset::newSubfile() { // TODO: @@ -293,22 +306,22 @@ void BasicToolset::newLine() { - // TODO: + createBasicObject(this->m_window); } void BasicToolset::newTriangle() { - // TODO: + createBasicObject(this->m_window); } void BasicToolset::newQuadrilateral() { - // TODO: + createBasicObject(this->m_window); } void BasicToolset::newConditionalLine() { - // TODO: + createBasicObject(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(); + } } } diff -r ac8f0297885b -r aee618d087ff src/widgets/vertexobjecteditor.cpp --- /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 +#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(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(); +} diff -r ac8f0297885b -r aee618d087ff src/widgets/vertexobjecteditor.h --- /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 +#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; +}; diff -r ac8f0297885b -r aee618d087ff src/widgets/vertexobjecteditor.ui --- /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 @@ + + + VertexObjectEditor + + + + 0 + 0 + 295 + 230 + + + + Dialog + + + + + + Vertices + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Colour: + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + VertexObjectEditor + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + VertexObjectEditor + reject() + + + 316 + 260 + + + 286 + 274 + + + + +