summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2020-04-19 18:15:26 +0100
committerAleks Kissinger <aleks0@gmail.com>2020-04-19 18:15:26 +0100
commit8f3f804990387607b7e52b5550ebce52e36aa619 (patch)
treec4b652c1bc7f075b3021a4355516cba3c42ec74b
parent05361085127d9849ee02b59b115a516c1bd05106 (diff)
add path as background
-rw-r--r--src/gui/mainmenu.cpp8
-rw-r--r--src/gui/mainmenu.h1
-rw-r--r--src/gui/mainmenu.ui9
-rw-r--r--src/gui/tikzscene.cpp57
-rw-r--r--src/gui/tikzscene.h2
-rw-r--r--tex/logo.tikzstyles5
6 files changed, 69 insertions, 13 deletions
diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp
index 092d8b4..efd453d 100644
--- a/src/gui/mainmenu.cpp
+++ b/src/gui/mainmenu.cpp
@@ -242,7 +242,13 @@ void MainMenu::on_actionMerge_Nodes_triggered()
void MainMenu::on_actionMake_Path_triggered()
{
if (tikzit->activeWindow() != 0)
- tikzit->activeWindow()->tikzScene()->makePath();
+ tikzit->activeWindow()->tikzScene()->makePath(false);
+}
+
+void MainMenu::on_actionMake_Path_as_Background_triggered()
+{
+ if (tikzit->activeWindow() != 0)
+ tikzit->activeWindow()->tikzScene()->makePath(true);
}
void MainMenu::on_actionSplit_Path_triggered()
diff --git a/src/gui/mainmenu.h b/src/gui/mainmenu.h
index 431e43a..d0d73e9 100644
--- a/src/gui/mainmenu.h
+++ b/src/gui/mainmenu.h
@@ -68,6 +68,7 @@ public slots:
void on_actionReverse_Edge_Direction_triggered();
void on_actionMerge_Nodes_triggered();
void on_actionMake_Path_triggered();
+ void on_actionMake_Path_as_Background_triggered();
void on_actionSplit_Path_triggered();
// Tools
diff --git a/src/gui/mainmenu.ui b/src/gui/mainmenu.ui
index 2e390f9..11778db 100644
--- a/src/gui/mainmenu.ui
+++ b/src/gui/mainmenu.ui
@@ -64,6 +64,7 @@
</property>
<addaction name="actionMake_Path"/>
<addaction name="actionSplit_Path"/>
+ <addaction name="actionMake_Path_as_Background"/>
</widget>
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
@@ -485,6 +486,14 @@
<string>Ctrl+Shift+P</string>
</property>
</action>
+ <action name="actionMake_Path_as_Background">
+ <property name="text">
+ <string>Make Path as Background</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+B</string>
+ </property>
+ </action>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp
index 9da8639..33e4710 100644
--- a/src/gui/tikzscene.cpp
+++ b/src/gui/tikzscene.cpp
@@ -314,11 +314,14 @@ void TikzScene::reverseSelectedEdges()
_tikzDocument->undoStack()->push(cmd);
}
-void TikzScene::makePath()
+void TikzScene::makePath(bool duplicateEdges)
{
QSet<Node*> selNodes;
+ QSet<Edge*> selEdges;
QSet<Edge*> edges;
- getSelection(selNodes, edges);
+ getSelection(selNodes, selEdges);
+
+ edges = selEdges;
// if no edges are selected, try to infer edges from nodes
if (edges.isEmpty()) {
@@ -334,13 +337,29 @@ void TikzScene::makePath()
}
foreach (Edge *e, edges) {
- if (e->path() != nullptr) {
+ if (e->path() != nullptr && !duplicateEdges) {
//QMessageBox::warning(nullptr, "Error", "Edges must not already be in another path.");
// TODO: maybe we want to automatically split paths if edges are in a path already?
return;
}
}
+ _tikzDocument->undoStack()->beginMacro("Make Path");
+
+ QVector<Edge *> oldEdgeOrder = graph()->edges();
+ QSet<Edge *> oldEdges, newEdges;
+ oldEdges = edges;
+
+ if (duplicateEdges) {
+ foreach (Edge *e, edges) {
+ Edge *e1 = e->copy();
+ _tikzDocument->undoStack()->push(new AddEdgeCommand(this, e1, false, selNodes, selEdges));
+ newEdges << e1;
+ oldEdgeOrder << e1;
+ }
+ edges = newEdges;
+ }
+
// try to turn selected edges into one contiguous chain or cycle, recording
// which edges need to be flipped.
@@ -387,16 +406,33 @@ void TikzScene::makePath()
return;
}
- //qDebug() << p;
- //qDebug() << flip;
+ _tikzDocument->undoStack()->push(new ReverseEdgesCommand(this, flip));
+
+ // order all of the edges together, and in the case of
+ // duplicate edges, just below the first original.
+ QVector<Edge*> newEdgeOrder;
+ bool firstEdge = true;
+ foreach (Edge *e, oldEdgeOrder) {
+ if (oldEdges.contains(e)) {
+ if (firstEdge) {
+ newEdgeOrder += p;
+ firstEdge = false;
+ }
+
+ if (duplicateEdges) newEdgeOrder << e;
+ } else if (!newEdges.contains(e)) {
+ newEdgeOrder << e;
+ }
+ }
+
+ _tikzDocument->undoStack()->push(new ReorderCommand(this,
+ graph()->nodes(), graph()->nodes(), oldEdgeOrder, newEdgeOrder));
QMap<Edge*, GraphElementData*> oldEdgeData;
foreach (Edge *e, p) {
if (e != p.first()) oldEdgeData[e] = e->data()->copy();
}
- _tikzDocument->undoStack()->beginMacro("Make Path");
- _tikzDocument->undoStack()->push(new ReverseEdgesCommand(this, flip));
_tikzDocument->undoStack()->push(new MakePathCommand(this, p, oldEdgeData));
_tikzDocument->undoStack()->endMacro();
}
@@ -754,10 +790,11 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
nodeItems()[e->source()]->setSelected(sel);
nodeItems()[e->target()]->setSelected(sel);
}
- } else {
- nodeItems()[_selectingEdge->source()]->setSelected(sel);
- nodeItems()[_selectingEdge->target()]->setSelected(sel);
}
+// else {
+// nodeItems()[_selectingEdge->source()]->setSelected(sel);
+// nodeItems()[_selectingEdge->target()]->setSelected(sel);
+// }
}
if (_rubberBandItem->isVisible()) {
diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h
index 3f035e2..e1d30d2 100644
--- a/src/gui/tikzscene.h
+++ b/src/gui/tikzscene.h
@@ -83,7 +83,7 @@ public:
void reverseSelectedEdges();
- void makePath();
+ void makePath(bool duplicateEdges);
void splitPath();
void getSelection(QSet<Node*> &selNodes, QSet<Edge*> &selEdges) const;
diff --git a/tex/logo.tikzstyles b/tex/logo.tikzstyles
index 3419ee3..1103b0b 100644
--- a/tex/logo.tikzstyles
+++ b/tex/logo.tikzstyles
@@ -4,9 +4,12 @@
% \tikzstyle{NAME}=[PROPERTY LIST]
% Node styles
-\tikzstyle{test}=[fill=none, draw=black, shape=circle]
+\tikzstyle{white dot}=[fill=white, draw=black, shape=circle]
% Edge styles
\tikzstyle{bg}=[-, line width=0.5mm, fill={rgb,255: red,217; green,217; blue,217}]
\tikzstyle{fg}=[-, fill=black]
\tikzstyle{dir}=[->]
+\tikzstyle{region A}=[-, draw=none, fill={rgb,255: red,255; green,160; blue,162}, opacity=0.8]
+\tikzstyle{region B}=[-, draw=none, fill={rgb,255: red,190; green,185; blue,255}, opacity=0.8]
+\tikzstyle{region C}=[-, fill={rgb,255: red,179; green,255; blue,192}, draw=none, opacity=0.8]