graphicswidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.1
4  Written in Qt
5 
6  graphicswidget.h - description
7  -------------------
8  copyright : (C) 2005-2023 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 <QHash>
34 
35 class MainWindow;
36 class GraphicsNode;
37 class GraphicsEdge;
38 class GraphicsNodeNumber;
39 class GraphicsNodeLabel;
40 class GraphicsGuide;
41 class GraphicsEdgeWeight;
42 class GraphicsEdgeLabel;
43 
44 typedef QHash<QString, GraphicsEdge*> H_StrToEdge;
45 typedef QHash <int, GraphicsNode*> H_NumToNode;
46 
47 
48 typedef QPair<int, int> SelectedEdge;
49 
50 Q_DECLARE_METATYPE(SelectedEdge)
51 
52 
53 class GraphicsWidget : public QGraphicsView {
54  Q_OBJECT
55 
56 public:
57 
58  GraphicsWidget(QGraphicsScene *m_scene, MainWindow *m_parent);
59  ~GraphicsWidget();
60 
61  void clear();
62 
63  QString createEdgeName(const int &v1,
64  const int &v2,
65  const int &relation=-1);
66 
67  void setInitNodeSize(int);
68 
69  void setInitZoomIndex (const int &);
70  void setMaxZoomIndex (const int &);
71 
72  GraphicsNode* hasNode(QString text);
73  void setSelectedNodes(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 handleSelectionChanged();
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 &nodeNum);
123  void setNodeVisibility(const int &nodeNum, 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 &nodeNum,
131  const QString &shape,
132  const QString &iconPath=QString());
133  bool setNodeColor(const int &nodeNum, const QString &color);
134 
135  void setNodeNumberColor(const int &nodeNum, const QString &color);
136  void setNodeNumberVisibility(const bool &toggle);
137  bool setNodeNumberSize(const int &nodeNum, 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 &nodeNum, 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,
161  const int &sourceNum,
162  const int &targetNum,
163  const bool &visible,
164  const bool &preserveReverseEdge=false,
165  const int &edgeWeight=1,
166  const int &reverseEdgeWeight=1);
167 
168  bool setEdgeDirectionType(const int &source,
169  const int &target,
170  const int &dirType=false);
171 
172  bool setEdgeWeight(const int &, const int &, const qreal &);
173 
174  void setEdgeLabel(const int &source, const int &target, const QString &label);
175 
176  void setEdgeColor(const int &, const int&, const QString &);
177 
178  void setEdgeClicked(GraphicsEdge *, const bool &openMenu=false);
179 
180  void setEdgeOffsetFromNode(const int &source,
181  const int &target,
182  const int &offset);
183  void setEdgeArrowsVisibility(const bool &toggle);
184  void setEdgeWeightNumbersVisibility (const bool &toggle);
185  void setEdgeLabelsVisibility(const bool &toggle);
186 
187  void setEdgeHighlighting(const bool &toggle);
188 
189  void handleDoubleClickOnNode(GraphicsNode *node);
190 
191  void clearGuides();
192  void addGuideCircle( const double&x0, const double&y0, const double&radius);
193  void addGuideHLine(const double &y0);
194 
195  void zoomIn(const int step = 1);
196  void zoomOut(const int step = 1);
197  void rotateLeft();
198  void rotateRight();
199  void changeMatrixScale(const int value);
200  void changeMatrixRotation(int angle);
201  void reset();
202 
203  void setOptionsOpenGL(const bool &enabled=false);
204  void setOptionsAntialiasing(const bool &toggle);
205  void setOptionsNoAntialiasingAutoAdjust(const bool &toggle);
206 
207 signals:
208  void userDoubleClickNewNode(const QPointF &);
209  void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1);
210  void userClickOnEmptySpace(const QPointF &p);
211  void openNodeMenu();
212  void openContextMenu(const QPointF p);
213  void userNodeMoved(const int &, const int &, const int &);
214  //void userSelectedItems(const int nodes, const int edges);
215  void userSelectedItems(const QList<int> selectedNodes,
216  const QList<SelectedEdge> selectedEdges);
217  void userClickedNode(const int &nodeNumber, const QPointF &p);
218  void userClickedEdge(const int &source, const int &target, const bool &openMenu=false);
219  void zoomChanged(const int);
220  void rotationChanged(const int);
221  void resized(const int, const int);
222  void setCursor(Qt::CursorShape);
223 
224 
225 private:
226 
227  H_NumToNode nodeHash; //Our basic hash table for node items
228  H_StrToEdge edgesHash; // Our basic hash table for edge items
229  QList<int> m_selectedNodes;
230  QList<SelectedEdge> m_selectedEdges;
231  int m_curRelation, m_nodeSize;
233  int m_zoomIndex, m_zoomIndexInit, m_zoomIndexMax;
234  int markedEdgeSourceOrigSize, markedEdgeTargetOrigSize;
237  qreal fX,fY, factor;
238  QString m_nodeLabel, m_numberColor, m_labelColor;
239  QString edgeName;
241  bool hasDoubleClickedNode, clickedEdgeExists;
242  bool m_nodeNumbersInside, m_nodeNumberVisibility, m_nodeLabelVisibility;
244  GraphicsNode *firstDoubleClickedNode, *secondDoubleClickedNode;
248 };
249 
250 #endif
Definition: graphicsedgelabel.h:38
int type() const
Definition: graphicsedgelabel.h:44
Definition: graphicsedgeweight.h:38
Definition: graphicsedge.h:60
Definition: graphicsguide.h:41
Definition: graphicsnodelabel.h:37
Definition: graphicsnodenumber.h:38
Definition: graphicsnode.h:58
Definition: graphicswidget.h:53
int m_edgeMinOffsetFromNode
Definition: graphicswidget.h:235
int m_zoomIndex
Definition: graphicswidget.h:233
QString m_labelColor
Definition: graphicswidget.h:238
void userDoubleClickNewNode(const QPointF &)
void userMiddleClicked(const int &sourceNum, const int &targetNum, const qreal &weight=1)
QList< SelectedEdge > m_selectedEdges
Definition: graphicswidget.h:230
void userNodeMoved(const int &, const int &, const int &)
void resized(const int, const int)
void userClickedEdge(const int &source, const int &target, const bool &openMenu=false)
int markedEdgeSourceOrigSize
Definition: graphicswidget.h:234
void userClickedNode(const int &nodeNumber, const QPointF &p)
void userClickOnEmptySpace(const QPointF &p)
H_NumToNode nodeHash
Definition: graphicswidget.h:227
bool m_isTransformationActive
Definition: graphicswidget.h:240
void userSelectedItems(const QList< int > selectedNodes, const QList< SelectedEdge > selectedEdges)
QList< int > m_selectedNodes
Definition: graphicswidget.h:229
bool clickedEdgeExists
Definition: graphicswidget.h:241
double m_currentScaleFactor
Definition: graphicswidget.h:236
GraphicsNode * markedEdgeSource
Definition: graphicswidget.h:245
void zoomChanged(const int)
void openContextMenu(const QPointF p)
bool m_nodeLabelVisibility
Definition: graphicswidget.h:242
void setCursor(Qt::CursorShape)
QString edgeName
Definition: graphicswidget.h:239
int m_curRelation
Definition: graphicswidget.h:231
void openNodeMenu()
void rotationChanged(const int)
GraphicsEdge * clickedEdge
Definition: graphicswidget.h:247
GraphicsNode * firstDoubleClickedNode
Definition: graphicswidget.h:244
bool m_edgeHighlighting
Definition: graphicswidget.h:243
GraphicsNode * markedEdgeTarget
Definition: graphicswidget.h:246
qreal factor
Definition: graphicswidget.h:237
int m_currentRotationAngle
Definition: graphicswidget.h:232
H_StrToEdge edgesHash
Definition: graphicswidget.h:228
The base window of SocNetV contains all widgets and functionality.
Definition: mainwindow.h:115
QPair< int, int > SelectedEdge
Definition: global.h:147
QHash< int, GraphicsNode * > H_NumToNode
Definition: graphicswidget.h:45
QPair< int, int > SelectedEdge
Definition: graphicswidget.h:48
QHash< QString, GraphicsEdge * > H_StrToEdge
Definition: graphicswidget.h:42