From 7b59b08aa0188daa485e088f6125bcc5c3a11f85 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Fri, 11 Jan 2019 12:03:36 +0100 Subject: smart tool --- src/gui/tikzscene.cpp | 22 +++++++++++++++++++++- src/gui/tikzscene.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 8c1e853..47179f7 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -29,6 +29,7 @@ #include #include #include +#include TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, @@ -227,6 +228,7 @@ void TikzScene::refreshZIndices() void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { + QSettings settings("tikzit", "tikzit"); if (!_enabled) return; // current mouse position, in scene coordinates @@ -238,7 +240,19 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) qreal cpR = GLOBAL_SCALEF * (0.1); qreal cpR2 = cpR * cpR; - + if (event->button() == Qt::RightButton && + _tools->currentTool() == ToolPalette::SELECT && + settings.value("smart-tool-enabled", true).toBool()) + { + _smartTool = true; + if (!items(_mouseDownPos).isEmpty() && + dynamic_cast(items(_mouseDownPos)[0])) + { + _tools->setCurrentTool(ToolPalette::EDGE); + } else { + _tools->setCurrentTool(ToolPalette::VERTEX); + } + } switch (_tools->currentTool()) { case ToolPalette::SELECT: @@ -571,6 +585,12 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) break; } + if (_smartTool) { + _tools->setCurrentTool(ToolPalette::SELECT); + } + + _smartTool = false; + // clear artefacts from rubber band selection invalidate(QRect(), QGraphicsScene::BackgroundLayer); } diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 3baa929..3e46f6d 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -121,6 +121,7 @@ private: bool _highlightHeads; bool _highlightTails; + bool _smartTool; }; #endif // TIKZSCENE_H -- cgit v1.2.3