graphicswidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  graphicswidget.h - description
7  -------------------
8  copyright : (C) 2005-2019 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 //#include <QMetaType>
34 
35 class MainWindow;
36 
37 class GraphicsNode;
38 class GraphicsEdge;
39 class GraphicsNodeNumber;
40 class GraphicsNodeLabel;
41 class GraphicsGuide;
42 class GraphicsEdgeWeight;
44 
45 typedef QHash<QString, GraphicsEdge*> H_StrToEdge;
46 typedef QHash <int, GraphicsNode*> H_NumToNode;
47 
48 using namespace std;
49 
50 typedef QPair<int, int> SelectedEdge;
51 
52 Q_DECLARE_METATYPE(SelectedEdge)
53 
54 
55 class GraphicsWidget : public QGraphicsView {
56  Q_OBJECT
57 
58 public:
59 
60  GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent);
61  ~GraphicsWidget();
62 
63  void clear();
64 
65  QString createEdgeName(const int &v1,
66  const int &v2,
67  const int &relation=-1);
68 
69  void setInitNodeSize(int);
70 
71  void setInitZoomIndex (int);
72 
73  GraphicsNode* hasNode(QString text);
74  void setNodesMarked(QList<int> list);
75 
76  QList<QGraphicsItem *> selectedItems();
77  QList<int> selectedNodes();
78  QList<SelectedEdge> selectedEdges();
79 
80  void selectAll();
81  void selectNone();
82 
83  void removeItem(GraphicsEdge*);
84  void removeItem(GraphicsEdgeWeight *edgeWeight);
85  void removeItem(GraphicsEdgeLabel *edgeLabel);
86  void removeItem(GraphicsNode*);
87  void removeItem(GraphicsNodeNumber*);
88  void removeItem(GraphicsNodeLabel*);
89 
90  void setNumbersInsideNodes(const bool &toggle);
91 
92  void setAllItemsVisibility(int, bool);
93 
94  void removeAllItems(int);
95 
96 protected:
97 
98  void wheelEvent(QWheelEvent *event);
99  void mouseDoubleClickEvent ( QMouseEvent * e );
100  void mousePressEvent ( QMouseEvent * e );
101  void mouseReleaseEvent(QMouseEvent * e );
102  void resizeEvent( QResizeEvent *e );
103  void paintEvent ( QPaintEvent * event );
104 
105 public slots:
106 
107  void getSelectedItems();
108 
109  void relationSet(int relation);
110 
111  void drawNode(const QPointF &p,
112  const int &num,
113  const int &nodeSize,
114  const QString &nodeShape,
115  const QString &nodeIconPath,
116  const QString &nodeColor,
117  const QString &numberColor,
118  const int &numberSize,
119  const int &numberDistance,
120  const QString &nodeLabel,
121  const QString &labelColor,
122  const int &labelSize,
123  const int &labelDistance);
124  void removeNode(const int &number);
125  void setNodeVisibility(int, bool ); //Called from Graph via MW
126  void setNodeClicked(GraphicsNode *);
127  void moveNode(const int &num, const qreal &x, const qreal &y);
128 
129  bool setNodeSize(const int &nodeNumber, const int &size=0);
130  void setNodeSizeAll(const int &size=0);
131 
132  bool setNodeShape(const int &nodeNumber,
133  const QString &shape,
134  const QString &iconPath=QString::null);
135  bool setNodeColor(const int &, const QString &color);
136 
137  void setNodeNumberColor(const int &nodeNumber, const QString &color);
138  void setNodeNumberVisibility(const bool &toggle);
139  bool setNodeNumberSize(const int &, const int &size=0);
140  bool setNodeNumberDistance(const int &, const int &distance=0);
141 
142  void setNodeLabelsVisibility(const bool &toggle);
143  bool setNodeLabelColor(const int &number, const QString &color="green");
144  bool setNodeLabelSize(const int &, const int &size=0);
145  bool setNodeLabel(const int & , const QString &label);
146  bool setNodeLabelDistance(const int &, const int &distance=0);
147 
148  void drawEdge(const int &source,
149  const int &target,
150  const qreal &weight,
151  const QString &label="",
152  const QString &color="black",
153  const int &type=0,
154  const bool &drawArrows=true,
155  const bool &bezier=false,
156  const bool &weightNumbers=false);
157 
158  void removeEdge(const int &source,
159  const int &target,
160  const bool &removeOpposite=false);
161 
162  void setEdgeVisibility (int relation, int, int, bool);
163 
164  bool setEdgeDirectionType(const int &,
165  const int &,
166  const int &dirType=false);
167 
168  bool setEdgeWeight(const int &, const int &, const qreal &);
169 
170  void setEdgeLabel(const int &, const int&, const QString &);
171 
172  void setEdgeColor(const int &, const int&, const QString &);
173 
174  void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false);
175 
176  void setEdgeOffsetFromNode(const int &source,
177  const int &target,
178  const int &offset);
179  void setEdgeArrowsVisibility(const bool &toggle);
180  void setEdgeWeightNumbersVisibility (const bool &toggle);
181  void setEdgeLabelsVisibility(const bool &toggle);
182 
183  void setEdgeHighlighting(const bool &toggle);
184 
185  void startEdge(GraphicsNode *node);
186 
187  void clearGuides();
188  void addGuideCircle( const double&x0, const double&y0, const double&radius);
189  void addGuideHLine(const double &y0);
190 
191  void zoomIn(int level = 1);
192  void zoomOut(int level = 1);
193  void rotateLeft();
194  void rotateRight();
195  void changeMatrixScale(const int value);
196  void changeMatrixRotation(int angle);
197  void reset();
198 
199 signals:
200  void userDoubleClickNewNode(const QPointF &);
201  void userMiddleClicked(const int &, const int &);
202  void userClickOnEmptySpace(const QPointF &p);
203  void openNodeMenu();
204  void openContextMenu(const QPointF p);
205  void userNodeMoved(const int &, const int &, const int &);
206  //void userSelectedItems(const int nodes, const int edges);
207  void userSelectedItems(const QList<int> selectedNodes,
208  const QList<SelectedEdge> selectedEdges);
209  void userClickedNode(const int &nodeNumber);
210  void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
211  void zoomChanged(const int);
212  void rotationChanged(const int);
213  void resized(const int, const int);
214  void setCursor(Qt::CursorShape);
215 
216 
217 private:
218 
219  H_NumToNode nodeHash; //This is used in drawEdge() method
220  H_StrToEdge edgesHash; // helper hash to easily find edges
221  QList<int> m_selectedNodes;
222  QList<SelectedEdge> m_selectedEdges;
223  int m_curRelation, m_nodeSize;
225  int m_zoomIndex, markedEdgeSourceOrigSize, markedEdgeTargetOrigSize;
228  qreal fX,fY, factor;
229  QString m_nodeLabel, m_numberColor, m_labelColor;
230  QString edgeName;
232  bool secondDoubleClick, clickedEdgeExists;
233  bool m_nodeNumbersInside, m_nodeNumberVisibility, m_nodeLabelVisibility;
235  GraphicsNode *firstNode, *secondNode;
239 };
240 
241 #endif
QList< SelectedEdge > m_selectedEdges
Definition: graphicswidget.h:222
GraphicsNode * secondNode
Definition: graphicswidget.h:235
int m_edgeMinOffsetFromNode
Definition: graphicswidget.h:226
Definition: graphicsguide.h:42
int type() const
Definition: graphicsedgelabel.h:46
bool secondDoubleClick
Definition: graphicswidget.h:232
QPair< int, int > SelectedEdge
Definition: global.h:133
QString edgeName
Definition: graphicswidget.h:230
QPair< int, int > SelectedEdge
Definition: graphicswidget.h:50
Definition: graphicsedgelabel.h:39
QHash< QString, GraphicsEdge * > H_StrToEdge
Definition: graphicswidget.h:43
qreal fY
Definition: graphicswidget.h:228
GraphicsNode * markedEdgeTarget
Definition: graphicswidget.h:237
Definition: graphicsnodelabel.h:37
bool m_edgeHighlighting
Definition: graphicswidget.h:234
QHash< int, GraphicsNode * > H_NumToNode
Definition: graphicswidget.h:46
GraphicsNode * markedEdgeSource
Definition: graphicswidget.h:236
Definition: graphicsnodenumber.h:39
Definition: graphicsedge.h:60
bool transformationActive
Definition: graphicswidget.h:231
GraphicsEdge * clickedEdge
Definition: graphicswidget.h:238
int m_nodeSize
Definition: graphicswidget.h:223
int m_currentRotationAngle
Definition: graphicswidget.h:224
Definition: graphicsnode.h:58
QString m_numberColor
Definition: graphicswidget.h:229
Definition: graphicsedgeweight.h:39
Definition: graphicswidget.h:55
bool m_nodeNumberVisibility
Definition: graphicswidget.h:233
H_NumToNode nodeHash
Definition: graphicswidget.h:219
QList< int > m_selectedNodes
Definition: graphicswidget.h:221
double m_currentScaleFactor
Definition: graphicswidget.h:227
The base window of SocNetV contains all widgets and functionality.
Definition: mainwindow.h:133
H_StrToEdge edgesHash
Definition: graphicswidget.h:220
int markedEdgeTargetOrigSize
Definition: graphicswidget.h:225