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) 20 from PyQt5.QtCore
import Qt, pyqtSignal
21 from PyQt5.QtGui
import QBrush, QPen
22 from PyQt5.QtWidgets
import QGraphicsEllipseItem, QGraphicsObject, QGraphicsItem
24 from visualstates.gui.state.idtextboxgraphicsitem
import IdTextBoxGraphicsItem
34 posChanged = pyqtSignal(
'QGraphicsItem')
35 stateNameChanged = pyqtSignal(
'QGraphicsItem')
37 stateTextEditStarted = pyqtSignal()
38 stateTextEditFinished = pyqtSignal()
39 doubleClicked = pyqtSignal(
'QGraphicsItem')
42 super(QGraphicsObject, self).
__init__()
44 self.setAcceptHoverEvents(
True)
45 self.setFlag(QGraphicsItem.ItemIsMovable)
46 self.setAcceptDrops(
True)
49 self.setPos(self.stateData.x, self.stateData.y)
54 self.
ellipse = QGraphicsEllipseItem(-StateGraphicsItem.NODE_WIDTH / 2,
55 -StateGraphicsItem.NODE_WIDTH / 2,
56 StateGraphicsItem.NODE_WIDTH,
57 StateGraphicsItem.NODE_WIDTH, self)
58 brush = QBrush(Qt.SolidPattern)
59 brush.setColor(Qt.blue)
60 self.ellipse.setBrush(brush)
62 self.
textGraphics = IdTextBoxGraphicsItem(self.stateData.name, self)
63 textWidth = self.textGraphics.boundingRect().width()
64 self.textGraphics.setPos(-textWidth / 2, StateGraphicsItem.NODE_WIDTH -
65 (StateGraphicsItem.NODE_WIDTH / 2) + 5)
66 self.textGraphics.textChanged.connect(self.
nameChanged)
76 self.
initGraphics = QGraphicsEllipseItem(-StateGraphicsItem.INIT_WIDTH / 2,
77 -StateGraphicsItem.INIT_WIDTH / 2,
78 StateGraphicsItem.INIT_WIDTH,
79 StateGraphicsItem.INIT_WIDTH, self)
81 self.initGraphics.setParentItem(self)
84 self.initGraphics.setParentItem(
None)
87 myPen = QPen(Qt.SolidLine)
88 myPen.setWidth(StateGraphicsItem.PEN_FOCUS_WIDTH)
89 self.ellipse.setPen(myPen)
93 myPen = QPen(Qt.SolidLine)
94 myPen.setWidth(StateGraphicsItem.PEN_NORMAL_WIDTH)
95 self.ellipse.setPen(myPen)
99 if qGraphicsSceneMouseEvent.button() == Qt.LeftButton:
104 if qGraphicsSceneMouseEvent.button() == Qt.LeftButton:
110 self.posChanged.emit(self)
111 super(QGraphicsObject, self).
mouseMoveEvent(qGraphicsSceneMouseEvent)
114 self.doubleClicked.emit(self)
117 return self.ellipse.boundingRect()
120 self.stateData.name = newName
121 textWidth = self.textGraphics.boundingRect().width()
123 self.textGraphics.setPos(-textWidth / 2, StateGraphicsItem.NODE_WIDTH -
124 (StateGraphicsItem.NODE_WIDTH / 2) + 5)
125 self.stateNameChanged.emit(self)
128 self.stateTextEditStarted.emit()
131 self.stateTextEditFinished.emit()
133 def paint(self, QPainter, QStyleOptionGraphicsItem, QWidget_widget=None):
137 brush = QBrush(Qt.SolidPattern)
139 brush.setColor(Qt.green)
141 brush.setColor(Qt.blue)
143 self.ellipse.setBrush(brush)
147 self.textGraphics.disableTextEditingInteraction()
def paint(self, QPainter, QStyleOptionGraphicsItem, QWidget_widget=None)
def mouseDoubleClickEvent(self, qGraphicsSceneMouseEvent)
def setRunning(self, status)
def textEditFinished(self)
def mouseMoveEvent(self, qGraphicsSceneMouseEvent)
def hoverLeaveEvent(self, event)
def mouseReleaseEvent(self, qGraphicsSceneMouseEvent)
def disableInteraction(self)
def setInitial(self, initial)
def textEditStarted(self)
def hoverEnterEvent(self, event)
def nameChanged(self, newName)
def mousePressEvent(self, qGraphicsSceneMouseEvent)