From 82e1e16580b4832e1241ceb9e38906e660baec85 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sat, 22 Sep 2018 14:05:32 +0200 Subject: extend selection --- src/gui/mainmenu.cpp | 24 +++++++++++++++++ src/gui/mainmenu.h | 4 +++ src/gui/mainmenu.ui | 12 ++++----- src/gui/tikzscene.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--- src/gui/tikzscene.h | 4 +++ 5 files changed, 110 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index 6bbc95a..ca837fa 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -132,6 +132,30 @@ void MainMenu::on_actionRotateCCW_triggered() { tikzit->activeWindow()->tikzScene()->rotateNodes(false); } +void MainMenu::on_actionExtendUp_triggered() +{ + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->extendSelectionUp(); +} + +void MainMenu::on_actionExtendDown_triggered() +{ + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->extendSelectionDown(); +} + +void MainMenu::on_actionExtendLeft_triggered() +{ + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->extendSelectionLeft(); +} + +void MainMenu::on_actionExtendRight_triggered() +{ + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->extendSelectionRight(); +} + // Tikz void MainMenu::on_actionParse_triggered() diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h index b561eab..7132dde 100644 --- a/src/gui/mainmenu.h +++ b/src/gui/mainmenu.h @@ -54,6 +54,10 @@ public slots: void on_actionReflectVertical_triggered(); void on_actionRotateCW_triggered(); void on_actionRotateCCW_triggered(); + void on_actionExtendUp_triggered(); + void on_actionExtendDown_triggered(); + void on_actionExtendLeft_triggered(); + void on_actionExtendRight_triggered(); // Tikz void on_actionParse_triggered(); diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui index 1517fb1..d144fce 100644 --- a/src/gui/mainmenu.ui +++ b/src/gui/mainmenu.ui @@ -33,8 +33,8 @@ - - + + @@ -276,17 +276,17 @@ Shift+Right - + - Above + Upward Shift+Up - + - Below + Downward Shift+Down diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 1c6f0bb..947620f 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -105,6 +105,78 @@ void TikzScene::graphReplaced() } } +void TikzScene::extendSelectionUp() +{ + bool found = false; + float m = 0.0f; + foreach (Node *n, getSelectedNodes()) { + if (!found) { + m = n->point().y(); + found = true; + } else { + if (n->point().y() > m) m = n->point().y(); + } + } + + foreach (NodeItem *ni, nodeItems().values()) { + if (ni->node()->point().y() >= m) ni->setSelected(true); + } +} + +void TikzScene::extendSelectionDown() +{ + bool found = false; + float m = 0.0f; + foreach (Node *n, getSelectedNodes()) { + if (!found) { + m = n->point().y(); + found = true; + } else { + if (n->point().y() < m) m = n->point().y(); + } + } + + foreach (NodeItem *ni, nodeItems().values()) { + if (ni->node()->point().y() <= m) ni->setSelected(true); + } +} + +void TikzScene::extendSelectionLeft() +{ + bool found = false; + float m = 0.0f; + foreach (Node *n, getSelectedNodes()) { + if (!found) { + m = n->point().x(); + found = true; + } else { + if (n->point().x() < m) m = n->point().x(); + } + } + + foreach (NodeItem *ni, nodeItems().values()) { + if (ni->node()->point().x() <= m) ni->setSelected(true); + } +} + +void TikzScene::extendSelectionRight() +{ + bool found = false; + float m = 0.0f; + foreach (Node *n, getSelectedNodes()) { + if (!found) { + m = n->point().x(); + found = true; + } else { + if (n->point().x() < m) m = n->point().x(); + } + } + + foreach (NodeItem *ni, nodeItems().values()) { + if (ni->node()->point().x() >= m) ni->setSelected(true); + } +} + void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (!_enabled) return; @@ -642,11 +714,8 @@ void TikzScene::pasteFromClipboard() // attempt to parse whatever's on the clipboard, if we get a // non-empty tikz graph, insert it. if (ass.parse(tikz) && !g->nodes().isEmpty()) { - qDebug() << "CLIPBOARD:" << tikz; - qDebug() << "PARSED:" << g->tikz(); // make sure names in the new subgraph are fresh g->renameApart(graph()); - qDebug() << "FRESH:" << g->tikz(); QRectF srcRect = g->realBbox(); QRectF tgtRect = graph()->realBbox(); diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index 91f606f..16af125 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -76,6 +76,10 @@ public: public slots: void graphReplaced(); + void extendSelectionUp(); + void extendSelectionDown(); + void extendSelectionLeft(); + void extendSelectionRight(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) override; -- cgit v1.2.3