graphicswidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.2
4  Written in Qt
5 
6  graphicswidget.h - description
7  -------------------
8  copyright : (C) 2005-2017 by Dimitris B. Kalamaras
9  project site : http://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 
33 #include <QGraphicsView>
34 
35 
36 class MainWindow;
37 class Node;
38 class Edge;
39 class NodeNumber;
40 class NodeLabel;
41 class Guide;
42 class EdgeWeight;
43 class EdgeLabel;
44 
45 typedef QHash<QString, Edge*> H_StrToEdge;
46 typedef QHash <long int, Node*> H_NumToNode;
47 
48 using namespace std;
49 
50 
51 typedef pair<int, int> SelectedEdge;
52 
53 class GraphicsWidget : public QGraphicsView {
54  Q_OBJECT
55 public:
56  GraphicsWidget(QGraphicsScene*, MainWindow* parent);
57  ~GraphicsWidget();
58  void clear();
59 
60  void setInitNodeSize(int);
61  void setInitZoomIndex (int);
62 
63 
64  Node* hasNode(QString text);
65  bool setMarkedNode(QString text);
66 
67  QList<QGraphicsItem *> selectedItems();
68  QList<int> selectedNodes();
69  QList<SelectedEdge> selectedEdges();
70 
71  void selectAll();
72  void selectNone();
73 
74  void removeItem(Edge*);
75  void removeItem(EdgeWeight *edgeWeight);
76  void removeItem(EdgeLabel *edgeLabel);
77  void removeItem(Node*);
78  void removeItem(NodeNumber*);
79  void removeItem(NodeLabel*);
80 
81  void setNumbersInsideNodes(bool);
82 
83  void setAllItemsVisibility(int, bool);
84 
85  void removeAllItems(int);
86 protected:
87  void wheelEvent(QWheelEvent *event);
88  void mouseDoubleClickEvent ( QMouseEvent * e );
89  void mousePressEvent ( QMouseEvent * e );
90  void mouseReleaseEvent(QMouseEvent * e );
91  void resizeEvent( QResizeEvent *e );
92  void paintEvent ( QPaintEvent * event );
93 
94 public slots:
95 
96  void getSelectedItems();
97 
98  void relationSet(int relation);
99 
100  void drawNode(const int &num, const int &nodeSize,
101  const QString &nodeShape, const QString &nodeColor,
102  const bool &showNumbers, const bool &numberInsideNode,
103  const QString &numberColor, const int &numberSize,
104  const int &numberDistance,
105  const bool &showLabels, const QString &nodeLabel,
106  const QString &labelColor, const int &labelSize,
107  const int &labelDistance,
108  const QPointF &p
109  );
110  void eraseNode(const long int &number);
111  void setNodeVisibility(long int, bool ); //Called from Graph via MW
112  void nodeClicked(Node *);
113  void moveNode(const int &num, const qreal &x, const qreal &y); //Called from Graph when creating random nets.
114 
115  bool setNodeSize(const long int &nodeNumber, const int &size=0);
116  void setAllNodeSize(const int &size=0);
117 
118  bool setNodeShape(const long int &nodeNumber, const QString &shape);
119  bool setNodeColor(const long int &, const QString &color);
120 
121  void setNodeNumberVisibility(const bool &toggle);
122  bool setNodeNumberSize(const long int &, const int &size=0);
123  bool setNodeNumberDistance(const long int &, const int &distance=0);
124 
125  void setNodeLabelsVisibility(const bool &toggle);
126  bool setNodeLabelColor(const long int &number, const QString &color="green");
127  bool setNodeLabelSize(const long int &, const int &size=0);
128  bool setNodeLabel(long int , QString );
129  bool setNodeLabelDistance(const long int &, const int &distance=0);
130 
131  void drawEdge(const int &source, const int &target,
132  const float &weight,
133  const QString &label="",
134  const QString &color="black",
135  const int &type=0,
136  const bool &drawArrows=true,
137  const bool &bezier=false,
138  const bool &weightNumbers=false);
139  void eraseEdge(const long int &source, const long int &target);
140  void setEdgeVisibility (int relation, int, int, bool);
141  bool setEdgeUndirected(const long int &, const long int &, const float &);
142  bool setEdgeWeight(const long int &, const long int &, const float &);
143  void setEdgeLabel(const long int &, const long int&, const QString &);
144  void setEdgeColor(const long int &, const long int&, const QString &);
145  void edgeClicked(Edge *);
146  void setEdgeWeightNumbersVisibility (const bool &toggle);
147  void setEdgeLabelsVisibility(const bool &toggle);
148 
149  void startEdge(Node *node);
150 
151  void clearGuides();
152  void addGuideCircle( const double&x0, const double&y0, const double&radius);
153  void addGuideHLine(const double &y0);
154 
155  void zoomIn(int level = 1);
156  void zoomOut(int level = 1);
157  void rotateLeft();
158  void rotateRight();
159  void changeMatrixScale(const int value);
160  void changeMatrixRotation(int angle);
161  void reset();
162 
163 signals:
164  void userDoubleClickNewNode(const QPointF &);
165  void userMiddleClicked(const int &, const int &);
166  void userClickOnEmptySpace(const QPointF &p);
167  void openNodeMenu();
168  void openEdgeMenu();
169  void openContextMenu(const QPointF p);
170  void userNodeMoved(const int &, const int &, const int &);
171  //void userSelectedItems(const int nodes, const int edges);
172  void userSelectedItems(const QList<int> &selectedNodes,
173  const QList<SelectedEdge> &selectedEdges);
174  void userClickedNode(const int &nodeNumber);
175  void userClickedEdge(const int &source, const int &target);
176  void zoomChanged(const int);
177  void rotationChanged(const int);
178  void resized(const int, const int);
179  void setCursor(Qt::CursorShape);
180 
181 
182 
183 private:
184  H_NumToNode nodeHash; //This is used in drawEdge() method
185  H_StrToEdge edgesHash; // helper hash to easily find edges
186  QList<int> m_selectedNodes;
187  QList<SelectedEdge> m_selectedEdges;
188  int m_curRelation, m_nodeSize;
190  int m_zoomIndex, markedNodeOrigSize,markedEdgeSourceOrigSize, markedEdgeTargetOrigSize;
192  qreal fX,fY, factor;
193  QString m_nodeLabel, m_numberColor, m_labelColor;
194  QString edgeName;
196  bool secondDoubleClick, markedNodeExist, clickedEdgeExists;
197  Node *firstNode, *secondNode, *markedNode1, *markedEdgeSource;
198  Node *markedEdgeTarget, *tempNode ;
199 };
200 
201 #endif
QList< SelectedEdge > m_selectedEdges
Definition: graphicswidget.h:187
pair< int, int > SelectedEdge
Definition: graphicswidget.h:51
Definition: node.h:56
Definition: guide.h:42
bool secondDoubleClick
Definition: graphicswidget.h:196
Definition: nodenumber.h:39
QString edgeName
Definition: graphicswidget.h:194
int markedNodeOrigSize
Definition: graphicswidget.h:190
Definition: edge.h:54
Definition: edgelabel.h:39
qreal fY
Definition: graphicswidget.h:192
Node * tempNode
Definition: graphicswidget.h:198
Definition: nodelabel.h:37
bool transformationActive
Definition: graphicswidget.h:195
QHash< long int, Node * > H_NumToNode
Definition: graphicswidget.h:46
int m_nodeSize
Definition: graphicswidget.h:188
int m_currentRotationAngle
Definition: graphicswidget.h:189
QString m_numberColor
Definition: graphicswidget.h:193
QHash< QString, Edge * > H_StrToEdge
Definition: graphicswidget.h:43
Definition: graphicswidget.h:53
H_NumToNode nodeHash
Definition: graphicswidget.h:184
QList< int > m_selectedNodes
Definition: graphicswidget.h:186
double m_currentScaleFactor
Definition: graphicswidget.h:191
The base window of SocNetV contains all widgets and functionality.
Definition: mainwindow.h:105
H_StrToEdge edgesHash
Definition: graphicswidget.h:185
Node * secondNode
Definition: graphicswidget.h:197
Definition: edgeweight.h:39