feat: Manage active drawing tool state in controller and UI

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2026-02-13 17:33:56 -07:00
parent d51e7127af
commit 2727b73208
3 changed files with 37 additions and 0 deletions

View File

@@ -34,6 +34,21 @@ SketchFeature* ApplicationController::activeSketch() const
return m_activeSketch; return m_activeSketch;
} }
ApplicationController::ToolType ApplicationController::activeTool() const
{
return m_activeTool;
}
void ApplicationController::setActiveTool(ToolType tool)
{
if (m_activeTool == tool) {
return;
}
m_activeTool = tool;
emit activeToolChanged(m_activeTool);
}
void ApplicationController::newDocument() void ApplicationController::newDocument()
{ {
m_activeSketch = nullptr; m_activeSketch = nullptr;
@@ -114,6 +129,7 @@ void ApplicationController::beginSketchCreation()
void ApplicationController::endSketch() void ApplicationController::endSketch()
{ {
m_activeSketch = nullptr; m_activeSketch = nullptr;
setActiveTool(ToolType::None);
emit sketchModeEnded(); emit sketchModeEnded();
} }

View File

@@ -12,14 +12,24 @@ class ApplicationController : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum ToolType {
None,
Line,
Rectangle,
Circle
};
Q_ENUM(ToolType)
explicit ApplicationController(QObject *parent = nullptr); explicit ApplicationController(QObject *parent = nullptr);
~ApplicationController(); ~ApplicationController();
void setMainWindow(MainWindow* mainWindow); void setMainWindow(MainWindow* mainWindow);
Document* document() const; Document* document() const;
SketchFeature* activeSketch() const; SketchFeature* activeSketch() const;
ToolType activeTool() const;
public slots: public slots:
void setActiveTool(ToolType tool);
void newDocument(); void newDocument();
bool openDocument(); bool openDocument();
bool saveDocument(); bool saveDocument();
@@ -32,6 +42,7 @@ signals:
void sketchModeStarted(ViewportWidget::SketchPlane plane); void sketchModeStarted(ViewportWidget::SketchPlane plane);
void sketchModeEnded(); void sketchModeEnded();
void currentFileChanged(const QString& path); void currentFileChanged(const QString& path);
void activeToolChanged(ToolType tool);
private: private:
ApplicationController(const ApplicationController&) = delete; ApplicationController(const ApplicationController&) = delete;
@@ -43,6 +54,7 @@ private:
QString m_currentFile; QString m_currentFile;
MainWindow* m_mainWindow = nullptr; MainWindow* m_mainWindow = nullptr;
SketchFeature* m_activeSketch = nullptr; SketchFeature* m_activeSketch = nullptr;
ToolType m_activeTool = ToolType::None;
}; };
#endif // APPLICATIONCONTROLLER_H #endif // APPLICATIONCONTROLLER_H

View File

@@ -91,6 +91,9 @@ MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
lineButton->setIcon(QIcon(":/icons/line.svg")); lineButton->setIcon(QIcon(":/icons/line.svg"));
lineButton->setIconSize(QSize(48, 48)); lineButton->setIconSize(QSize(48, 48));
lineButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); lineButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
connect(lineButton, &QToolButton::clicked, this, [this]() {
m_appController->setActiveTool(ApplicationController::ToolType::Line);
});
sketchLayout->addWidget(lineButton); sketchLayout->addWidget(lineButton);
QToolButton *rectangleButton = new QToolButton(); QToolButton *rectangleButton = new QToolButton();
@@ -98,6 +101,9 @@ MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
rectangleButton->setIcon(QIcon(":/icons/rectangle.svg")); rectangleButton->setIcon(QIcon(":/icons/rectangle.svg"));
rectangleButton->setIconSize(QSize(48, 48)); rectangleButton->setIconSize(QSize(48, 48));
rectangleButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); rectangleButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
connect(rectangleButton, &QToolButton::clicked, this, [this]() {
m_appController->setActiveTool(ApplicationController::ToolType::Rectangle);
});
sketchLayout->addWidget(rectangleButton); sketchLayout->addWidget(rectangleButton);
QToolButton *circleButton = new QToolButton(); QToolButton *circleButton = new QToolButton();
@@ -105,6 +111,9 @@ MainWindow::MainWindow(ApplicationController* appController, QWidget *parent)
circleButton->setIcon(QIcon(":/icons/circle.svg")); circleButton->setIcon(QIcon(":/icons/circle.svg"));
circleButton->setIconSize(QSize(48, 48)); circleButton->setIconSize(QSize(48, 48));
circleButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); circleButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
connect(circleButton, &QToolButton::clicked, this, [this]() {
m_appController->setActiveTool(ApplicationController::ToolType::Circle);
});
sketchLayout->addWidget(circleButton); sketchLayout->addWidget(circleButton);
QToolButton *saveSketchButton = new QToolButton(); QToolButton *saveSketchButton = new QToolButton();