graphicswidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.0.2
4  Written in Qt
5 
6  graphicswidget.h - description
7  -------------------
8  copyright : (C) 2005-2021 by Dimitris B. Kalamaras
9  project site : https://socnetv.org
10 
11  ***************************************************************************/
12 
13 /*******************************************************************************
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation, either version 3 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
26 ********************************************************************************/
27 
28 #ifndef GRAPHICSWIDGET_H
29 #define GRAPHICSWIDGET_H
30 
31 
32 #include <QGraphicsView>
33 
34 class MainWindow;
35 
36 class GraphicsNode;
37 class GraphicsEdge;
38 class GraphicsNodeNumber;
39 class GraphicsNodeLabel;
40 class GraphicsGuide;
41 class GraphicsEdgeWeight;
43 
44 typedef QHash<QString, GraphicsEdge*> H_StrToEdge;
45 typedef QHash <int, GraphicsNode*> H_NumToNode;
46 
47 using namespace std;
48 
49 typedef QPair<int, int> SelectedEdge;
50 
51 Q_DECLARE_METATYPE(SelectedEdge)
52 
53 
54 class GraphicsWidget : public QGraphicsView {
55  Q_OBJECT
56 
57 public:
58 
59  GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent);
60  ~GraphicsWidget();
61 
62  void clear();
63 
64  QString createEdgeName(const int &v1,
65  const int &v2,
66  const int &relation=-1);
67 
68  void setInitNodeSize(int);
69 
70  void setInitZoomIndex (int);
71 
72  GraphicsNode* hasNode(QString text);
73  void setNodesMarked(QList<int> list);
74 
75  QList<QGraphicsItem *> selectedItems();
76  QList<int> selectedNodes();
77  QList<SelectedEdge> selectedEdges();
78 
79  void selectAll();
80  void selectNone();
81 
82  void removeItem(GraphicsEdge*);
83  void removeItem(GraphicsEdgeWeight *edgeWeight);
84  void removeItem(GraphicsEdgeLabel *edgeLabel);
85  void removeItem(GraphicsNode*);
86  void removeItem(GraphicsNodeNumber*);
87  void removeItem(GraphicsNodeLabel*);
88 
89  void setNumbersInsideNodes(const bool &toggle);
90 
91  void setAllItemsVisibility(int, bool);
92 
93  void removeAllItems(int);
94 
95 protected:
96 
97  void wheelEvent(QWheelEvent *event);
98  void mouseDoubleClickEvent ( QMouseEvent * e );
99  void mousePressEvent ( QMouseEvent * e );
100  void mouseReleaseEvent(QMouseEvent * e );
101  void resizeEvent( QResizeEvent *e );
102 
103 public slots:
104 
105  void getSelectedItems();
106 
107  void relationSet(int relation);
108 
109  void drawNode(const QPointF &p,
110  const int &num,
111  const int &nodeSize,
112  const QString &nodeShape,
113  const QString &nodeIconPath,
114  const QString &nodeColor,
115  const QString &numberColor,
116  const int &numberSize,
117  const int &numberDistance,
118  const QString &nodeLabel,
119  const QString &labelColor,
120  const int &labelSize,
121  const int &labelDistance);
122  void removeNode(const int &number);
123  void setNodeVisibility(const int &number, const bool &toggle ); //Called from Graph via MW
124  void setNodeClicked(GraphicsNode *);
125  void moveNode(const int &num, const qreal &x, const qreal &y);
126 
127  bool setNodeSize(const int &nodeNumber, const int &size=0);
128  void setNodeSizeAll(const int &size=0);
129 
130  bool setNodeShape(const int &nodeNumber,
131  const QString &shape,
132  const QString &iconPath=QString());
133  bool setNodeColor(const int &nodeNumber, const QString &color);
134 
135  void setNodeNumberColor(const int &nodeNumber, const QString &color);
136  void setNodeNumberVisibility(const bool &toggle);
137  bool setNodeNumberSize(const int &nodeNumber, const int &size=0);
138  bool setNodeNumberDistance(const int &, const int &distance=0);
139 
140  void setNodeLabelsVisibility(const bool &toggle);
141  bool setNodeLabelColor(const int &number, const QString &color="green");
142  bool setNodeLabelSize(const int &, const int &size=0);
143  bool setNodeLabel(const int & , const QString &label);
144  bool setNodeLabelDistance(const int &, const int &distance=0);
145 
146  void drawEdge(const int &source,
147  const int &target,
148  const qreal &weight,
149  const QString &label="",
150  const QString &color="black",
151  const int &type=0,
152  const bool &drawArrows=true,
153  const bool &bezier=false,
154  const bool &weightNumbers=false);
155 
156  void removeEdge(const int &source,
157  const int &target,
158  const bool &removeOpposite=false);
159 
160  void setEdgeVisibility (const int &relation, const int &source, const int &target, const bool &visible);
161 
162  bool setEdgeDirectionType(const int &source,
163  const int &target,
164  const int &dirType=false);
165 
166  bool setEdgeWeight(const int &, const int &, const qreal &);
167 
168  void setEdgeLabel(const int &source, const int &target, const QString &label);
169 
170  void setEdgeColor(const int &, const int&, const QString &);
171 
172  void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false);
173 
174  void setEdgeOffsetFromNode(const int &source,
175  const int &target,
176  const int &offset);
177  void setEdgeArrowsVisibility(const bool &toggle);
178  void setEdgeWeightNumbersVisibility (const bool &toggle);
179  void setEdgeLabelsVisibility(const bool &toggle);
180 
181  void setEdgeHighlighting(const bool &toggle);
182 
183  void startEdge(GraphicsNode *node);
184 
185  void clearGuides();
186  void addGuideCircle( const double&x0, const double&y0, const double&radius);
187  void addGuideHLine(const double &y0);
188 
189  void zoomIn(int level = 1);
190  void zoomOut(int level = 1);
191  void rotateLeft();
192  void rotateRight();
193  void changeMatrixScale(const int value);
194  void changeMatrixRotation(int angle);
195  void reset();
196 
197  void setOptionsOpenGL(const bool &enabled=false);
198  void setOptionsAntialiasing(const bool &toggle);
199  void setOptionsNoAntialiasingAutoAdjust(const bool &toggle);
200 
201 signals:
202  void userDoubleClickNewNode(const QPointF &);
203  void userMiddleClicked(const int &, const int &);
204  void userClickOnEmptySpace(const QPointF &p);
205  void openNodeMenu();
206  void openContextMenu(const QPointF p);
207  void userNodeMoved(const int &, const int &, const int &);
208  //void userSelectedItems(const int nodes, const int edges);
209  void userSelectedItems(const QList<int> selectedNodes,
210  const QList<SelectedEdge> selectedEdges);
211  void userClickedNode(const int &nodeNumber, const QPointF &p);
212  void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
213  void zoomChanged(const int);
214  void rotationChanged(const int);
215  void resized(const int, const int);
216  void setCursor(Qt::CursorShape);
217 
218 
219 private:
220 
221  H_NumToNode nodeHash; //Our basic hash table for node items
222  H_StrToEdge edgesHash; // Our basic hash table for edge items
223  QList<int> m_selectedNodes;
224  QList<SelectedEdge> m_selectedEdges;
225  int m_curRelation, m_nodeSize;
227  int m_zoomIndex, markedEdgeSourceOrigSize, markedEdgeTargetOrigSize;
230  qreal fX,fY, factor;
231  QString m_nodeLabel, m_numberColor, m_labelColor;
232  QString edgeName;
234  bool secondDoubleClick, clickedEdgeExists;
235  bool m_nodeNumbersInside, m_nodeNumberVisibility, m_nodeLabelVisibility;
237  GraphicsNode *firstNode, *secondNode;
241 };
242 
243 #endif
double m_currentScaleFactor
Definition: graphicswidget.h:229
GraphicsNode * secondNode
Definition: graphicswidget.h:237
QPair< int, int > SelectedEdge
Definition: global.h:147
Definition: graphicsedgelabel.h:37
QString m_numberColor
Definition: graphicswidget.h:231
int m_nodeSize
Definition: graphicswidget.h:225
bool m_isTransformationActive
Definition: graphicswidget.h:233
Definition: graphicsnodelabel.h:37
Definition: graphicswidget.h:54
H_NumToNode nodeHash
Definition: graphicswidget.h:221
bool m_nodeNumberVisibility
Definition: graphicswidget.h:235
QList< int > m_selectedNodes
Definition: graphicswidget.h:223
int type() const
Definition: graphicsedgelabel.h:44
qreal fY
Definition: graphicswidget.h:230
The base window of SocNetV contains all widgets and functionality.
Definition: mainwindow.h:118
int markedEdgeTargetOrigSize
Definition: graphicswidget.h:227
Definition: graphicsedge.h:60
QPair< int, int > SelectedEdge
Definition: graphicswidget.h:49
GraphicsNode * markedEdgeTarget
Definition: graphicswidget.h:239
GraphicsNode * markedEdgeSource
Definition: graphicswidget.h:238
int m_currentRotationAngle
Definition: graphicswidget.h:226
QHash< int, GraphicsNode * > H_NumToNode
Definition: graphicswidget.h:45
Definition: graphicsnode.h:58
int m_edgeMinOffsetFromNode
Definition: graphicswidget.h:228
QList< SelectedEdge > m_selectedEdges
Definition: graphicswidget.h:224
Definition: graphicsedgeweight.h:37
GraphicsEdge * clickedEdge
Definition: graphicswidget.h:240
Definition: graphicsnodenumber.h:38
bool secondDoubleClick
Definition: graphicswidget.h:234
bool m_edgeHighlighting
Definition: graphicswidget.h:236
H_StrToEdge edgesHash
Definition: graphicswidget.h:222
QString edgeName
Definition: graphicswidget.h:232
Definition: graphicsguide.h:41
QHash< QString, GraphicsEdge * > H_StrToEdge
Definition: graphicswidget.h:42