Wed, 09 Mar 2022 14:22:22 +0200
Show type of object in the object editor
--- a/src/linetypes/conditionaledge.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/conditionaledge.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -29,3 +29,8 @@ { return ":/icons/linetype-conditionaledge.png"; } + +QString ldraw::ConditionalEdge::typeName() const +{ + return QObject::tr("conditional edge"); +}
--- a/src/linetypes/conditionaledge.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/conditionaledge.h Wed Mar 09 14:22:22 2022 +0200 @@ -14,4 +14,5 @@ Type typeIdentifier() const override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; };
--- a/src/linetypes/edge.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/edge.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -34,3 +34,8 @@ { return ":/icons/linetype-edgeline.png"; } + +QString ldraw::Edge::typeName() const +{ + return QObject::tr("edge"); +}
--- a/src/linetypes/edge.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/edge.h Wed Mar 09 14:22:22 2022 +0200 @@ -15,4 +15,5 @@ Type typeIdentifier() const override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; };
--- a/src/linetypes/errorline.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/errorline.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -66,3 +66,8 @@ { return ":/icons/linetype-errorline.png"; } + +QString ldraw::ErrorLine::typeName() const +{ + return QObject::tr("error line"); +}
--- a/src/linetypes/errorline.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/errorline.h Wed Mar 09 14:22:22 2022 +0200 @@ -20,6 +20,7 @@ QDataStream& deserialize(QDataStream& stream) override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; QString text; QString message; protected:
--- a/src/linetypes/metacommand.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/metacommand.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -61,3 +61,8 @@ return ":/icons/chatbubble-ellipses-outline.png"; } +QString ldraw::MetaCommand::typeName() const +{ + return QObject::tr("comment"); +} +
--- a/src/linetypes/metacommand.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/metacommand.h Wed Mar 09 14:22:22 2022 +0200 @@ -19,6 +19,7 @@ QDataStream& deserialize(QDataStream& stream) override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; protected: void setProperty(SetPropertyResult* result, const PropertyKeyValue& pair) override; };
--- a/src/linetypes/object.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/object.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -161,3 +161,8 @@ { return ""; } + +QString ldraw::Empty::typeName() const +{ + return QObject::tr("empty"); +}
--- a/src/linetypes/object.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/object.h Wed Mar 09 14:22:22 2022 +0200 @@ -80,6 +80,7 @@ virtual Type typeIdentifier() const = 0; virtual QString toLDrawCode() const = 0; virtual QString iconName() const; + virtual QString typeName() const = 0; protected: template<Property property, typename Function> @@ -146,4 +147,5 @@ QString textRepresentation() const override; Type typeIdentifier() const override; QString toLDrawCode() const override; + QString typeName() const override; };
--- a/src/linetypes/quadrilateral.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/quadrilateral.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -50,3 +50,8 @@ { return ":/icons/linetype-quadrilateral.png"; } + +QString ldraw::Quadrilateral::typeName() const +{ + return QObject::tr("quadrilateral"); +}
--- a/src/linetypes/quadrilateral.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/quadrilateral.h Wed Mar 09 14:22:22 2022 +0200 @@ -16,4 +16,5 @@ Type typeIdentifier() const override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; };
--- a/src/linetypes/subfilereference.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/subfilereference.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -143,3 +143,8 @@ { return ":/icons/linetype-subfile.png"; } + +QString ldraw::SubfileReference::typeName() const +{ + return QObject::tr("subfile reference"); +}
--- a/src/linetypes/subfilereference.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/subfilereference.h Wed Mar 09 14:22:22 2022 +0200 @@ -27,6 +27,7 @@ QDataStream& deserialize(QDataStream& stream) override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; glm::mat4 transformation; QString referenceName; bool isInverted = false;
--- a/src/linetypes/triangle.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/triangle.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -47,3 +47,8 @@ { return ":/icons/linetype-triangle.png"; } + +QString ldraw::Triangle::typeName() const +{ + return QObject::tr("triangle"); +}
--- a/src/linetypes/triangle.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/linetypes/triangle.h Wed Mar 09 14:22:22 2022 +0200 @@ -16,5 +16,6 @@ Type typeIdentifier() const override; QString toLDrawCode() const override; QString iconName() const override; + QString typeName() const override; };
--- a/src/ui/objecteditor.cpp Wed Mar 09 14:07:58 2022 +0200 +++ b/src/ui/objecteditor.cpp Wed Mar 09 14:22:22 2022 +0200 @@ -1,13 +1,28 @@ #include <QVBoxLayout> +#include <QLabel> #include "objecteditor.h" #include "document.h" ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) : QWidget{document}, - document{document} + document{document}, + objectTypeNameLabel{new QLabel{this}}, + objectTypeIconLabel{new QLabel{this}} { this->setObjectId(id); this->setLayout(new QVBoxLayout{this}); + QWidget* objectTitleLayoutContainer = new QWidget{this}; + QLayout* objectTitleLayout = new QHBoxLayout{objectTitleLayoutContainer}; + objectTitleLayoutContainer->setLayout(objectTitleLayout); + objectTitleLayout->addWidget(this->objectTypeIconLabel); + objectTitleLayout->addWidget(this->objectTypeNameLabel); + objectTitleLayout->addWidget(new QSplitter{Qt::Horizontal, this}); + this->layout()->addWidget(objectTitleLayoutContainer); +} + +QString titleCase(const QString& string) +{ + return string.left(1).toUpper() + string.mid(1); } void ObjectEditor::setObjectId(const ldraw::id_t id) @@ -16,6 +31,8 @@ const ldraw::Object* object = this->document->getModel().get(id); if (object != nullptr and object->numPoints() > 0) { + this->objectTypeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>"); + this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24)); if (not this->polygonEditor.has_value()) { this->polygonEditor.emplace(this->document, id); @@ -28,6 +45,8 @@ } else { + this->objectTypeNameLabel->clear(); + this->objectTypeIconLabel->clear(); this->polygonEditor.reset(); } }
--- a/src/ui/objecteditor.h Wed Mar 09 14:07:58 2022 +0200 +++ b/src/ui/objecteditor.h Wed Mar 09 14:22:22 2022 +0200 @@ -16,4 +16,6 @@ Document* const document; ldraw::id_t objectId = ldraw::NULL_ID; std::optional<PolygonObjectEditor> polygonEditor; + class QLabel* objectTypeNameLabel; + class QLabel* objectTypeIconLabel; };