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


Python QPointF.setY方法代码示例

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


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

示例1: applyLayerValue

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def applyLayerValue(self, id, val):
        layer = self.mObject
        layerIndex = self.mMapDocument.map().layers().indexOf(layer)
        command = None
        x = id
        if x==PropertyId.NameProperty:
            command = RenameLayer(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.VisibleProperty:
            command = SetLayerVisible(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.OpacityProperty:
            command = SetLayerOpacity(self.mMapDocument, layerIndex, val)
        elif x==PropertyId.OffsetXProperty or x==PropertyId.OffsetYProperty:
            offset = QPointF(layer.offset())

            if id == PropertyId.OffsetXProperty:
                offset.setX(val)
            else:
                offset.setY(val)

            command = SetLayerOffset(self.mMapDocument, layerIndex, offset)
        else:
            x = layer.layerType()
            if x==Layer.TileLayerType:
                self.applyTileLayerValue(id, val)
            elif x==Layer.ObjectGroupType:
                self.applyObjectGroupValue(id, val)
            elif x==Layer.ImageLayerType:
                self.applyImageLayerValue(id, val)
        if (command):
            self.mMapDocument.undoStack().push(command)
开发者ID:theall,项目名称:Python-Tiled,代码行数:32,代码来源:propertybrowser.py

示例2: activateNeighbor

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def activateNeighbor(self,  active_prexoveritem: 'PreXoverItem',
                                shortcut: str = None):
        """Draws a quad line starting from the item5p to the item3p.
        To be called with whatever the active_prexoveritem is for the parts
        `active_base`.

        Args:
            active_prexoveritem: Description
            shortcut: Default is None
        """
        if self._getActiveTool().methodPrefix() != "selectTool":
            return

        if self.is3p and not active_prexoveritem.is3p:
            item5p = active_prexoveritem
            item3p = self
        elif not self.is3p and active_prexoveritem.is3p:
            item5p = self
            item3p = active_prexoveritem
        else:
            return

        same_parity = self.is_fwd == active_prexoveritem.is_fwd

        p1 = item5p._tick_marks.scenePos() + item5p.exit_pos
        p2 = item3p._tick_marks.scenePos() + item3p.exit_pos

        c1 = QPointF()

        # case 1: same parity
        if same_parity:
            dy = abs(p2.y() - p1.y())
            c1.setX(p1.x() + _X_SCALE * dy)
            c1.setY(0.5 * (p1.y() + p2.y()))
        # case 2: different parity
        else:
            if item3p.is_fwd:
                c1.setX(p1.x() - _X_SCALE * abs(p2.y() - p1.y()))
            else:
                c1.setX(p1.x() + _X_SCALE * abs(p2.y() - p1.y()))
            c1.setY(0.5 * (p1.y() + p2.y()))

        pp = QPainterPath()
        pp.moveTo(self._tick_marks.mapFromScene(p1))
        pp.quadTo(self._tick_marks.mapFromScene(c1),
                  self._tick_marks.mapFromScene(p2))
        # pp.cubicTo(c1, c2, self._tick_marks.mapFromScene(p2))
        self._bond_item.setPath(pp)
        self._bond_item.show()
开发者ID:cadnano,项目名称:cadnano2.5,代码行数:51,代码来源:pathextras.py

示例3: mouseMovedWhileCreatingObject

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def mouseMovedWhileCreatingObject(self, pos, modifiers):
        renderer = self.mapDocument().renderer()
        pixelCoords = renderer.screenToPixelCoords_(pos)
        # Update the size of the new map object
        objectPos = self.mNewMapObjectItem.mapObject().position()
        newSize = QPointF(max(0.0, pixelCoords.x() - objectPos.x()),
                        max(0.0, pixelCoords.y() - objectPos.y()))
        # Holding shift creates circle or square
        if (modifiers & Qt.ShiftModifier):
            m = max(newSize.x(), newSize.y())
            newSize.setX(m)
            newSize.setY(m)

        SnapHelper(renderer, modifiers).snap(newSize)
        self.mNewMapObjectItem.resizeObject(QSizeF(newSize.x(), newSize.y()))
开发者ID:theall,项目名称:Python-Tiled,代码行数:17,代码来源:createscalableobjecttool.py

示例4: offsetObjects

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def offsetObjects(self, offset, bounds, wrapX, wrapY):
        for object in self.mObjects:
            objectCenter = object.bounds().center()
            if (not bounds.contains(objectCenter)):
                continue
            newCenter = QPointF(objectCenter + offset)
            if (wrapX and bounds.width() > 0):
                nx = math.fmod(newCenter.x() - bounds.left(), bounds.width())
                if nx < 0:
                    x = bounds.width() + nx
                else:
                    x = nx
                newCenter.setX(bounds.left() + x)

            if (wrapY and bounds.height() > 0):
                ny = math.fmod(newCenter.y() - bounds.top(), bounds.height())
                if ny < 0:
                    x = bounds.height() + ny
                else:
                    x = ny
                newCenter.setY(bounds.top() + x)

            object.setPosition(object.position() + (newCenter - objectCenter))
开发者ID:theall,项目名称:Python-Tiled,代码行数:25,代码来源:objectgroup.py

示例5: MapObject

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]

#.........这里部分代码省略.........
    ##
    # Returns the position of this object.
    ##
    def position(self):
        return QPointF(self.mPos)

    ##
    # Sets the position of this object.
    ##
    def setPosition(self, pos):
        self.mPos = pos

    ##
    # Returns the x position of this object.
    ##
    def x(self):
        return self.mPos.x()

    ##
    # Sets the x position of this object.
    ##
    def setX(self, x):
        self.mPos.setX(x)

    ##
    # Returns the y position of this object.
    ##
    def y(self):
        return self.mPos.y()

    ##
    # Sets the x position of this object.
    ##
    def setY(self, y):
        self.mPos.setY(y)

    ##
    # Returns the size of this object.
    ##
    def size(self):
        return self.mSize

    ##
    # Sets the size of this object.
    ##
    def setSize(self, *args):
        l = len(args)
        if l==1:
            size = args[0]
            self.mSize = QSizeF(size)
        elif l==2:
            width, height = args
            self.setSize(QSizeF(width, height))

    ##
    # Returns the width of this object.
    ##
    def width(self):
        return self.mSize.width()

    ##
    # Sets the width of this object.
    ##
    def setWidth(self, width):
        self.mSize.setWidth(width)
开发者ID:theall,项目名称:Python-Tiled,代码行数:69,代码来源:mapobject.py

示例6: TeleopWidget

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
class TeleopWidget(QWidget):

    stopSIG=pyqtSignal()

    def __init__(self,winParent):
        super(TeleopWidget, self).__init__()
        self.winParent=winParent
        self.line = QPointF(0, 0);
        self.qimage=QtGui.QImage()
        self.qimage.load(':images/ball.png')
        self.stopSIG.connect(self.stop)
        self.initUI()

    def initUI(self):
        layout=QGridLayout()
        self.setLayout(layout)
        self.setAutoFillBackground(True)
        p = self.palette()
        p.setColor(self.backgroundRole(), Qt.black)
        self.setPalette(p)
        self.resize(300,300)
        self.setMinimumSize(300,300)

    def stop(self):
        self.line = QPointF(0, 0);
        self.repaint();

    def mouseMoveEvent(self,e):
        if e.buttons() == Qt.LeftButton:
            x = e.x()-self.width()/2
            y = e.y()-self.height()/2
            self.line = QPointF(x, y)
            self.repaint()


    def returnToOrigin(self):
        x = 0
        y = 0
        self.line = QPointF(x, y)
        self.repaint()

    def paintEvent(self, e):
        _width = self.width()
        _height = self.height()


        width = 2

        painter=QtGui.QPainter(self)

        pen = QtGui.QPen(Qt.blue, width)
        painter.setPen(pen)

        #Centro del widget
        painter.translate(QPoint(_width/2, _height/2))

        #eje
        painter.drawLine(QPointF(-_width, 0),
                QPointF( _width, 0))

        painter.drawLine(QPointF(0, -_height),
                QPointF(0, _height))

        #con el raton
        pen = QtGui.QPen(Qt.red, width)
        painter.setPen(pen)

        #Comprobamos que el raton este dentro de los limites
        if abs(self.line.x()*2) >= self.size().width():
            if self.line.x()>=0:
                self.line.setX(self.size().width()/2)
            elif self.line.x()<0:
                self.line.setX((-self.size().width()/2)+1)

        if abs(self.line.y()*2) >= self.size().height():
            if self.line.y()>=0:
                self.line.setY(self.size().height()/2)
            elif self.line.y()<0:
                self.line.setY((-self.size().height()/2)+1)

        painter.drawLine(QPointF(self.line.x(), -_height),
                QPointF(self.line.x(), _height))

        painter.drawLine(QPointF(-_width, self.line.y()),
                QPointF( _width, self.line.y()))

        #print "x: %f y: %f" % (self.line.x(), self.line.y())

        v_normalized = (1.0/(self.size().height()/2)) * self.line.y()
        v_normalized = float("{0:.2f}".format(v_normalized))
        w_normalized = (1.0/(self.size().width()/2)) * self.line.x()
        w_normalized = float("{0:.2f}".format(w_normalized))

        #print "v: %f w: %f" % (v_normalized,w_normalized)
        self.winParent.setXYValues(w_normalized,v_normalized)
        painter.drawImage(self.line.x()-self.qimage.width()/2, self.line.y()-self.qimage.height()/2, self.qimage);
开发者ID:aitormf,项目名称:TeachingRobotics,代码行数:98,代码来源:teleopWidget.py

示例7: updateFloatPath

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def updateFloatPath(self, point=None):
        """
        Draws a quad curve from the edge of the fromBase
        to the top or bottom of the toBase (q5), and
        finally to the center of the toBase (toBaseEndpoint).

        If floatPos!=None, this is a floatingXover and floatPos is the
        destination point (where the mouse is) while toHelix, toIndex
        are potentially None and represent the base at floatPos.

        Args:
            point (None, optional): Description

        """
        node3 = self._node3
        node5 = self._node5

        bw = _BASE_WIDTH

        vhi5 = self._virtual_helix_item
        nucleicacid_part_item = vhi5.partItem()
        pt5 = vhi5.mapToItem(nucleicacid_part_item, *node5.floatPoint())

        n5_is_forward = node5.is_forward

        # Enter/exit are relative to the direction that the path travels
        # overall.
        five_enter_pt = pt5 + QPointF(0 if n5_is_forward else 1, .5)*bw
        five_center_pt = pt5 + QPointF(.5, .5)*bw
        five_exit_pt = pt5 + QPointF(.5, 0 if n5_is_forward else 1)*bw

        vhi3 = node3.virtualHelixItem()

        if point:
            pt3 = point
            n3_is_forward = True
            same_strand = False
            same_parity = False
            three_enter_pt = three_center_pt = three_exit_pt = pt3
        else:
            pt3 = vhi3.mapToItem(nucleicacid_part_item, *node3.point())
            n3_is_forward = node3.is_forward
            same_strand = (n5_is_forward == n3_is_forward) and vhi3 == vhi5
            same_parity = n5_is_forward == n3_is_forward

            three_enter_pt = pt3 + QPointF(.5, 0 if n3_is_forward else 1)*bw
            three_center_pt = pt3 + QPointF(.5, .5)*bw
            three_exit_pt = pt3 + QPointF(1 if n3_is_forward else 0, .5)*bw

        c1 = QPointF()
        # case 1: same strand
        if same_strand:
            dx = abs(three_enter_pt.x() - five_exit_pt.x())
            c1.setX(0.5 * (five_exit_pt.x() + three_enter_pt.x()))
            if n5_is_forward:
                c1.setY(five_exit_pt.y() - _yScale * dx)
            else:
                c1.setY(five_exit_pt.y() + _yScale * dx)
            # case 2: same parity
        elif same_parity:
            dy = abs(three_enter_pt.y() - five_exit_pt.y())
            c1.setX(five_exit_pt.x() + _xScale * dy)
            c1.setY(0.5 * (five_exit_pt.y() + three_enter_pt.y()))
        # case 3: different parity
        else:
            if n5_is_forward:
                c1.setX(five_exit_pt.x() - _xScale *
                        abs(three_enter_pt.y() - five_exit_pt.y()))
            else:
                c1.setX(five_exit_pt.x() + _xScale *
                        abs(three_enter_pt.y() - five_exit_pt.y()))
            c1.setY(0.5 * (five_exit_pt.y() + three_enter_pt.y()))

        # Construct painter path
        painterpath = QPainterPath()
        painterpath.moveTo(five_enter_pt)
        painterpath.lineTo(five_center_pt)
        painterpath.lineTo(five_exit_pt)
        painterpath.quadTo(c1, three_enter_pt)
        painterpath.lineTo(three_center_pt)
        painterpath.lineTo(three_exit_pt)

        self.setPath(painterpath)
        self._updateFloatPen()
开发者ID:hadim,项目名称:cadnano2.5,代码行数:86,代码来源:penciltool.py

示例8: _updatePath

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def _updatePath(self, strand5p):
        """
        Draws a quad curve from the edge of the fromBase
        to the top or bottom of the toBase (q5), and
        finally to the center of the toBase (toBaseEndpoint).

        If floatPos!=None, this is a floatingXover and floatPos is the
        destination point (where the mouse is) while toHelix, toIndex
        are potentially None and represent the base at floatPos.

        """
        group = self.group()
        self.tempReparent()

        node3 = self._node3
        node5 = self._node5

        bw = _BASE_WIDTH

        parent = self.partItem()

        vhi5 = self._virtual_helix_item
        pt5 = vhi5.mapToItem(parent, *node5.point())

        five_is_top = node5.isOnTop()
        five_is_5to3 = node5.isDrawn5to3()

        vhi3 = node3.virtualHelixItem()
        pt3 = vhi3.mapToItem(parent, *node3.point())

        three_is_top = node3.isOnTop()
        three_is_5to3 = node3.isDrawn5to3()
        same_strand = (node5.strandType() == node3.strandType()) and vhi3 == vhi5
        same_parity = five_is_5to3 == three_is_5to3

        # Enter/exit are relative to the direction that the path travels
        # overall.
        five_enter_pt = pt5 + QPointF(0 if five_is_5to3 else 1, 0.5) * bw
        five_center_pt = pt5 + QPointF(0.5, 0.5) * bw
        five_exit_pt = pt5 + QPointF(0.5, 0 if five_is_top else 1) * bw

        three_enter_pt = pt3 + QPointF(0.5, 0 if three_is_top else 1) * bw
        three_center_pt = pt3 + QPointF(0.5, 0.5) * bw
        three_exit_pt = pt3 + QPointF(1 if three_is_5to3 else 0, 0.5) * bw

        c1 = QPointF()
        # case 1: same strand
        if same_strand:
            dx = abs(three_enter_pt.x() - five_exit_pt.x())
            c1.setX(0.5 * (five_exit_pt.x() + three_enter_pt.x()))
            if five_is_top:
                c1.setY(five_exit_pt.y() - _Y_SCALE * dx)
            else:
                c1.setY(five_exit_pt.y() + _Y_SCALE * dx)
        # case 2: same parity
        elif same_parity:
            dy = abs(three_enter_pt.y() - five_exit_pt.y())
            c1.setX(five_exit_pt.x() + _X_SCALE * dy)
            c1.setY(0.5 * (five_exit_pt.y() + three_enter_pt.y()))
        # case 3: different parity
        else:
            if five_is_top and five_is_5to3:
                c1.setX(five_exit_pt.x() - _X_SCALE * abs(three_enter_pt.y() - five_exit_pt.y()))
            else:
                c1.setX(five_exit_pt.x() + _X_SCALE * abs(three_enter_pt.y() - five_exit_pt.y()))
            c1.setY(0.5 * (five_exit_pt.y() + three_enter_pt.y()))

        # Construct painter path
        painterpath = QPainterPath()
        painterpath.moveTo(five_enter_pt)
        painterpath.lineTo(five_center_pt)
        painterpath.lineTo(five_exit_pt)

        # The xover5's non-crossing-over end (3') has a connection
        painterpath.quadTo(c1, three_enter_pt)
        painterpath.lineTo(three_center_pt)
        painterpath.lineTo(three_exit_pt)

        tempR = painterpath.boundingRect()
        tempR.adjust(-bw / 2, 0, bw, 0)
        self._click_area.setRect(tempR)
        self.setPath(painterpath)
        node3.updatePositionAndAppearance()
        node5.updatePositionAndAppearance()

        if group:
            group.addToGroup(self)

        self._updateColor(strand5p)
开发者ID:alyosharomanov,项目名称:cadnano2.5,代码行数:91,代码来源:xoveritem.py

示例9: interactiveResize

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def interactiveResize(self, mousePos):
        """
        Handle the interactive resize of the shape.
        :type mousePos: QPointF
        """
        scene = self.scene()
        snap = scene.mainwindow.snapToGrid
        size = scene.GridSize
        offset = self.handleSize + self.handleMove
        moved = self.label.moved

        R = QRectF(self.boundingRect())
        D = QPointF(0, 0)

        minBoundW = self.minwidth + offset * 2
        minBoundH = self.minheight + offset * 2

        self.prepareGeometryChange()

        if self.mousePressHandle == self.handleTL:

            fromX = self.mousePressBound.left()
            fromY = self.mousePressBound.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            toX = snapF(toX, size, -offset, snap)
            toY = snapF(toY, size, -offset, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setLeft(toX)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.width() < minBoundW:
                D.setX(D.x() - minBoundW + R.width())
                R.setLeft(R.left() - minBoundW + R.width())
            if R.height() < minBoundH:
                D.setY(D.y() - minBoundH + R.height())
                R.setTop(R.top() - minBoundH + R.height())

            self.background.setLeft(R.left())
            self.background.setTop(R.top())
            self.selection.setLeft(R.left())
            self.selection.setTop(R.top())
            self.polygon.setLeft(R.left() + offset)
            self.polygon.setTop(R.top() + offset)

        elif self.mousePressHandle == self.handleTM:

            fromY = self.mousePressBound.top()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            toY = snapF(toY, size, -offset, snap)
            D.setY(toY - fromY)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.height() < minBoundH:
                D.setY(D.y() - minBoundH + R.height())
                R.setTop(R.top() - minBoundH + R.height())

            self.background.setTop(R.top())
            self.selection.setTop(R.top())
            self.polygon.setTop(R.top() + offset)

        elif self.mousePressHandle == self.handleTR:

            fromX = self.mousePressBound.right()
            fromY = self.mousePressBound.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            toX = snapF(toX, size, +offset, snap)
            toY = snapF(toY, size, -offset, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setRight(toX)
            R.setTop(toY)

             ## CLAMP SIZE
            if R.width() < minBoundW:
                D.setX(D.x() + minBoundW - R.width())
                R.setRight(R.right() + minBoundW - R.width())
            if R.height() < minBoundH:
                D.setY(D.y() - minBoundH + R.height())
                R.setTop(R.top() - minBoundH + R.height())

            self.background.setRight(R.right())
            self.background.setTop(R.top())
            self.selection.setRight(R.right())
            self.selection.setTop(R.top())
            self.polygon.setRight(R.right() - offset)
            self.polygon.setTop(R.top() + offset)

        elif self.mousePressHandle == self.handleML:

            fromX = self.mousePressBound.left()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toX = snapF(toX, size, -offset, snap)
            D.setX(toX - fromX)
            R.setLeft(toX)

#.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:eddy,代码行数:103,代码来源:concept.py

示例10: PixmapDial

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]

#.........这里部分代码省略.........
        self.fLabelGradientColorT = [enabled, disabled]

    def updateSizes(self):
        self.fPixmapWidth  = self.fPixmap.width()
        self.fPixmapHeight = self.fPixmap.height()

        if self.fPixmapWidth < 1:
            self.fPixmapWidth = 1

        if self.fPixmapHeight < 1:
            self.fPixmapHeight = 1

        if self.fPixmapOrientation == self.HORIZONTAL:
            self.fPixmapBaseSize    = self.fPixmapHeight
            self.fPixmapLayersCount = self.fPixmapWidth / self.fPixmapHeight
        else:
            self.fPixmapBaseSize    = self.fPixmapWidth
            self.fPixmapLayersCount = self.fPixmapHeight / self.fPixmapWidth

        self.setMinimumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5)
        self.setMaximumSize(self.fPixmapBaseSize, self.fPixmapBaseSize + self.fLabelHeight + 5)

        if not self.fLabel:
            self.fLabelHeight = 0
            self.fLabelWidth  = 0
            return

        self.fLabelWidth  = QFontMetrics(self.fLabelFont).width(self.fLabel)
        self.fLabelHeight = QFontMetrics(self.fLabelFont).height()

        self.fLabelPos.setX(float(self.fPixmapBaseSize)/2.0 - float(self.fLabelWidth)/2.0)

        if self.fPixmapNum in ("01", "02", "07", "08", "09", "10"):
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight)
        elif self.fPixmapNum in ("11",):
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight*2/3)
        else:
            self.fLabelPos.setY(self.fPixmapBaseSize + self.fLabelHeight/2)

        self.fLabelGradient.setStart(0, float(self.fPixmapBaseSize)/2.0)
        self.fLabelGradient.setFinalStop(0, self.fPixmapBaseSize + self.fLabelHeight + 5)

        self.fLabelGradientRect = QRectF(float(self.fPixmapBaseSize)/8.0, float(self.fPixmapBaseSize)/2.0, float(self.fPixmapBaseSize*3)/4.0, self.fPixmapBaseSize+self.fLabelHeight+5)

    def setCustomPaintMode(self, paintMode):
        if self.fCustomPaintMode == paintMode:
            return

        self.fCustomPaintMode = paintMode
        self.update()

    def setCustomPaintColor(self, color):
        if self.fCustomPaintColor == color:
            return

        self.fCustomPaintColor = color
        self.update()

    def setLabel(self, label):
        if self.fLabel == label:
            return

        self.fLabel = label
        self.updateSizes()
        self.update()
开发者ID:falkTX,项目名称:Carla,代码行数:69,代码来源:pixmapdial.py

示例11: interactiveResize

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def interactiveResize(self, mousePos):
        """
        Perform shape interactive resize.
        """
        offset = self.handleSize + self.handleSpace
        boundingRect = self.boundingRect()
        rect = self.rect()
        diff = QPointF(0, 0)

        self.prepareGeometryChange()

        if self.handleSelected == self.handleTopLeft:
            fromX = self.mousePressRect.left()
            fromY = self.mousePressRect.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setLeft(toX)
            boundingRect.setTop(toY)
            rect.setLeft(boundingRect.left() + offset)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleTopMiddle:
            fromY = self.mousePressRect.top()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setY(toY - fromY)
            boundingRect.setTop(toY)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleTopRight:
            fromX = self.mousePressRect.right()
            fromY = self.mousePressRect.top()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setRight(toX)
            boundingRect.setTop(toY)
            rect.setRight(boundingRect.right() - offset)
            rect.setTop(boundingRect.top() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleMiddleLeft:
            fromX = self.mousePressRect.left()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            diff.setX(toX - fromX)
            boundingRect.setLeft(toX)
            rect.setLeft(boundingRect.left() + offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleMiddleRight:
            fromX = self.mousePressRect.right()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            diff.setX(toX - fromX)
            boundingRect.setRight(toX)
            rect.setRight(boundingRect.right() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomLeft:
            fromX = self.mousePressRect.left()
            fromY = self.mousePressRect.bottom()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setLeft(toX)
            boundingRect.setBottom(toY)
            rect.setLeft(boundingRect.left() + offset)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomMiddle:
            fromY = self.mousePressRect.bottom()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setY(toY - fromY)
            boundingRect.setBottom(toY)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        elif self.handleSelected == self.handleBottomRight:
            fromX = self.mousePressRect.right()
            fromY = self.mousePressRect.bottom()
            toX = fromX + mousePos.x() - self.mousePressPos.x()
            toY = fromY + mousePos.y() - self.mousePressPos.y()
            diff.setX(toX - fromX)
            diff.setY(toY - fromY)
            boundingRect.setRight(toX)
            boundingRect.setBottom(toY)
            rect.setRight(boundingRect.right() - offset)
            rect.setBottom(boundingRect.bottom() - offset)
            self.setRect(rect)

        self.updateHandlesPos()
开发者ID:zdenop,项目名称:pyTesseractDemo,代码行数:98,代码来源:areaitem.py

示例12: Node

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
class Node(QGraphicsItem):
    Type = QGraphicsItem.UserType + 1

    def __init__(self, graphWidget):
        super(Node, self).__init__()

        self.graph = graphWidget
        self.edgeList = []
        self.newPos = QPointF()

        self.setFlag(QGraphicsItem.ItemIsMovable)
        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
        self.setCacheMode(QGraphicsItem.DeviceCoordinateCache)
        self.setZValue(1)

    def type(self):
        return Node.Type

    def addEdge(self, edge):
        self.edgeList.append(edge)
        edge.adjust()

    def edges(self):
        return self.edgeList

    def calculateForces(self):
        if not self.scene() or self.scene().mouseGrabberItem() is self:
            self.newPos = self.pos()
            return
    
        # Sum up all forces pushing this item away.
        xvel = 0.0
        yvel = 0.0
        for item in self.scene().items():
            if not isinstance(item, Node):
                continue

            line = QLineF(self.mapFromItem(item, 0, 0), QPointF(0, 0))
            dx = line.dx()
            dy = line.dy()
            l = 2.0 * (dx * dx + dy * dy)
            if l > 0:
                xvel += (dx * 150.0) / l
                yvel += (dy * 150.0) / l

        # Now subtract all forces pulling items together.
        weight = (len(self.edgeList) + 1) * 10.0
        for edge in self.edgeList:
            if edge.sourceNode() is self:
                pos = self.mapFromItem(edge.destNode(), 0, 0)
            else:
                pos = self.mapFromItem(edge.sourceNode(), 0, 0)
            xvel += pos.x() / weight
            yvel += pos.y() / weight
    
        if qAbs(xvel) < 0.1 and qAbs(yvel) < 0.1:
            xvel = yvel = 0.0

        sceneRect = self.scene().sceneRect()
        self.newPos = self.pos() + QPointF(xvel, yvel)
        self.newPos.setX(min(max(self.newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10))
        self.newPos.setY(min(max(self.newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10))

    def advance(self):
        if self.newPos == self.pos():
            return False

        self.setPos(self.newPos)
        return True

    def boundingRect(self):
        adjust = 2.0
        return QRectF(-10 - adjust, -10 - adjust, 23 + adjust, 23 + adjust)

    def shape(self):
        path = QPainterPath()
        path.addEllipse(-10, -10, 20, 20)
        return path

    def paint(self, painter, option, widget):
        painter.setPen(Qt.NoPen)
        painter.setBrush(Qt.darkGray)
        painter.drawEllipse(-7, -7, 20, 20)

        gradient = QRadialGradient(-3, -3, 10)
        if option.state & QStyle.State_Sunken:
            gradient.setCenter(3, 3)
            gradient.setFocalPoint(3, 3)
            gradient.setColorAt(1, QColor(Qt.yellow).lighter(120))
            gradient.setColorAt(0, QColor(Qt.darkYellow).lighter(120))
        else:
            gradient.setColorAt(0, Qt.yellow)
            gradient.setColorAt(1, Qt.darkYellow)

        painter.setBrush(QBrush(gradient))
        painter.setPen(QPen(Qt.black, 0))
        painter.drawEllipse(-10, -10, 20, 20)

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemPositionHasChanged:
#.........这里部分代码省略.........
开发者ID:heylenz,项目名称:python27,代码行数:103,代码来源:elasticnodes.py

示例13: mouseMoveEvent

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
    def mouseMoveEvent(self, mouseEvent):
        """
        Executed when then mouse is moved on the view.
        :type mouseEvent: QGraphicsSceneMouseEvent
        """
        scene = self.scene()
        mousePos = mouseEvent.pos()
        mouseButtons = mouseEvent.buttons()
        viewport = self.viewport()

        if mouseButtons & Qt.RightButton:

            if (mouseEvent.pos() - self.mousePressPos).manhattanLength() >= QApplication.startDragDistance():

                ########################################################################################################
                #                                                                                                      #
                #                                            SCENE DRAG                                                #
                #                                                                                                      #
                ########################################################################################################

                if scene.mode is not DiagramMode.SceneDrag:
                    scene.setMode(DiagramMode.SceneDrag)
                    viewport.setCursor(Qt.ClosedHandCursor)

                mousePos /= self.zoom
                mousePressPos = self.mousePressPos / self.zoom
                self.centerOn(self.mousePressCenterPos - mousePos + mousePressPos)

        else:

            super().mouseMoveEvent(mouseEvent)

            if mouseButtons & Qt.LeftButton:
                
                self.stopMove()

                if scene.mode is DiagramMode.RubberBandDrag:

                    ####################################################################################################
                    #                                                                                                  #
                    #                                       RUBBERBAND DRAG                                            #
                    #                                                                                                  #
                    ####################################################################################################

                    area = QRectF(self.mapFromScene(self.rubberBandOrigin), mousePos).normalized()
                    path = QPainterPath()
                    path.addRect(area)
                    scene.setSelectionArea(self.mapToScene(path))
                    self.rubberBand.setGeometry(area.toRect())

                if scene.mode in { DiagramMode.BreakPointMove,
                                   DiagramMode.InsertEdge,
                                   DiagramMode.MoveNode,
                                   DiagramMode.ResizeNode,
                                   DiagramMode.RubberBandDrag }:

                    ####################################################################################################
                    #                                                                                                  #
                    #                                      VIEW SCROLLING                                              #
                    #                                                                                                  #
                    ####################################################################################################

                    R = viewport.rect()
                    if not R.contains(mousePos):

                        move = QPointF(0, 0)

                        if mousePos.x() < R.left():
                            move.setX(mousePos.x() - R.left())
                        elif mousePos.x() > R.right():
                            move.setX(mousePos.x() - R.right())

                        if mousePos.y() < R.top():
                            move.setY(mousePos.y() - R.top())
                        elif mousePos.y() > R.bottom():
                            move.setY(mousePos.y() - R.bottom())

                        if move:
                            move.setX(clamp(move.x(), -MainView.MoveBound, +MainView.MoveBound))
                            move.setY(clamp(move.y(), -MainView.MoveBound, +MainView.MoveBound))
                            self.startMove(move, MainView.MoveRate)
开发者ID:gitter-badger,项目名称:eddy,代码行数:83,代码来源:view.py

示例14: __findIntersection

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]
 def __findIntersection(self, p1, p2, p3, p4):
     """
     Private method to calculate the intersection point of two lines.
     
     The first line is determined by the points p1 and p2, the second
     line by p3 and p4. If the intersection point is not contained in
     the segment p1p2, then it returns (-1.0, -1.0).
     
     For the function's internal calculations remember:<br />
     QT coordinates start with the point (0,0) as the topleft corner
     and x-values increase from left to right and y-values increase
     from top to bottom; it means the visible area is quadrant I in
     the regular XY coordinate system
     
     <pre>
         Quadrant II     |   Quadrant I
        -----------------|-----------------
         Quadrant III    |   Quadrant IV
     </pre>
     
     In order for the linear function calculations to work in this method
     we must switch x and y values (x values become y values and viceversa)
     
     @param p1 first point of first line (QPointF)
     @param p2 second point of first line (QPointF)
     @param p3 first point of second line (QPointF)
     @param p4 second point of second line (QPointF)
     @return the intersection point (QPointF)
     """
     x1 = p1.y()
     y1 = p1.x()
     x2 = p2.y()
     y2 = p2.x()
     x3 = p3.y()
     y3 = p3.x()
     x4 = p4.y()
     y4 = p4.x()
     
     # line 1 is the line between (x1, y1) and (x2, y2)
     # line 2 is the line between (x3, y3) and (x4, y4)
     no_line1 = True    # it is false, if line 1 is a linear function
     no_line2 = True    # it is false, if line 2 is a linear function
     slope1 = 0.0
     slope2 = 0.0
     b1 = 0.0
     b2 = 0.0
     
     if x2 != x1:
         slope1 = (y2 - y1) / (x2 - x1)
         b1 = y1 - slope1 * x1
         no_line1 = False
     if x4 != x3:
         slope2 = (y4 - y3) / (x4 - x3)
         b2 = y3 - slope2 * x3
         no_line2 = False
     
     pt = QPointF()
     # if either line is not a function
     if no_line1 and no_line2:
         # if the lines are not the same one
         if x1 != x3:
             return QPointF(-1.0, -1.0)
         # if the lines are the same ones
         if y3 <= y4:
             if y3 <= y1 and y1 <= y4:
                 return QPointF(y1, x1)
             else:
                 return QPointF(y2, x2)
         else:
             if y4 <= y1 and y1 <= y3:
                 return QPointF(y1, x1)
             else:
                 return QPointF(y2, x2)
     elif no_line1:
         pt.setX(slope2 * x1 + b2)
         pt.setY(x1)
         if y1 >= y2:
             if not (y2 <= pt.x() and pt.x() <= y1):
                 pt.setX(-1.0)
                 pt.setY(-1.0)
         else:
             if not (y1 <= pt.x() and pt.x() <= y2):
                 pt.setX(-1.0)
                 pt.setY(-1.0)
         return pt
     elif no_line2:
         pt.setX(slope1 * x3 + b1)
         pt.setY(x3)
         if y3 >= y4:
             if not (y4 <= pt.x() and pt.x() <= y3):
                 pt.setX(-1.0)
                 pt.setY(-1.0)
         else:
             if not (y3 <= pt.x() and pt.x() <= y4):
                 pt.setX(-1.0)
                 pt.setY(-1.0)
         return pt
     
     if slope1 == slope2:
         pt.setX(-1.0)
#.........这里部分代码省略.........
开发者ID:pycom,项目名称:EricShort,代码行数:103,代码来源:AssociationItem.py

示例15: ObjectSelectionTool

# 需要导入模块: from PyQt5.QtCore import QPointF [as 别名]
# 或者: from PyQt5.QtCore.QPointF import setY [as 别名]

#.........这里部分代码省略.........
        rect = QRectF(self.mStart, pos).normalized()
        # Make sure the rect has some contents, otherwise intersects returns False
        rect.setWidth(max(1.0, rect.width()))
        rect.setHeight(max(1.0, rect.height()))
        selectedItems = QSet()
        for item in self.mapScene().items(rect):
            if type(item) == MapObjectItem:
                selectedItems.insert(item)

        if (modifiers & (Qt.ControlModifier | Qt.ShiftModifier)):
            selectedItems |= self.mapScene().selectedObjectItems()
        else:
            self.setMode(Mode.Resize)
        self.mapScene().setSelectedObjectItems(selectedItems)

    def startSelecting(self):
        self.mAction = Action.Selecting
        self.mapScene().addItem(self.mSelectionRectangle)

    def startMoving(self, modifiers):
        # Move only the clicked item, if it was not part of the selection
        if (self.mClickedObjectItem and not (modifiers & Qt.AltModifier)):
            if (not self.mapScene().selectedObjectItems().contains(self.mClickedObjectItem)):
                self.mapScene().setSelectedObjectItems(QSet([self.mClickedObjectItem]))

        self.saveSelectionState()
        self.mAction = Action.Moving
        self.mAlignPosition = self.mMovingObjects[0].oldPosition
        for object in self.mMovingObjects:
            pos = object.oldPosition
            if (pos.x() < self.mAlignPosition.x()):
                self.mAlignPosition.setX(pos.x())
            if (pos.y() < self.mAlignPosition.y()):
                self.mAlignPosition.setY(pos.y())

        self.updateHandleVisibility()

    def updateMovingItems(self, pos, modifiers):
        renderer = self.mapDocument().renderer()

        diff = self.snapToGrid(pos-self.mStart, modifiers)
        for object in self.mMovingObjects:
            newPixelPos = object.oldItemPosition + diff
            newPos = renderer.screenToPixelCoords_(newPixelPos)

            mapObject = object.item.mapObject()
            mapObject.setPosition(newPos)
        self.mapDocument().mapObjectModel().emitObjectsChanged(self.changingObjects())
        
    def finishMoving(self, pos):
        self.mAction = Action.NoAction
        self.updateHandles()
        if (self.mStart == pos): # Move is a no-op
            return
        undoStack = self.mapDocument().undoStack()
        undoStack.beginMacro(self.tr("Move %n Object(s)", "", self.mMovingObjects.size()))
        for object in self.mMovingObjects:
            undoStack.push(MoveMapObject(self.mapDocument(), object.item.mapObject(), object.oldPosition))

        undoStack.endMacro()
        self.mMovingObjects.clear()

    def startRotating(self):
        self.mAction = Action.Rotating
        self.mOrigin = self.mOriginIndicator.pos()
        self.saveSelectionState()
开发者ID:theall,项目名称:Python-Tiled,代码行数:70,代码来源:objectselectiontool.py


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