Sun, 29 Aug 2021 20:05:24 +0300
esc with draw mode now clears the polygon
src/document.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/mainwindow.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/ui/canvas.h | file | annotate | diff | comparison | revisions |
--- a/src/document.cpp Fri Aug 27 14:38:56 2021 +0300 +++ b/src/document.cpp Sun Aug 29 20:05:24 2021 +0300 @@ -81,6 +81,10 @@ { Q_EMIT this->mouseMove(this, canvas, event); }); + connect(this->renderer, &Canvas::keyReleased, this, [this](Canvas* canvas, QKeyEvent* event) + { + Q_EMIT this->keyReleased(this, canvas, event); + }); connect(&this->vertexMap, &VertexMap::verticesChanged, [&]() { this->renderer->rebuildVertices(this);
--- a/src/mainwindow.cpp Fri Aug 27 14:38:56 2021 +0300 +++ b/src/mainwindow.cpp Sun Aug 29 20:05:24 2021 +0300 @@ -214,6 +214,7 @@ connect(document, &Document::splitterChanged, this, &MainWindow::handleDocumentSplitterChange); connect(document, &Document::mouseClick, this, &MainWindow::canvasMouseReleased); connect(document, &Document::mouseMove, this, &MainWindow::canvasMouseMoved); + connect(document, &Document::keyReleased, this, &MainWindow::canvasKeyReleased); document->setCanvasOverpaintCallback([&](Canvas* canvas, QPainter* painter) { if (this->selectedTool != nullptr) @@ -445,7 +446,20 @@ } } -void MainWindow::canvasKeyReleased(QKeyEvent* event) +void MainWindow::keyReleaseEvent(QKeyEvent *event) { - Q_UNUSED(event) + if (this->selectedTool != nullptr) + { + this->selectedTool->keyReleased(event); + } } + +void MainWindow::canvasKeyReleased(Document *document, Canvas *canvas, QKeyEvent *event) +{ +#if 0 + if (this->selectedTool != nullptr) + { + this->selectedTool->keyReleased(document, canvas, event); + } +#endif +}
--- a/src/mainwindow.h Fri Aug 27 14:38:56 2021 +0300 +++ b/src/mainwindow.h Sun Aug 29 20:05:24 2021 +0300 @@ -47,6 +47,7 @@ protected: void changeEvent(QEvent* event) override; void closeEvent(QCloseEvent* event) override; + void keyReleaseEvent(QKeyEvent *event) override; private: std::unique_ptr<class Ui_MainWindow> ui; DocumentManager documents; @@ -81,5 +82,4 @@ void canvasMouseReleased(Document *document, Canvas *canvas, QMouseEvent *event); void canvasMouseDoubleClicked(QMouseEvent* event); void canvasMouseMoved(Document *document, Canvas *canvas, QMouseEvent *event); - void canvasKeyReleased(QKeyEvent*); };
--- a/src/tools/drawtool.cpp Fri Aug 27 14:38:56 2021 +0300 +++ b/src/tools/drawtool.cpp Sun Aug 29 20:05:24 2021 +0300 @@ -80,6 +80,20 @@ return false; } +bool DrawTool::keyReleased(QKeyEvent* event) +{ + if (event->key() == Qt::Key_Escape) + { + this->polygon.clear(); + this->updatePreviewPolygon(); + return true; + } + else + { + return false; + } +} + void DrawTool::updatePreviewPolygon() { this->previewPolygon.resize(this->polygon.size() + 1);
--- a/src/tools/drawtool.h Fri Aug 27 14:38:56 2021 +0300 +++ b/src/tools/drawtool.h Sun Aug 29 20:05:24 2021 +0300 @@ -12,6 +12,7 @@ QString toolTip() const override; bool mouseClick(Document* document, Canvas* canvas, QMouseEvent* event) override; bool mouseMove(Document* document, Canvas* canvas, QMouseEvent* event) override; + bool keyReleased(QKeyEvent*) override; void reset() override; void overpaint(Canvas*, QPainter*) const override; private:
--- a/src/ui/canvas.h Fri Aug 27 14:38:56 2021 +0300 +++ b/src/ui/canvas.h Sun Aug 29 20:05:24 2021 +0300 @@ -30,6 +30,7 @@ void mouseMoveEvent(QMouseEvent* event) override; void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; + void keyReleaseEvent(QKeyEvent *event) override; void initializeGL() override; void paintGL() override; Q_SIGNALS: