-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathNetworkView.py
90 lines (73 loc) · 3.35 KB
/
NetworkView.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from PyQt4 import QtCore, QtGui
import GlobalParameters
import Utility
class NetworkViewer(QtGui.QGraphicsView):
def __init__(self, parent):
super(NetworkViewer, self).__init__(parent)
self._zoom = 0
self.totalFactor = 1.0
self.pan = False
self.parentClass = None
# self.startX = 0
# self.startY = 0
self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
def SetParentClass(self, parentClass):
self.parentClass = parentClass
def zoomFactor(self):
return self._zoom
def wheelEvent(self, event):
if len(self.scene().items()) > 0:
if event.delta() > 0:
factor = 1.25
self._zoom += 1
else:
factor = 0.8
self._zoom -= 1
if self._zoom != 0:
self.scale(factor, factor)
self.totalFactor *= factor
elif self._zoom == 0:pass
#self.fitInView()
else:
self._zoom = 0
def mouseDoubleClickEvent(self, QMouseEvent):
if QMouseEvent.button() == QtCore.Qt.RightButton:
self.scale(1/self.totalFactor, 1/self.totalFactor)
self.totalFactor = 1.0
if QMouseEvent.button() == QtCore.Qt.LeftButton:
if self.parentClass is None:
return
currentX = QMouseEvent.x()
currentY = QMouseEvent.y()
for node in self.parentClass.nodeItemList:
rect = self.parentClass.nodeItemList[node].rect()
topLeft = rect.topLeft()
topRight = rect.topRight()
bottomLeft = rect.bottomLeft()
if currentX >= topLeft.x() and currentX <= topRight.x() and currentY <= bottomLeft.y() and currentY >= topLeft.y():
item = self.parentClass.nodeItemList[node]
brush = QtGui.QBrush(QtGui.QColor(GlobalParameters.SeedNodeBrushColor))
item.setBrush(brush)
seedText = self.parentClass.textEditSeedNodes.toPlainText()
self.parentClass.textEditSeedNodes.setPlainText(str(seedText + ";" + str(node)).lstrip(";"))
break
def mousePressEvent(self, QMouseEvent):
if QMouseEvent.button() == QtCore.Qt.LeftButton:
self.pan = True
self.startX = QtGui.QCursor.pos().x()
self.startY = QtGui.QCursor.pos().y()
self.setCursor(QtCore.Qt.ClosedHandCursor)
def mouseReleaseEvent(self, QMouseEvent):
if QMouseEvent.button() == QtCore.Qt.LeftButton:
self.pan = False
self.setCursor(QtCore.Qt.ArrowCursor)
def mouseMoveEvent(self, QMouseEvent):
if self.pan:
pos = QtGui.QCursor.pos()
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - (pos.x() - self.startX))
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - (pos.y() - self.startY))
self.startX = pos.x()
self.startY = pos.y()