当前位置: 首页>>代码示例>>Python>>正文


Python QGraphicsLineItem.collidesWithPath方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QGraphicsLineItem.collidesWithPath方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsLineItem.collidesWithPath方法的具体用法?Python QGraphicsLineItem.collidesWithPath怎么用?Python QGraphicsLineItem.collidesWithPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QGraphicsLineItem的用法示例。


在下文中一共展示了QGraphicsLineItem.collidesWithPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EScene

# 需要导入模块: from PyQt4.QtGui import QGraphicsLineItem [as 别名]
# 或者: from PyQt4.QtGui.QGraphicsLineItem import collidesWithPath [as 别名]
class EScene(QGraphicsScene):

    def __init__(self, view=None, parent=None):
        QGraphicsScene.__init__(self, parent)

        if view is None:
            raise AttributeError

        self.__view = view
        self.__create__()

    def __create__(self):

        self.__gridSize = 35

        self.__isGridActive = True
        self.__isAltModifier = False
        self.__isControlModifier = False
        self.__isNodePressed = False

        self.__kDummy = EDummy()
        self.__kDummy.setGridSize(self.__gridSize)
        self.__kDummy.onPress.connect(self.__onNodePressed)
        self.__kDummy.onEditEnd.connect(self.__onDummyEdit)

        self.addItem(self.__kDummy)

        self.__kSelected = ESceneSelection()

        self.addItem(self.__kSelected)

        self.__kCutLine = QGraphicsLineItem()
        self.__kCutLine.hide()

        self.addItem(self.__kCutLine)

        self.__nodes = {}
        self.__connections = {}

        self.__graphHandle = EGraphHandle()
        self.__graphHandle.Message.connect(self.__messageFilter)

        self.__propEditor = EPropertyEditor()
        self.addItem(self.__propEditor)

    def __isNode(self, EObject):
        return isinstance(EObject, ENode)

    def __isEdge(self, EObject):
        return isinstance(EObject, EEdge)

    def __onNodePressed(self):

        if self.__isNode(self.sender()):
            self.__graphHandle.process(self.sender().mapFromPoint(self.__kDummy.scenePos()))
            return

        if not self.__kDummy.isEditMode():
            self.__graphHandle.process(self.__kDummy.Id)

    def __onDummyEdit(self, line):

        if self.__isNode(self.itemAt(line.p1())) and self.__isNode(self.itemAt(line.p2())):
            return

        self.__kCutLine.setLine(line)

        result = []

        for item in self.__kCutLine.collidingItems():
            if isinstance(item, EEdge):

                if self.__kCutLine.collidesWithPath(item.shape()):
                    result.append(item.Id)

        self.__graphHandle.process(result)

    def __getDataFromId(self, theId):
        handle = self.__graphHandle.getHandleFromId(theId)
        if handle:
            return self.__nodes[handle].mapFromId(theId)

        return None

    def __messageFilter(self, message):

        if message.match(EGraphHandle.kMessageEditBegin):
            self.__kDummy.toggleEditMode()
            return

        if message.match(EGraphHandle.kMessageEditEnd):
            if self.__kDummy.isEditMode():
                self.__kDummy.toggleEditMode()
            return

        if message.match(EGraphHandle.kMessageNodeAdded):
            self.addItem(ENode(message.getData()))
            return

        if message.match(EGraphHandle.kMessageNodeRemoved):
#.........这里部分代码省略.........
开发者ID:shrimo,项目名称:node_image_tools,代码行数:103,代码来源:escene.py


注:本文中的PyQt4.QtGui.QGraphicsLineItem.collidesWithPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。