summaryrefslogtreecommitdiff
path: root/src/gui/tikzscene.h
blob: e1d30d2ffe6206164aa9262f96ef861506ac31cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
    TikZiT - a GUI diagram editor for TikZ
    Copyright (C) 2018 Aleks Kissinger

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*!
  * Manage the scene, which contains a single Graph, and respond to user input. This serves as
  * the controller for the MVC (TikzDocument, TikzView, TikzScene).
  */

#ifndef TIKZSCENE_H
#define TIKZSCENE_H

#include "graph.h"
#include "nodeitem.h"
#include "edgeitem.h"
#include "pathitem.h"
#include "tikzdocument.h"
#include "toolpalette.h"
#include "stylepalette.h"

#include <QWidget>
#include <QGraphicsScene>
#include <QPainter>
#include <QRectF>
#include <QVector>
#include <QGraphicsEllipseItem>
#include <QGraphicsSceneMouseEvent>

class TikzScene : public QGraphicsScene
{
    Q_OBJECT
public:
   TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, StylePalette *styles, QObject *parent);
    ~TikzScene() override;
    Graph *graph();
    QMap<Node*,NodeItem*> &nodeItems();
    QMap<Edge*,EdgeItem*> &edgeItems();
    QMap<Path*,PathItem*> &pathItems();
    void refreshAdjacentEdges(QList<Node*> nodes);
//    void setBounds(QRectF bounds);

    TikzDocument *tikzDocument() const;
    void setTikzDocument(TikzDocument *tikzDocument);
    void reloadStyles();
    //void refreshSceneBounds();
    void applyActiveStyleToNodes();
	void applyActiveStyleToEdges();
    void deleteSelectedItems();
    void copyToClipboard();
    void cutToClipboard();
    void pasteFromClipboard();
    void selectAllNodes();
    void deselectAll();
    bool parseTikz(QString tikz);
    void reflectNodes(bool horizontal);
    void rotateNodes(bool clockwise);
    bool enabled() const;
    void setEnabled(bool enabled);
    int lineNumberForSelection();

    void extendSelectionUp();
    void extendSelectionDown();
    void extendSelectionLeft();
    void extendSelectionRight();

    void mergeNodes();

    void reorderSelection(bool toFront);

    void reverseSelectedEdges();

    void makePath(bool duplicateEdges);
    void splitPath();

    void getSelection(QSet<Node*> &selNodes, QSet<Edge*> &selEdges) const;
    QSet<Node*> getSelectedNodes() const;

    void refreshSceneBounds();

    bool highlightHeads() const;
    bool highlightTails() const;

    bool drawNodeLabels() const;
    void setDrawNodeLabels(bool drawNodeLabels);

public slots:
    void graphReplaced();
    void refreshZIndices();

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
private:
    TikzDocument *_tikzDocument;
    ToolPalette *_tools;
    StylePalette *_styles;
    QMap<Node*,NodeItem*> _nodeItems;
    QMap<Edge*,EdgeItem*> _edgeItems;
    QMap<Path*,PathItem*> _pathItems;
    QGraphicsLineItem *_drawEdgeItem;
    QGraphicsRectItem *_rubberBandItem;
    EdgeItem *_modifyEdgeItem;
    Edge *_selectingEdge;
    NodeItem *_edgeStartNodeItem;
    NodeItem *_edgeEndNodeItem;
    bool _firstControlPoint;
    QPointF _mouseDownPos;
    bool _draggingNodes;
    bool _drawNodeLabels;

    QMap<Node*,QPointF> _oldNodePositions;
    qreal _oldWeight;
    int _oldBend;
    int _oldInAngle;
    int _oldOutAngle;
    bool _enabled;

    bool _highlightHeads;
    bool _highlightTails;
    bool _smartTool;

    bool _ctrlWasPressed;
};

#endif // TIKZSCENE_H