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

#include <QVBoxLayout>
#include <QLabel>
#include "objecteditor.h"
#include "document.h"

ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) :
	QWidget{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)
{
	this->objectId = id;
	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);
			this->layout()->addWidget(&*this->polygonEditor);
		}
		else
		{
			this->polygonEditor->setObjectId(id);
		}
	}
	else
	{
		this->objectTypeNameLabel->clear();
		this->objectTypeIconLabel->clear();
		this->polygonEditor.reset();
	}
}

mercurial