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