1 #include <QVBoxLayout> |
1 #include <QVBoxLayout> |
|
2 #include <QFormLayout> |
|
3 #include <QPushButton> |
2 #include <QLabel> |
4 #include <QLabel> |
|
5 #include <QSpinBox> |
3 #include "objecteditor.h" |
6 #include "objecteditor.h" |
4 #include "document.h" |
7 #include "document.h" |
|
8 #include "modeleditor.h" |
|
9 #include "widgets/colorbutton.h" |
|
10 #include "widgets/colorindexinput.h" |
|
11 |
|
12 template<ldraw::Property property> |
|
13 static void makeColorEditor() |
|
14 { |
|
15 QString propertyName = ldraw::PropertyTraits<property>::name; |
|
16 } |
5 |
17 |
6 ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) : |
18 ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) : |
7 QWidget{document}, |
19 QWidget{document}, |
8 document{document}, |
20 document{document}, |
|
21 formContainer{new QWidget{this}}, |
9 objectTypeNameLabel{new QLabel{this}}, |
22 objectTypeNameLabel{new QLabel{this}}, |
10 objectTypeIconLabel{new QLabel{this}} |
23 objectTypeIconLabel{new QLabel{this}} |
11 { |
24 { |
12 this->setObjectId(id); |
25 this->polygonEditor.emplace(this->document, id); |
13 this->setLayout(new QVBoxLayout{this}); |
26 this->setLayout(new QVBoxLayout{this}); |
14 QWidget* objectTitleLayoutContainer = new QWidget{this}; |
27 QWidget* objectTitleLayoutContainer = new QWidget{this}; |
15 QLayout* objectTitleLayout = new QHBoxLayout{objectTitleLayoutContainer}; |
28 QLayout* objectTitleLayout = new QHBoxLayout{objectTitleLayoutContainer}; |
16 objectTitleLayoutContainer->setLayout(objectTitleLayout); |
29 objectTitleLayoutContainer->setLayout(objectTitleLayout); |
17 objectTitleLayout->addWidget(this->objectTypeIconLabel); |
30 objectTitleLayout->addWidget(this->objectTypeIconLabel); |
18 objectTitleLayout->addWidget(this->objectTypeNameLabel); |
31 objectTitleLayout->addWidget(this->objectTypeNameLabel); |
19 objectTitleLayout->addWidget(new QSplitter{Qt::Horizontal, this}); |
32 objectTitleLayout->addWidget(new QSplitter{Qt::Horizontal, this}); |
20 this->layout()->addWidget(objectTitleLayoutContainer); |
33 this->layout()->addWidget(objectTitleLayoutContainer); |
|
34 this->layout()->addWidget(&*this->polygonEditor); |
|
35 this->layout()->addWidget(formContainer); |
|
36 this->setObjectId(id); |
|
37 |
|
38 QWidget* const parent = this->formContainer; |
|
39 QFormLayout* formLayout = new QFormLayout{parent}; |
|
40 this->formContainer->setLayout(formLayout); |
|
41 QLabel* colorLabel = new QLabel{"Color", parent}; |
|
42 ColorIndexInput* colorWidget = new ColorIndexInput{document, {0}, parent}; |
|
43 formLayout->addRow(colorLabel, colorWidget); |
|
44 connect(colorWidget, &ColorIndexInput::colorChanged, [this](ldraw::Color color) |
|
45 { |
|
46 const QModelIndex index = this->document->getModel().find(this->objectId); |
|
47 if (index.isValid()) |
|
48 { |
|
49 this->document->editModel()->modifyObjectAt<ldraw::ColoredObject>( |
|
50 index.row(), |
|
51 [color](ldraw::ColoredObject* object) |
|
52 { |
|
53 object->colorIndex = color; |
|
54 } |
|
55 ); |
|
56 } |
|
57 }); |
|
58 this->propertyWidgets[ldraw::Property::Color] = {colorLabel, colorWidget}; |
21 } |
59 } |
22 |
60 |
23 QString titleCase(const QString& string) |
61 QString titleCase(const QString& string) |
24 { |
62 { |
25 return string.left(1).toUpper() + string.mid(1); |
63 return string.left(1).toUpper() + string.mid(1); |
27 |
65 |
28 void ObjectEditor::setObjectId(const ldraw::id_t id) |
66 void ObjectEditor::setObjectId(const ldraw::id_t id) |
29 { |
67 { |
30 this->objectId = id; |
68 this->objectId = id; |
31 const ldraw::Object* object = this->document->getModel().get(id); |
69 const ldraw::Object* object = this->document->getModel().get(id); |
32 if (object != nullptr and object->numPoints() > 0) |
70 this->clear(); |
|
71 if (object != nullptr) |
33 { |
72 { |
34 this->objectTypeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>"); |
73 this->objectTypeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>"); |
35 this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24)); |
74 this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24)); |
36 if (not this->polygonEditor.has_value()) |
75 if (object->numPoints() > 0) |
37 { |
76 { |
38 this->polygonEditor.emplace(this->document, id); |
77 this->polygonEditor->setObjectId(id); |
39 this->layout()->addWidget(&*this->polygonEditor); |
|
40 } |
78 } |
41 else |
79 else |
42 { |
80 { |
43 this->polygonEditor->setObjectId(id); |
81 this->polygonEditor->clear(); |
|
82 } |
|
83 constexpr ldraw::Property prop = ldraw::Property::Color; |
|
84 QVariant color = object->getProperty(prop); |
|
85 this->propertyWidgets[prop].first->setVisible(not color.isNull()); |
|
86 this->propertyWidgets[prop].second->setVisible(not color.isNull()); |
|
87 if (not color.isNull()) |
|
88 { |
|
89 static_cast<ColorIndexInput*>(this->propertyWidgets[prop].second)->setSelectedColor(color.value<ldraw::Color>()); |
44 } |
90 } |
45 } |
91 } |
46 else |
92 else |
47 { |
93 { |
48 this->objectTypeNameLabel->clear(); |
94 for (auto& pair : this->propertyWidgets) |
49 this->objectTypeIconLabel->clear(); |
95 { |
50 this->polygonEditor.reset(); |
96 pair.first->setVisible(false); |
|
97 pair.second->setVisible(false); |
|
98 } |
51 } |
99 } |
52 } |
100 } |
|
101 |
|
102 void ObjectEditor::clear() |
|
103 { |
|
104 this->objectTypeNameLabel->clear(); |
|
105 this->objectTypeIconLabel->clear(); |
|
106 this->polygonEditor->clear(); |
|
107 delete this->formContainer->layout(); |
|
108 } |