src/ui/objecteditor.cpp

Wed, 09 Mar 2022 14:22:22 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 09 Mar 2022 14:22:22 +0200
changeset 177
f69d53c053df
parent 152
03f8e6d42e13
child 178
a23024fc98e0
permissions
-rw-r--r--

Show type of object in the object editor

81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QVBoxLayout>
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
2 #include <QLabel>
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 #include "objecteditor.h"
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
4 #include "document.h"
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
6 ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) :
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
7 QWidget{document},
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
8 document{document},
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
9 objectTypeNameLabel{new QLabel{this}},
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
10 objectTypeIconLabel{new QLabel{this}}
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 this->setObjectId(id);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 this->setLayout(new QVBoxLayout{this});
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
14 QWidget* objectTitleLayoutContainer = new QWidget{this};
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
15 QLayout* objectTitleLayout = new QHBoxLayout{objectTitleLayoutContainer};
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
16 objectTitleLayoutContainer->setLayout(objectTitleLayout);
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
17 objectTitleLayout->addWidget(this->objectTypeIconLabel);
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
18 objectTitleLayout->addWidget(this->objectTypeNameLabel);
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
19 objectTitleLayout->addWidget(new QSplitter{Qt::Horizontal, this});
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
20 this->layout()->addWidget(objectTitleLayoutContainer);
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
21 }
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
22
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
23 QString titleCase(const QString& string)
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
24 {
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
25 return string.left(1).toUpper() + string.mid(1);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 void ObjectEditor::setObjectId(const ldraw::id_t id)
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 this->objectId = id;
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
31 const ldraw::Object* object = this->document->getModel().get(id);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 if (object != nullptr and object->numPoints() > 0)
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
34 this->objectTypeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>");
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
35 this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24));
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 if (not this->polygonEditor.has_value())
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
152
03f8e6d42e13 Major refactoring
Teemu Piippo <teemu@hecknology.net>
parents: 81
diff changeset
38 this->polygonEditor.emplace(this->document, id);
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 this->layout()->addWidget(&*this->polygonEditor);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 this->polygonEditor->setObjectId(id);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46 else
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 {
177
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
48 this->objectTypeNameLabel->clear();
f69d53c053df Show type of object in the object editor
Teemu Piippo <teemu@hecknology.net>
parents: 152
diff changeset
49 this->objectTypeIconLabel->clear();
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 this->polygonEditor.reset();
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 }

mercurial