2 Copyright (C) 1997-2017 JDERobot Developers Team 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU Library General Public License for more details. 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, see <http://www.gnu.org/licenses/>. 17 Authors : Okan Asik (asik.okan@gmail.com) 22 from PyQt5.QtCore
import Qt, QPointF, QLineF, pyqtSignal
23 from PyQt5.QtGui
import QBrush, QPolygonF
24 from PyQt5.QtWidgets
import QGraphicsObject, QGraphicsLineItem, QGraphicsPolygonItem, QGraphicsItem
26 from visualstates.gui.state.idtextboxgraphicsitem
import IdTextBoxGraphicsItem
27 from visualstates.gui.state.guistate
import StateGraphicsItem
28 from visualstates.gui.transition.recthandlegraphicsitem
import RectHandleGraphicsItem
38 posChanged = pyqtSignal(
'QGraphicsItem')
41 super(QGraphicsObject, self).
__init__()
57 self.
midPointX = (self.graphicsDestination.scenePos().x() + self.graphicsOrigin.scenePos().x()) / 2.0
58 self.
midPointY = (self.graphicsDestination.scenePos().y() + self.graphicsOrigin.scenePos().y()) / 2.0
77 self.graphicsOrigin.scenePos().y(), self)
79 self.originLine.setLine(QLineF(self.
midPointX, self.
midPointY, self.graphicsOrigin.scenePos().x(),
80 self.graphicsOrigin.scenePos().y()))
81 myLine = self.originLine.line()
82 myLine.setLength(myLine.length() - StateGraphicsItem.NODE_WIDTH / 2)
83 self.originLine.setLine(myLine)
88 self.graphicsDestination.scenePos().y(), self)
90 self.destinationLine.setLine(QLineF(self.
midPointX, self.
midPointY, self.graphicsDestination.scenePos().x(),
91 self.graphicsDestination.scenePos().y()))
93 myLine = self.destinationLine.line()
94 myLine.setLength(myLine.length() - StateGraphicsItem.NODE_WIDTH / 2)
95 self.destinationLine.setLine(myLine)
99 myLine = self.destinationLine.line()
100 myLine.setLength(myLine.length() - TransitionGraphicsItem.ARROW_SIZE)
101 rotatePoint = myLine.p2() - self.destinationLine.line().p2()
103 rightPointX = rotatePoint.x() * math.cos(math.pi / 6) - rotatePoint.y() * math.sin(math.pi / 6)
104 rightPointY = rotatePoint.x() * math.sin(math.pi / 6) + rotatePoint.y() * math.cos(math.pi / 6)
105 rightPoint = QPointF(rightPointX + self.destinationLine.line().x2(),
106 rightPointY + self.destinationLine.line().y2())
108 leftPointX = rotatePoint.x() * math.cos(-math.pi / 6) - rotatePoint.y() * math.sin(-math.pi / 6)
109 leftPointY = rotatePoint.x() * math.sin(-math.pi / 6) + rotatePoint.y() * math.cos(-math.pi / 6)
110 leftPoint = QPointF(leftPointX + self.destinationLine.line().x2(),
111 leftPointY + self.destinationLine.line().y2())
113 polygon = QPolygonF()
114 polygon << rightPoint << leftPoint << self.destinationLine.line().p2() << rightPoint
116 if self.
arrow ==
None:
117 self.
arrow = QGraphicsPolygonItem(polygon, self)
119 self.arrow.setPolygon(polygon)
121 brush = QBrush(Qt.SolidPattern)
122 brush.setColor(Qt.black)
123 self.arrow.setBrush(brush)
128 self.
middleHandle = RectHandleGraphicsItem(TransitionGraphicsItem.SQUARE_SIDE, self)
129 self.middleHandle.setFlag(QGraphicsItem.ItemIsMovable)
135 self.
textGraphics = IdTextBoxGraphicsItem(self.transitionData.name, self)
136 self.textGraphics.textChanged.connect(self.
nameChanged)
138 self.textGraphics.setPlainText(self.transitionData.name)
139 textWidth = self.textGraphics.boundingRect().width()
140 self.textGraphics.setPos(self.
midPointX - textWidth / 2, self.
midPointY + TransitionGraphicsItem.SQUARE_SIDE -
141 (TransitionGraphicsItem.SQUARE_SIDE / 2) + 5)
150 self.posChanged.emit(self)
153 self.transitionData.name = name
158 return self.middleHandle.boundingRect()
164 self.middleHandle.setFlag(QGraphicsItem.ItemIsMovable,
False)
165 self.middleHandle.disableInteraction()
167 self.textGraphics.disableTextEditingInteraction()
def statePosChanged(self, state)
def updateMiddlePoints(self, newPosition)
def createIdTextBox(self)
def createMiddleHandle(self)
def createDestinationLine(self)
def disableInteraction(self)
def createOriginLine(self)
def nameChanged(self, name)