# HG changeset patch # User Teemu Piippo # Date 1630261688 -10800 # Node ID a7c720aff97cb190b76346fcb4af6c676199c1cc # Parent f127982d341265d462430faa1c019ecee4ccf27c moved ObjectEditor under SelectTool diff -r f127982d3412 -r a7c720aff97c src/document.cpp --- 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& 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(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); + } } } diff -r f127982d3412 -r a7c720aff97c src/document.h --- 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 #include #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 tools; BaseTool* selectedTool = nullptr; diff -r f127982d3412 -r a7c720aff97c src/document.ui --- 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 @@ - + QFrame::StyledPanel diff -r f127982d3412 -r a7c720aff97c src/tools/basetool.cpp --- 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} {} diff -r f127982d3412 -r a7c720aff97c src/tools/basetool.h --- 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&) {} virtual void reset() {} virtual void overpaint(Canvas*, QPainter*) const {} }; diff -r f127982d3412 -r a7c720aff97c src/tools/drawtool.cpp --- 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 { diff -r f127982d3412 -r a7c720aff97c src/tools/drawtool.h --- 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; diff -r f127982d3412 -r a7c720aff97c src/tools/selecttool.cpp --- 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& newSelection) +{ + if (newSelection.size() == 1) + { + this->objectEditor.setObjectId(*newSelection.begin()); + } + else + { + this->objectEditor.setObjectId(ldraw::NULL_ID); + } +} diff -r f127982d3412 -r a7c720aff97c src/tools/selecttool.h --- 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 &newSelection) override; + ObjectEditor objectEditor; };