Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
node.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef NODE_H
24 #define NODE_H
25 
26 #include <QWidget>
27 
28 #include <QObject>
29 #include <QGraphicsObject>
30 #include <QList>
31 QT_BEGIN_NAMESPACE
32 class QGraphicsSceneMouseEvent;
33 QT_END_NAMESPACE
34 
35 class Diagram;
36 class DiagramWidget;
37 class Proxy;
38 
39 class Node : public QGraphicsObject
40 {
41  Q_OBJECT
42 
43 public:
44 
45  static std::pair<QPointF, QPointF> getEffectiveNodes(
46  Node *first,
47  Node *second
48  );
49 
51 
52  enum { Type = static_cast<int>(UserType) + 1 };
53  int type() const override { return Type; }
54 
55  QString getName() const;
56  qint32 getNodeSize() const {
57  return nodeSize;
58  }
59  QColor getColor() const {
60  return color;
61  }
62  qint32 getNodeType() const {
63  return nodeType;
64  }
65  bool hasGraphFocus() const;
66  bool isOperator() const;
67  void focusInGraph();
68  void unFocusInGraph();
69  void setOperator(bool t_op);
70  void setGridPos(qreal x, qreal y);
71  void setDiagramWidget(DiagramWidget *t_widget) {
72  widget = t_widget;
73  }
74 
75  QRectF boundingRect() const override;
76  QPainterPath shape() const override;
77  void paint(QPainter *painter,
78  const QStyleOptionGraphicsItem *option,
79  QWidget *widget) override;
80  void paintCross(
81  QPainter *painter);
82  void paintDisk(
83  QPainter *painter);
84  void paintCircle(
85  QPainter *painter);
86  void paintHatch(
87  QPainter *painter);
88  void show();
89  void hide();
90 
91 public slots:
92 
93  void setName(QString const& t_name);
94  void setNodeSize(qint32 t_size) {
95  nodeSize = t_size;
96  Node::update();
97  }
98  void setColor(QColor t_color) {
99  color = t_color;
100  Node::update();
101  }
102  void setNodeType(qint32 t_nodeType) {
103  nodeType = t_nodeType;
104  Node::update();
105  }
106  void changeNode(QAction *action = nullptr);
107  void changeColor();
108  void changeName();
109  void moveLabel();
110  void updateEdge();
111 
112 protected:
113  QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
114 
115  void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
116  void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
117  void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
118  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
119  void dropEvent(QGraphicsSceneDragDropEvent *event) override;
120  void update();
121 
122 public:
123  static constexpr qint32 size = 16;
124  static constexpr qreal zValue = -1;
125 
126  Proxy *label = nullptr;
127 
128 private:
129 
130  QPointF oldPos;
131  Diagram *graph;
132  DiagramWidget *widget;
133  QColor color;
134  qint32 nodeSize;
135  qint32 nodeType;
136  qint32 doubleClicked = 0;
137  bool graphFocus;
138  bool displayNode;
139 };
140 
141 #endif // NODE_H
Definition: node.h:39
Type
Definition: diagram.h:52
Definition: diagramwidget.h:43
Definition: diagram.h:243
Definition: amplitudeSimplification.h:38