# HG changeset patch # User Teemu Piippo # Date 1521367239 -7200 # Node ID 389516787a4c6e65a6cd7c385dab0014f80d9710 # Parent aee618d087ffb5f1c9e8718962a67a0835237525 added subfile reference editor diff -r aee618d087ff -r 389516787a4c CMakeLists.txt --- a/CMakeLists.txt Sat Mar 17 23:59:15 2018 +0200 +++ b/CMakeLists.txt Sun Mar 18 12:00:39 2018 +0200 @@ -62,6 +62,7 @@ src/dialogs/externalprogrampathdialog.cpp src/dialogs/generateprimitivedialog.cpp src/dialogs/ldrawpathdialog.cpp + src/dialogs/subfilereferenceeditor.cpp src/dialogs/newpartdialog.cpp src/dialogs/openprogressdialog.cpp src/editmodes/abstractEditMode.cpp @@ -133,6 +134,7 @@ src/dialogs/generateprimitivedialog.h src/dialogs/ldrawpathdialog.h src/dialogs/newpartdialog.h + src/dialogs/subfilereferenceeditor.h src/dialogs/openprogressdialog.h src/editmodes/abstractEditMode.h src/editmodes/circleMode.h @@ -183,6 +185,7 @@ src/dialogs/rectifierdialog.ui src/dialogs/replacecoordinatesdialog.ui src/dialogs/rotationpointdialog.ui + src/dialogs/subfilereferenceeditor.ui src/dialogs/ytruderdialog.ui src/toolsets/fixroundingerrors.ui src/mainwindow.ui diff -r aee618d087ff -r 389516787a4c src/dialogs/subfilereferenceeditor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/subfilereferenceeditor.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -0,0 +1,69 @@ +#include "subfilereferenceeditor.h" +#include "ui_subfilereferenceeditor.h" +#include "../linetypes/modelobject.h" +#include "../primitives.h" +#include "../guiutilities.h" + +SubfileReferenceEditor::SubfileReferenceEditor(LDSubfileReference* reference, QWidget* parent) : + QDialog {parent}, + reference {reference}, + ui {*new Ui::SubfileReferenceEditor} +{ + this->ui.setupUi(this); + this->ui.referenceName->setText(reference->referenceName()); + this->color = reference->color(); + this->ui.positionX->setValue(reference->position().x()); + this->ui.positionY->setValue(reference->position().y()); + this->ui.positionZ->setValue(reference->position().z()); + ::setupColorButton(parent, this->ui.colorButton, &this->color); + for (int i : {0, 1, 2}) + for (int j : {0, 1, 2}) + { + QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); + QDoubleSpinBox* spinbox = item ? qobject_cast(item->widget()) : nullptr; + spinbox->setValue(reference->transformationMatrix()(i, j)); + } + connect( + this->ui.primitivesTreeView, + &QTreeView::clicked, + [&](const QModelIndex& index) + { + QAbstractItemModel* model = this->ui.primitivesTreeView->model(); + QVariant primitiveName = model->data(index, PrimitiveManager::PrimitiveNameRole); + + if (primitiveName.isValid()) + this->ui.referenceName->setText(primitiveName.toString()); + } + ); +} + +void SubfileReferenceEditor::accept() +{ + this->reference->setReferenceName(this->ui.referenceName->text()); + Matrix transformationMatrix; + for (int i : {0, 1, 2}) + for (int j : {0, 1, 2}) + { + QLayoutItem* item = this->ui.matrixLayout->itemAtPosition(i, j); + QDoubleSpinBox* spinbox = item ? qobject_cast(item->widget()) : nullptr; + transformationMatrix(i, j) = spinbox->value(); + } + this->reference->setTransformationMatrix(transformationMatrix); + this->reference->setPosition({ + this->ui.positionX->value(), + this->ui.positionY->value(), + this->ui.positionZ->value() + }); + this->reference->setColor(this->color); + QDialog::accept(); +} + +void SubfileReferenceEditor::setPrimitivesTree(PrimitiveManager* primitives) +{ + this->ui.primitivesTreeView->setModel(primitives); +} + +SubfileReferenceEditor::~SubfileReferenceEditor() +{ + delete &this->ui; +} diff -r aee618d087ff -r 389516787a4c src/dialogs/subfilereferenceeditor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/subfilereferenceeditor.h Sun Mar 18 12:00:39 2018 +0200 @@ -0,0 +1,20 @@ +#pragma once +#include +#include "../main.h" + +class SubfileReferenceEditor : public QDialog +{ + Q_OBJECT + +public: + SubfileReferenceEditor(class LDSubfileReference* reference, QWidget *parent = nullptr); + ~SubfileReferenceEditor(); + + void accept() override; + void setPrimitivesTree(class PrimitiveManager* primitives); + +private: + class Ui_SubfileReferenceEditor& ui; + class LDSubfileReference* const reference; + LDColor color; +}; diff -r aee618d087ff -r 389516787a4c src/dialogs/subfilereferenceeditor.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/dialogs/subfilereferenceeditor.ui Sun Mar 18 12:00:39 2018 +0200 @@ -0,0 +1,297 @@ + + + SubfileReferenceEditor + + + + 0 + 0 + 625 + 642 + + + + Dialog + + + + + + + + + + + Name of subfile: + + + + + + + + + + Colour: + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Position: + + + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + + + Transformation matrix: + + + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + 5 + + + -10000.000000000000000 + + + 10000.000000000000000 + + + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SubfileReferenceEditor + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SubfileReferenceEditor + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -r aee618d087ff -r 389516787a4c src/guiutilities.cpp --- a/src/guiutilities.cpp Sat Mar 17 23:59:15 2018 +0200 +++ b/src/guiutilities.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -18,9 +18,11 @@ #include #include +#include #include "colors.h" #include "guiutilities.h" #include "lddocument.h" +#include "dialogs/colorselector.h" #include "mainwindow.h" GuiUtilities::GuiUtilities (QObject* parent) : @@ -146,3 +148,35 @@ return colors; } + + +void setColorButton(QPushButton* button, LDColor color) +{ + if (color.isValid()) + { + button->setFlat(true); + button->setText(color.name()); + button->setStyleSheet(format("background-color: %1", color.hexcode())); + button->setStyleSheet(format("color: %1", color.edgeColor().name())); + } + else + { + button->setFlat(false); + button->setText(""); + button->setStyleSheet(""); + } +} + +void setupColorButton(QWidget* parent, QPushButton* button, LDColor* color) +{ + QObject::connect( + button, + &QPushButton::clicked, + [&]() + { + if (ColorSelector::selectColor(parent, *color, *color)) + ::setColorButton(button, *color); + } + ); + setColorButton(button, *color); +} diff -r aee618d087ff -r 389516787a4c src/guiutilities.h --- a/src/guiutilities.h Sat Mar 17 23:59:15 2018 +0200 +++ b/src/guiutilities.h Sun Mar 18 12:00:39 2018 +0200 @@ -38,3 +38,5 @@ }; QIcon makeColorIcon(LDColor color, int size); +void setColorButton(class QPushButton* button, LDColor color); +void setupColorButton(QWidget* parent, QPushButton* button, LDColor* color); diff -r aee618d087ff -r 389516787a4c src/linetypes/modelobject.cpp --- a/src/linetypes/modelobject.cpp Sat Mar 17 23:59:15 2018 +0200 +++ b/src/linetypes/modelobject.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -236,6 +236,11 @@ } } +void LDSubfileReference::setReferenceName(const QString& newReferenceName) +{ + changeProperty(&this->m_referenceName, newReferenceName); +} + // ============================================================================= // // Moves this object using the given vertex as a movement List diff -r aee618d087ff -r 389516787a4c src/linetypes/modelobject.h --- a/src/linetypes/modelobject.h Sat Mar 17 23:59:15 2018 +0200 +++ b/src/linetypes/modelobject.h Sun Mar 18 12:00:39 2018 +0200 @@ -230,6 +230,7 @@ bool hasMatrix() const override { return true; } QString typeName() const override { return "subfilereference"; } void serialize(class Serializer& serializer) override; + void setReferenceName(const QString& newReferenceName); private: QString m_referenceName; diff -r aee618d087ff -r 389516787a4c src/primitives.cpp --- a/src/primitives.cpp Sat Mar 17 23:59:15 2018 +0200 +++ b/src/primitives.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -551,8 +551,16 @@ { case Qt::DisplayRole: return format("%1 - %2", primitive.name, primitive.title); + case Qt::DecorationRole: return MainWindow::getIcon("subfilereference"); + + case PrimitiveNameRole: + return primitive.name; + + case PrimitiveDescriptionRole: + return primitive.title; + default: return {}; } @@ -566,8 +574,10 @@ { case Qt::DisplayRole: return category->name(); + case Qt::DecorationRole: return MainWindow::getIcon("folder"); + default: return {}; } diff -r aee618d087ff -r 389516787a4c src/primitives.h --- a/src/primitives.h Sat Mar 17 23:59:15 2018 +0200 +++ b/src/primitives.h Sun Mar 18 12:00:39 2018 +0200 @@ -91,6 +91,12 @@ Q_OBJECT public: + enum + { + PrimitiveNameRole = Qt::UserRole + 10, + PrimitiveDescriptionRole, + }; + PrimitiveManager(QObject* parent); PrimitiveScanner* activeScanner(); diff -r aee618d087ff -r 389516787a4c src/toolsets/basictoolset.cpp --- a/src/toolsets/basictoolset.cpp Sat Mar 17 23:59:15 2018 +0200 +++ b/src/toolsets/basictoolset.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -32,6 +32,7 @@ #include "../ldobjectiterator.h" #include "../mainwindow.h" #include "../dialogs/colorselector.h" +#include "../dialogs/subfilereferenceeditor.h" #include "../grid.h" #include "../parser.h" #include "../widgets/vertexobjecteditor.h" @@ -292,36 +293,44 @@ } template -void createBasicObject(MainWindow* window) +static T* createObject(MainWindow* window) { - LDObject* object = window->currentDocument()->emplaceAt(window->suggestInsertPoint()); + return window->currentDocument()->emplaceAt(window->suggestInsertPoint()); +} + +template +static void createVertexObject(MainWindow* window) +{ + LDObject* object = createObject(window); VertexObjectEditor editor {object}; editor.exec(); } void BasicToolset::newSubfile() { - // TODO: + LDSubfileReference* reference = createObject(this->m_window); + SubfileReferenceEditor editor {reference, this->m_window}; + editor.exec(); } void BasicToolset::newLine() { - createBasicObject(this->m_window); + createVertexObject(this->m_window); } void BasicToolset::newTriangle() { - createBasicObject(this->m_window); + createVertexObject(this->m_window); } void BasicToolset::newQuadrilateral() { - createBasicObject(this->m_window); + createVertexObject(this->m_window); } void BasicToolset::newConditionalLine() { - createBasicObject(this->m_window); + createVertexObject(this->m_window); } void BasicToolset::newComment() diff -r aee618d087ff -r 389516787a4c src/widgets/vertexobjecteditor.cpp --- a/src/widgets/vertexobjecteditor.cpp Sat Mar 17 23:59:15 2018 +0200 +++ b/src/widgets/vertexobjecteditor.cpp Sun Mar 18 12:00:39 2018 +0200 @@ -3,6 +3,7 @@ #include "vertexobjecteditor.h" #include "ui_vertexobjecteditor.h" #include "../dialogs/colorselector.h" +#include "../guiutilities.h" VertexObjectEditor::VertexObjectEditor(LDObject* object, QWidget *parent) : QDialog {parent}, @@ -12,15 +13,8 @@ { 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); - } - ); + this->currentColor = this->object->color(); + ::setupColorButton(parent, this->ui.color, &this->currentColor); for (int i : range(0, 1, object->numVertices() - 1)) { @@ -44,9 +38,6 @@ spinbox->setValue(this->object->vertex(i)[axis]); } } - - this->currentColor = this->object->color(); - this->setColorButton(this->object->color()); } VertexObjectEditor::~VertexObjectEditor() @@ -54,21 +45,6 @@ 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(); diff -r aee618d087ff -r 389516787a4c src/widgets/vertexobjecteditor.h --- a/src/widgets/vertexobjecteditor.h Sat Mar 17 23:59:15 2018 +0200 +++ b/src/widgets/vertexobjecteditor.h Sun Mar 18 12:00:39 2018 +0200 @@ -14,7 +14,6 @@ private: class QDoubleSpinBox* spinboxAt(int i, Axis axis); - void setColorButton(LDColor color); class Ui_VertexObjectEditor& ui; class QGridLayout* vertexGrid;