add ui file to object editor

Sun, 13 Mar 2022 20:26:28 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 13 Mar 2022 20:26:28 +0200
changeset 182
27fb1c3c9fbb
parent 181
79de20dc6a1e
child 183
97b591813c8b

add ui file to object editor

CMakeLists.txt file | annotate | diff | comparison | revisions
src/ui/objecteditor.cpp file | annotate | diff | comparison | revisions
src/ui/objecteditor.h file | annotate | diff | comparison | revisions
src/ui/objecteditor.ui file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sun Mar 13 20:11:06 2022 +0200
+++ b/CMakeLists.txt	Sun Mar 13 20:26:28 2022 +0200
@@ -145,6 +145,7 @@
 	src/settingseditor/librarieseditor.ui
 	src/settingseditor/settingseditor.ui
 	src/ui/multiplyfactordialog.ui
+	src/ui/objecteditor.ui
 	src/widgets/colorselectdialog.ui
 	src/widgets/colorindexinput.ui
 	src/widgets/matrixeditor.ui
--- a/src/ui/objecteditor.cpp	Sun Mar 13 20:11:06 2022 +0200
+++ b/src/ui/objecteditor.cpp	Sun Mar 13 20:26:28 2022 +0200
@@ -10,34 +10,17 @@
 #include "widgets/colorbutton.h"
 #include "widgets/colorindexinput.h"
 #include "widgets/vec3editor.h"
-
-template<ldraw::Property property>
-static void makeColorEditor()
-{
-	QString propertyName = ldraw::PropertyTraits<property>::name;
-}
+#include "ui_objecteditor.h"
 
 ObjectEditor::ObjectEditor(Document* document, const ldraw::id_t id) :
 	QWidget{document},
-	document{document},
-	formContainer{new QWidget{this}},
-	objectTypeNameLabel{new QLabel{this}},
-	objectTypeIconLabel{new QLabel{this}}
+	ui{*new Ui_ObjectEditor}, 
+	document{document}
 {
-	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);
-	this->layout()->addWidget(objectTitleLayoutContainer);
-	this->layout()->addWidget(formContainer);
+	this->ui.setupUi(this);
 	this->setObjectId(id);
-
-	QWidget* const parent = this->formContainer;
-	QFormLayout* formLayout = new QFormLayout{parent};
-	this->formContainer->setLayout(formLayout);
-
+	QFormLayout* formLayout = new QFormLayout{ui.properties};
+	this->ui.properties->setLayout(formLayout);
 	for (const ldraw::Property property : ldraw::ALL_PROPERTIES)
 	{
 		QWidget* editorWidget = this->makeEditorWidgetForProperty(property);
@@ -49,8 +32,12 @@
 			this->propertyWidgets[property] = {propertyLabel, editorWidget};
 		}
 	}
+	this->setObjectId(ldraw::NULL_ID);
+}
 
-	this->setObjectId(ldraw::NULL_ID);
+ObjectEditor::~ObjectEditor()
+{
+	delete &this->ui;
 }
 
 QString titleCase(const QString& string)
@@ -79,10 +66,11 @@
 {
 	this->objectId = id;
 	const ldraw::Object* object = this->document->getModel().get(id);
+	this->ui.properties->setVisible(object != nullptr);
 	if (object != nullptr)
 	{
-		this->objectTypeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>");
-		this->objectTypeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24));
+		this->ui.typeNameLabel->setText("<b>" + titleCase(object->typeName()) + "</b>");
+		this->ui.typeIconLabel->setPixmap(QPixmap{object->iconName()}.scaledToWidth(24));
 		for (const ldraw::Property property : ldraw::ALL_PROPERTIES)
 		{
 			const QVariant value = object->getProperty(property);
@@ -100,13 +88,8 @@
 	}
 	else
 	{
-		this->objectTypeNameLabel->clear();
-		this->objectTypeIconLabel->clear();
-		for (auto& pair : this->propertyWidgets)
-		{
-			pair.first->setVisible(false);
-			pair.second->setVisible(false);
-		}
+		this->ui.typeNameLabel->setText(tr("No object selected"));
+		this->ui.typeIconLabel->clear();
 	}
 }
 
--- a/src/ui/objecteditor.h	Sun Mar 13 20:11:06 2022 +0200
+++ b/src/ui/objecteditor.h	Sun Mar 13 20:26:28 2022 +0200
@@ -10,15 +10,14 @@
 	Q_OBJECT
 public:
 	explicit ObjectEditor(Document* document, ldraw::id_t id = ldraw::NULL_ID);
+	~ObjectEditor();
 	void setObjectId(ldraw::id_t id);
 private:
 	Q_SLOT void handleColorChange(ldraw::Color value);
 	Q_SLOT void handleVec3Change(const glm::vec3& value);
+	class Ui_ObjectEditor& ui;
 	Document* const document;
 	ldraw::id_t objectId = ldraw::NULL_ID;
-	QWidget* formContainer;
-	class QLabel* objectTypeNameLabel;
-	class QLabel* objectTypeIconLabel;
 	QMap<ldraw::Property, QPair<QWidget*, QWidget*>> propertyWidgets;
 	QWidget* makeEditorWidgetForProperty(ldraw::Property property);
 	void handlePropertyChange(QObject* caller, const QVariant& value);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ui/objecteditor.ui	Sun Mar 13 20:26:28 2022 +0200
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ObjectEditor</class>
+ <widget class="QWidget" name="ObjectEditor">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>664</width>
+    <height>468</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout_2">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QLabel" name="typeIconLabel">
+         <property name="text">
+          <string>&lt;icon&gt;</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLabel" name="typeNameLabel">
+         <property name="styleSheet">
+          <string notr="true">font-weight: bold</string>
+         </property>
+         <property name="text">
+          <string>Object</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QGroupBox" name="properties">
+       <property name="title">
+        <string>Properties</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="verticalSpacer">
+       <property name="orientation">
+        <enum>Qt::Vertical</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>40</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="horizontalSpacer">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>508</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

mercurial