src/document.cpp

changeset 126
a7c720aff97c
parent 125
f127982d3412
child 127
f64bfb7f5d26
--- a/src/document.cpp	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/document.cpp	Sun Aug 29 21:28:08 2021 +0300
@@ -43,7 +43,6 @@
 	vertexMap{model},
 	renderer{new Canvas{model, documents, colorTable, this}},
 	ui{*new Ui::Document},
-	objectEditor{model, ldraw::NULL_ID, this},
 	toolsBar{new QToolBar{this}}
 {
 	this->ui.setupUi(this);
@@ -52,8 +51,6 @@
 	this->ui.listView->setModel(model);
 	this->ui.viewportFrame->setLayout(new QVBoxLayout{this->ui.listView});
 	this->ui.viewportFrame->layout()->addWidget(this->renderer);
-	this->ui.objectEditorFrame->setLayout(new QVBoxLayout{this->ui.objectEditorFrame});
-	this->ui.objectEditorFrame->layout()->addWidget(&this->objectEditor);
 	this->toolsBar->setOrientation(Qt::Vertical);
 	this->setMouseTracking(true);
 	connect(this->ui.splitter, &QSplitter::splitterMoved, this, &Document::splitterChanged);
@@ -151,13 +148,9 @@
 
 void Document::selectionChanged(const QSet<ldraw::id_t>& newSelection)
 {
-	if (newSelection.size() == 1)
+	if (this->selectedTool != nullptr)
 	{
-		this->objectEditor.setObjectId(*newSelection.begin());
-	}
-	else
-	{
-		this->objectEditor.setObjectId(ldraw::NULL_ID);
+		this->selectedTool->selectionChanged(newSelection);
 	}
 }
 
@@ -165,7 +158,7 @@
 {
 	for (const QMetaObject* const metaObject : ::toolMetaObjects)
 	{
-		QObject* const objectInstance = metaObject->newInstance(Q_ARG(QObject*, this));
+		QObject* const objectInstance = metaObject->newInstance(Q_ARG(Model*, this->model), Q_ARG(QObject*, this));
 		BaseTool* const toolInstance = qobject_cast<BaseTool*>(objectInstance);
 		if (toolInstance)
 		{
@@ -176,6 +169,15 @@
 			action->setToolTip(toolInstance->toolTip());
 			connect(action, &QAction::triggered, this, &Document::toolActionTriggered);
 			this->toolsBar->addAction(action);
+			QWidget* const widget = toolInstance->toolWidget();
+			if (widget)
+			{
+				this->ui.toolWidgetStack->addWidget(widget);
+			}
+			else
+			{
+				this->ui.toolWidgetStack->addWidget(new QWidget{this});
+			}
 		}
 		else
 		{
@@ -215,6 +217,11 @@
 		{
 			pair.value->setChecked(pair.key == tool);
 		}
+		const int index = this->tools.indexOf(tool);
+		if (index != -1)
+		{
+			this->ui.toolWidgetStack->setCurrentIndex(index);
+		}
 	}
 }
 

mercurial