moved ObjectEditor under SelectTool

Sun, 29 Aug 2021 21:28:08 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 29 Aug 2021 21:28:08 +0300
changeset 126
a7c720aff97c
parent 125
f127982d3412
child 127
f64bfb7f5d26

moved ObjectEditor under SelectTool

src/document.cpp file | annotate | diff | comparison | revisions
src/document.h file | annotate | diff | comparison | revisions
src/document.ui file | annotate | diff | comparison | revisions
src/tools/basetool.cpp file | annotate | diff | comparison | revisions
src/tools/basetool.h file | annotate | diff | comparison | revisions
src/tools/drawtool.cpp file | annotate | diff | comparison | revisions
src/tools/drawtool.h file | annotate | diff | comparison | revisions
src/tools/selecttool.cpp file | annotate | diff | comparison | revisions
src/tools/selecttool.h file | annotate | diff | comparison | revisions
--- 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);
+		}
 	}
 }
 
--- a/src/document.h	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/document.h	Sun Aug 29 21:28:08 2021 +0300
@@ -21,7 +21,6 @@
 #include <QWidget>
 #include <QToolBar>
 #include "ui/canvas.h"
-#include "ui/objecteditor.h"
 #include "model.h"
 #include "vertexmap.h"
 
@@ -63,7 +62,6 @@
 	VertexMap vertexMap;
 	Canvas* renderer;
 	Ui::Document& ui;
-	ObjectEditor objectEditor;
 	QToolBar* toolsBar;
 	QVector<class BaseTool*> tools;
 	BaseTool* selectedTool = nullptr;
--- a/src/document.ui	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/document.ui	Sun Aug 29 21:28:08 2021 +0300
@@ -46,7 +46,7 @@
        </property>
       </widget>
      </widget>
-     <widget class="QFrame" name="objectEditorFrame">
+     <widget class="QStackedWidget" name="toolWidgetStack">
       <property name="frameShape">
        <enum>QFrame::StyledPanel</enum>
       </property>
--- a/src/tools/basetool.cpp	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/basetool.cpp	Sun Aug 29 21:28:08 2021 +0300
@@ -1,4 +1,4 @@
 #include "basetool.h"
 
-BaseTool::BaseTool(QObject* parent) :
+BaseTool::BaseTool(Model*, QObject* parent) :
 	QObject{parent} {}
--- a/src/tools/basetool.h	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/basetool.h	Sun Aug 29 21:28:08 2021 +0300
@@ -10,7 +10,7 @@
 	Q_OBJECT
 
 public:
-	BaseTool(QObject* parent = nullptr);
+	BaseTool(Model* model, QObject* parent = nullptr);
 
 	virtual QString name() const = 0;
 	virtual QString toolTip() const = 0;
@@ -18,6 +18,8 @@
 	virtual bool mouseDoubleClicked(QMouseEvent*, QMouseEvent*) { return false; }
 	virtual bool mouseMove(Document*, Canvas*, QMouseEvent*) { return false; }
 	virtual bool keyReleased(Document*, Canvas*, QKeyEvent*) { return false; }
+	virtual QWidget* toolWidget() { return nullptr; }
+	virtual void selectionChanged(const QSet<ldraw::id_t>&) {}
 	virtual void reset() {}
 	virtual void overpaint(Canvas*, QPainter*) const {}
 };
--- a/src/tools/drawtool.cpp	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/drawtool.cpp	Sun Aug 29 21:28:08 2021 +0300
@@ -12,8 +12,8 @@
 static const QBrush polygonBrush = {QColor{64, 255, 128, 192}};
 static const QBrush badPolygonBrush = {QColor{255, 96, 96, 192}};
 
-DrawTool::DrawTool(QObject* parent) :
-	BaseTool{parent} {}
+DrawTool::DrawTool(Model *model, QObject *parent) :
+	BaseTool{model, parent} {}
 
 QString DrawTool::name() const
 {
--- a/src/tools/drawtool.h	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/drawtool.h	Sun Aug 29 21:28:08 2021 +0300
@@ -6,7 +6,7 @@
 	Q_OBJECT
 
 public:
-	Q_INVOKABLE DrawTool(QObject* parent = nullptr);
+	Q_INVOKABLE DrawTool(Model* model, QObject* parent = nullptr);
 
 	QString name() const override;
 	QString toolTip() const override;
--- a/src/tools/selecttool.cpp	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/selecttool.cpp	Sun Aug 29 21:28:08 2021 +0300
@@ -1,7 +1,8 @@
 #include "selecttool.h"
 
-SelectTool::SelectTool(QObject* parent) :
-	BaseTool{parent} {}
+SelectTool::SelectTool(Model* model, QObject* parent) :
+	BaseTool{model, parent},
+	objectEditor{model, ldraw::NULL_ID, nullptr} {}
 
 QString SelectTool::name() const
 {
@@ -33,3 +34,20 @@
 		return false;
 	}
 }
+
+QWidget* SelectTool::toolWidget()
+{
+	return &this->objectEditor;
+}
+
+void SelectTool::selectionChanged(const QSet<ldraw::id_t>& newSelection)
+{
+	if (newSelection.size() == 1)
+	{
+		this->objectEditor.setObjectId(*newSelection.begin());
+	}
+	else
+	{
+		this->objectEditor.setObjectId(ldraw::NULL_ID);
+	}
+}
--- a/src/tools/selecttool.h	Sun Aug 29 20:39:55 2021 +0300
+++ b/src/tools/selecttool.h	Sun Aug 29 21:28:08 2021 +0300
@@ -1,14 +1,18 @@
 #pragma once
 #include "basetool.h"
+#include "ui/objecteditor.h"
 
 class SelectTool : public BaseTool
 {
 	Q_OBJECT
 
 public:
-	Q_INVOKABLE SelectTool(QObject* parent = nullptr);
+	Q_INVOKABLE SelectTool(Model* model, QObject* parent = nullptr);
 
 	QString name() const override;
 	QString toolTip() const override;
 	bool mouseClick(Document*, Canvas*, QMouseEvent*) override;
+	QWidget* toolWidget() override;
+	void selectionChanged(const QSet<ldraw::id_t> &newSelection) override;
+	ObjectEditor objectEditor;
 };

mercurial