Python PyQt5.QtCore 模块,QPointF() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtCore.QPointF()

项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def generateNodes(count, offset, depth):
    for i in range(count):
        node1 = Node(graph, 'node' + str(depth) + str(i))
        node1.addPort(InputPort(node1, graph, 'InPort', QtGui.QColor(128, 170, 170, 255), 'MyDataX'))
        node1.addPort(OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataX'))
        node1.setNodePos(QtCore.QPointF(offset, i * 100))

        graph.addNode(node1)

        global totalCount
        totalCount += 1

    if depth < 6:
        generateNodes(count * 2, offset+160, depth+1)

        for i in range(count):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2), 'InPort')
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2+1), 'InPort')
    elif depth < 12:
        generateNodes(int(count / 2), offset+160, depth+1)

        for i in range(count//2):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(int(i)), 'InPort')
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def mouseMoveEvent(self, event):
        if self.__dragging:
            newPos = self.mapToScene(event.pos())

            graph = self.getGraph()
            if graph.getSnapToGrid() is True:
                gridSize = graph.getGridSize()

                newNodePos = newPos - self._mouseDelta

                snapPosX = math.floor(newNodePos.x() / gridSize) * gridSize
                snapPosY = math.floor(newNodePos.y() / gridSize) * gridSize
                snapPos = QtCore.QPointF(snapPosX, snapPosY)

                newPosOffset = snapPos - newNodePos

                newPos = newPos + newPosOffset

            delta = newPos - self._lastDragPoint
            self.__graph.moveSelectedNodes(delta)
            self._lastDragPoint = newPos
            self._nodesMoved = True
        else:
            super(Node, self).mouseMoveEvent(event)
项目:QtPropertyBrowserV2.6-for-pyqt5    作者:theall    | 项目源码 | 文件源码
def initializeProperty(self, property):
        if (self.propertyType(property) == QVariant.PointF):
            d = VariantManager.Data()

            d.value = QVariant(QPointF(0, 0))

            d.x = self.addProperty(QVariant.Double)
            d.x.setPropertyName(self.tr("Position X"))
            property.addSubProperty(d.x)
            self.xToProperty[d.x] = property

            d.y = self.addProperty(QVariant.Double)
            d.y.setPropertyName(self.tr("Position Y"))
            property.addSubProperty(d.y)
            self.yToProperty[d.y] = property

            self.propertyToData[property] = d

        super(VariantManager, self).initializeProperty(property)
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def transfer():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    dx = window.spin_trans_x.value()
    dy = window.spin_trans_y.value()
    scene.clear()
    p1 = [p1[0] + dx, p1[1] + dy]
    p2 = [p2[0] + dx, p2[1] + dy]
    p3 = [p3[0] + dx, p3[1] + dy]
    p4 = [p4[0] + dx, p4[1] + dy]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    epi_x = [x + dx for x in epi_x]
    epi_y = [y + dy for y in epi_y]
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def set():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    scene.clear()
    dx = 500
    dy = 500
    kx = 10
    ky = 10
    p1 = [-10 * kx + dx, -10 * ky + dy]
    p2 = [-10 * kx + dx + 20 * kx, -10 * ky + dy]
    p3 = [-10 * kx + dx + 20 * kx, -10 * ky + dy + 20 * ky]
    p4 = [-10 * kx + dx, -10 * ky + dy + 20 * ky]

    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    epi_x = []
    epi_y = []
    scene.addPolygon(rect, pen=p, brush=b)
    for t in np.arange(0, 4 * math.pi, 0.001):
        x = 5 * math.cos(t) * kx - 2 * math.cos(5 / 2 * t) * kx + dx
        y = 5 * math.sin(t) * ky - 2 * math.sin(5 / 2 * t) * ky + dy
        epi_x.append(x)
        epi_y.append(y)
        scene.addLine(x, y, x + 0.01, y + 0.01, pen=p)
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def undo():
    global b_epi_x, b_epi_y, b1, b2, b3, b4, epi_x, epi_y, p1, p2, p3, p4, btn_undo
    epi_x = b_epi_x
    epi_y = b_epi_y
    p1 = b1
    p2 = b2
    p3 = b3
    p4 = b4
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.clear()
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
项目:pyree-old    作者:DrLuke    | 项目源码 | 文件源码
def update(self, pos=None):
                path = QPainterPath()

                if pos is not None:
                    if self.ioend is None:
                        startpos = self.iostart.pos() + self.iostart.parent.pos()
                        endpos = pos
                    elif self.iostart is None:
                        startpos = pos
                        endpos = self.ioend.pos() + self.ioend.parent.pos()
                else:
                    startpos = self.iostart.pos() + self.iostart.parent.pos()
                    endpos = self.ioend.pos() + self.ioend.parent.pos()

                controlpoint = QPointF(abs((endpos - startpos).x()) * 0.8, 0)

                path.moveTo(startpos)
                path.cubicTo(startpos + controlpoint,
                             endpos - controlpoint,
                             endpos)

                self.setPath(path)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, startp=Point(), endp=None,
                 length=60.0, angle=50.0,
                 color=QtCore.Qt.red, pencolor=QtCore.Qt.green,
                 startarrow=True):
        """
        Initialisation of the class.
        """
        self.sc = None
        super(Arrow, self).__init__()

        self.startp = QtCore.QPointF(startp.x, -startp.y)
        self.endp = endp

        self.length = length
        self.angle = angle
        self.startarrow = startarrow
        self.allwaysshow = False

        self.arrowHead = QPolygonF()
        self.setFlag(QGraphicsItem.ItemIsSelectable, False)
        self.myColor = color
        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)
        self.arrowSize = 8.0
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def boundingRect(self):
        """
        Override inherited function to enlarge selection of Arrow to include all
        @param flag: The flag to enable or disable Selection
        """
        if not self.sc:  # since this function is called before paint; and scale is unknown
            return QtCore.QRectF(self.startp.x(), self.startp.y(), 1e-9, 1e-9)

        arrowSize = self.arrowSize / self.sc
        extra = arrowSize  # self.pen.width() +

        if self.endp is None:
            dx = cos(self.angle) * self.length / self.sc
            dy = sin(self.angle) * self.length / self.sc

            endp = QtCore.QPointF(self.startp.x() - dx, self.startp.y() + dy)
        else:
            endp = QtCore.QPointF(self.endp.x, -self.endp.y)

        brect = QtCore.QRectF(self.startp,
                              QtCore.QSizeF(endp.x()-self.startp.x(),
                                            endp.y()-self.startp.y())).normalized().adjusted(-extra, -extra, extra, extra)
        return brect
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, text='S', startp=Point(x=0.0, y=0.0),):
        """
        Initialisation of the class.
        """
        QGraphicsItem.__init__(self)

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QColor(0, 200, 255)
        self.brush = QColor(0, 100, 255)

        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)

        self.path = QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0),
                          QFont("Arial", 10/self.sc),
                          self.text)
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def adjust(self):
        if not self.source or not self.dest:
            return

        line = QLineF(self.mapFromItem(self.source, 0, 0),
                self.mapFromItem(self.dest, 0, 0))
        length = line.length()

        self.prepareGeometryChange()

        if length > 20.0:
            edgeOffset = QPointF((line.dx() * 10) / length,
                    (line.dy() * 10) / length)

            self.sourcePoint = line.p1() + edgeOffset
            self.destPoint = line.p2() - edgeOffset
        else:
            self.sourcePoint = line.p1()
            self.destPoint = line.p1()
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def renderEdge(self, eid, einfo, points):
        scene = self.scene()

        # If we have been drawn already, get rid of it.
        gproxy = einfo.get('gproxy')
        if gproxy:
            scene.removeItem(gproxy)

        qpoints = [QtCore.QPointF(x, y) for (x, y) in points]
        qpoly = QtGui.QPolygonF(qpoints)

        ecolor = self._vg_graph.getMeta('edgecolor', '#000')
        ecolor = einfo.get('color', ecolor)

        pen = QtGui.QPen(QtGui.QColor(ecolor))
        gproxy = self.scene().addPolygon(qpoly, pen=pen)
        gproxy.setZValue(-1.0)

        einfo['gproxy'] = gproxy
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def update_geometry(self):
        self.clip_rect = QClippingPath.calculate_clipping_area(
            self.path().boundingRect(),
            self.clip_start_x,
            self.clip_width,
            self.pen().width())
        self.bounding_rect = QClippingPath.calculate_bounding_rect(
            self.path().boundingRect(),
            self.clip_start_x,
            self.clip_width,
            self.pen().width())
        if self.clip_start_x is not None:
            self.painter_offset = QtCore.QPointF(
                -1 * GraphicUnit(self.clip_start_x).value, 0)
        else:
            self.painter_offset = None
        self.prepareGeometryChange()
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def __init__(self,
                 *args,
                 origin_offset=None,
                 scale_factor=1,
                 clip_start_x=None,
                 clip_width=None,
                 **kwargs):
        """
        Args:
            origin_offset (QPointF): The offset of the glyph's origin from (0, 0)
            scale_factor (float): A hard scaling factor.
            clip_start_x (Unit or None): The local starting position for the
                clipping region. Use `None` to render from the start.
            clip_width (Unit or None): The width of the clipping region.
                Use `None` to render to the end

        All other args are passed directly to QGraphicsSimpleTextItem
        """
        super().__init__(*args, **kwargs)
        self.origin_offset = origin_offset
        self.scale_factor = scale_factor
        self.clip_start_x = clip_start_x
        self.clip_width = clip_width
        self.update_geometry()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def animate(self):
        self.angle += (math.pi / 30)
        xs = 200 * math.sin(self.angle) - 40 + 25
        ys = 200 * math.cos(self.angle) - 40 + 25
        self.m_lightSource.setPos(xs, ys)

        for item in self.m_items:
            effect = item.graphicsEffect()

            delta = QPointF(item.x() - xs, item.y() - ys)
            effect.setOffset(QPointF(delta.toPoint() / 30))

            dd = math.hypot(delta.x(), delta.y())
            color = effect.color()
            color.setAlphaF(max(0.4, min(1 - dd / 200.0, 0.7)))
            effect.setColor(color)

        self.m_scene.update()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def setPosUsingSheepDog(self, dest, sceneFence):
        self.setPos(dest)
        if sceneFence.isNull():
            return

        itemWidth = self.boundingRect().width()
        itemHeight = self.boundingRect().height()
        fenceRight = sceneFence.x() + sceneFence.width()
        fenceBottom = sceneFence.y() + sceneFence.height()

        if self.scenePos().x() < sceneFence.x():
            self.moveBy(self.mapFromScene(QPointF(sceneFence.x(), 0)).x(), 0)

        if self.scenePos().x() > fenceRight - itemWidth:
            self.moveBy(self.mapFromScene(QPointF(fenceRight - itemWidth, 0)).x(), 0)

        if self.scenePos().y() < sceneFence.y():
            self.moveBy(0, self.mapFromScene(QPointF(0, sceneFence.y())).y())

        if self.scenePos().y() > fenceBottom - itemHeight:
            self.moveBy(0, self.mapFromScene(QPointF(0, fenceBottom - itemHeight)).y())
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def setupScanItem(self):
        if Colors.useButtonBalls:
            scanItem = ScanItem(self)
            scanItem.setZValue(self.zValue() + 1)

            self.scanAnim = DemoItemAnimation(scanItem)

            x = 1.0
            y = 1.5
            stop = TextButton.BUTTON_WIDTH - scanItem.boundingRect().width() - x
            if self.alignment == TextButton.LEFT:
                self.scanAnim.setDuration(2500)
                self.scanAnim.setKeyValueAt(0.0, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.7, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(x, y))
                scanItem.setPos(QPointF(x, y))
            else:
                self.scanAnim.setKeyValueAt(0.0, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(stop, y))
                scanItem.setPos(QPointF(stop, y))
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def animate(self):
        self.angle += (math.pi / 30)
        xs = 200 * math.sin(self.angle) - 40 + 25
        ys = 200 * math.cos(self.angle) - 40 + 25
        self.m_lightSource.setPos(xs, ys)

        for item in self.m_items:
            effect = item.graphicsEffect()

            delta = QPointF(item.x() - xs, item.y() - ys)
            effect.setOffset(QPointF(delta.toPoint() / 30))

            dd = math.hypot(delta.x(), delta.y())
            color = effect.color()
            color.setAlphaF(max(0.4, min(1 - dd / 200.0, 0.7)))
            effect.setColor(color)

        self.m_scene.update()
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def setPosUsingSheepDog(self, dest, sceneFence):
        self.setPos(dest)
        if sceneFence.isNull():
            return

        itemWidth = self.boundingRect().width()
        itemHeight = self.boundingRect().height()
        fenceRight = sceneFence.x() + sceneFence.width()
        fenceBottom = sceneFence.y() + sceneFence.height()

        if self.scenePos().x() < sceneFence.x():
            self.moveBy(self.mapFromScene(QPointF(sceneFence.x(), 0)).x(), 0)

        if self.scenePos().x() > fenceRight - itemWidth:
            self.moveBy(self.mapFromScene(QPointF(fenceRight - itemWidth, 0)).x(), 0)

        if self.scenePos().y() < sceneFence.y():
            self.moveBy(0, self.mapFromScene(QPointF(0, sceneFence.y())).y())

        if self.scenePos().y() > fenceBottom - itemHeight:
            self.moveBy(0, self.mapFromScene(QPointF(0, fenceBottom - itemHeight)).y())
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def setupScanItem(self):
        if Colors.useButtonBalls:
            scanItem = ScanItem(self)
            scanItem.setZValue(self.zValue() + 1)

            self.scanAnim = DemoItemAnimation(scanItem)

            x = 1.0
            y = 1.5
            stop = TextButton.BUTTON_WIDTH - scanItem.boundingRect().width() - x
            if self.alignment == TextButton.LEFT:
                self.scanAnim.setDuration(2500)
                self.scanAnim.setKeyValueAt(0.0, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.7, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(x, y))
                scanItem.setPos(QPointF(x, y))
            else:
                self.scanAnim.setKeyValueAt(0.0, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(stop, y))
                scanItem.setPos(QPointF(stop, y))
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def _draw_video_pos(self, painter):
        if not self._api.video.current_pts:
            return
        x = self._pts_to_x(self._api.video.current_pts)
        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(get_color(self._api, 'spectrogram/video-marker'))

        width = 7
        polygon = QtGui.QPolygonF()
        for x, y in [
            (x - width / 2, 0),
            (x + width / 2, 0),
            (x + width / 2, SLIDER_SIZE),
            (x + 1, SLIDER_SIZE + width / 2),
            (x + 1, painter.viewport().height() - 1),
            (x, painter.viewport().height() - 1),
            (x, SLIDER_SIZE + width / 2),
            (x - width / 2, SLIDER_SIZE),
        ]:
            polygon.append(QtCore.QPointF(x, y))

        painter.drawPolygon(polygon)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def animate(self):
        self.angle += (math.pi / 30)
        xs = 200 * math.sin(self.angle) - 40 + 25
        ys = 200 * math.cos(self.angle) - 40 + 25
        self.m_lightSource.setPos(xs, ys)

        for item in self.m_items:
            effect = item.graphicsEffect()

            delta = QPointF(item.x() - xs, item.y() - ys)
            effect.setOffset(QPointF(delta.toPoint() / 30))

            dd = math.hypot(delta.x(), delta.y())
            color = effect.color()
            color.setAlphaF(max(0.4, min(1 - dd / 200.0, 0.7)))
            effect.setColor(color)

        self.m_scene.update()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def setPosUsingSheepDog(self, dest, sceneFence):
        self.setPos(dest)
        if sceneFence.isNull():
            return

        itemWidth = self.boundingRect().width()
        itemHeight = self.boundingRect().height()
        fenceRight = sceneFence.x() + sceneFence.width()
        fenceBottom = sceneFence.y() + sceneFence.height()

        if self.scenePos().x() < sceneFence.x():
            self.moveBy(self.mapFromScene(QPointF(sceneFence.x(), 0)).x(), 0)

        if self.scenePos().x() > fenceRight - itemWidth:
            self.moveBy(self.mapFromScene(QPointF(fenceRight - itemWidth, 0)).x(), 0)

        if self.scenePos().y() < sceneFence.y():
            self.moveBy(0, self.mapFromScene(QPointF(0, sceneFence.y())).y())

        if self.scenePos().y() > fenceBottom - itemHeight:
            self.moveBy(0, self.mapFromScene(QPointF(0, fenceBottom - itemHeight)).y())
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def setupScanItem(self):
        if Colors.useButtonBalls:
            scanItem = ScanItem(self)
            scanItem.setZValue(self.zValue() + 1)

            self.scanAnim = DemoItemAnimation(scanItem)

            x = 1.0
            y = 1.5
            stop = TextButton.BUTTON_WIDTH - scanItem.boundingRect().width() - x
            if self.alignment == TextButton.LEFT:
                self.scanAnim.setDuration(2500)
                self.scanAnim.setKeyValueAt(0.0, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(0.7, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(x, y))
                scanItem.setPos(QPointF(x, y))
            else:
                self.scanAnim.setKeyValueAt(0.0, QPointF(stop, y))
                self.scanAnim.setKeyValueAt(0.5, QPointF(x, y))
                self.scanAnim.setKeyValueAt(1.0, QPointF(stop, y))
                scanItem.setPos(QPointF(stop, y))
项目:echolocation    作者:hgross    | 项目源码 | 文件源码
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient))
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def paint(self, painter, option, widget):
        srcPoint = self.mapFromScene(self.__srcPortCircle.centerInSceneCoords())
        dstPoint = self.mapFromScene(self.__dstPortCircle.centerInSceneCoords())

        dist_between = dstPoint - srcPoint

        self.__path = QtGui.QPainterPath()
        self.__path.moveTo(srcPoint)
        self.__path.cubicTo(
            srcPoint + QtCore.QPointF(0, 0),
            dstPoint - QtCore.QPointF(0, 0),
            dstPoint
            )
        self.setPath(self.__path)
        super(Connection, self).paint(painter, option, widget)
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def getGraphPos(self):
        transform = self.transform()
        size = self.size()
        return QtCore.QPointF(transform.dx()+(size.width()*0.5), transform.dy()+(size.height()*0.5))
项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def setDragPoint(self, dragPoint):
        topLeft = QtCore.QPointF(self.__mouseDownPos)
        bottomRight = QtCore.QPointF(dragPoint)
        if dragPoint.x() < self.__mouseDownPos.x():
            topLeft.setX(dragPoint.x())
            bottomRight.setX(self.__mouseDownPos.x())
        if dragPoint.y() < self.__mouseDownPos.y():
            topLeft.setY(dragPoint.y())
            bottomRight.setY(self.__mouseDownPos.y())
        self.setPos(topLeft)
        self.resize(bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y())
项目:transpyler    作者:Transpyler    | 项目源码 | 文件源码
def to_qvector(value):
    """
    Converts a vector-like object to QPointF.
    """
    return QPointF(*value)
项目:transpyler    作者:Transpyler    | 项目源码 | 文件源码
def from_qvector(value):
    """
    Converts a QPointF to a Vec.
    """
    return Vec(value.x(), value.y())
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def scale():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    kx = window.spin_kx.value()
    sc_x = window.spin_scl_x.value()
    sc_y = window.spin_scl_y.value()
    ky = window.spin_ky.value()
    #print(kx, ky)

    scene.clear()
    epi_x = [x * kx + (1 - kx) * sc_x for x in epi_x]
    epi_y = [y * ky + (1 - ky) * sc_y for y in epi_y]
    p1 = [p1[0] * kx + (1 - kx) * sc_x, p1[1] * ky + (1 - ky) * sc_y]
    p2 = [p2[0] * kx + (1 - kx) * sc_x, p2[1] * ky + (1 - ky) * sc_y]
    p3 = [p3[0] * kx + (1 - kx) * sc_x, p3[1] * ky + (1 - ky) * sc_y]
    p4 = [p4[0] * kx + (1 - kx) * sc_x, p4[1] * ky + (1 - ky) * sc_y]
    #print(p1.x)

    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
项目:Computer-graphics    作者:Panda-Lewandowski    | 项目源码 | 文件源码
def turn():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    teta = math.radians(window.spin_deg.value())
    t_x = window.spin_turn_x.value()
    t_y = window.spin_turn_y.value()
    scene.clear()

    rect_t = QPolygonF(4)
    p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
          t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
    p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
          t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
    p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
          t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
    p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
          t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
        y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
        epi_x[i] = x1
        epi_y[i] = y1
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p)
项目:pyree-old    作者:DrLuke    | 项目源码 | 文件源码
def __init__(self, listItem:QListWidgetItem, propertiesDockWidget:QDockWidget, sendMessageCallback, data=None):
        self.sendMessageCallback = sendMessageCallback
        self.scene = QNodeScene(ModulePickerDialog(sendMessageCallback))
        self.view = QNodeView()
        self.view.setScene(self.scene)
        self.scene.setSceneRect(-2500, -2500, 5000, 5000)   # TODO: Make this less shitty
        self.listItem = listItem
        self.id = self.listItem.data(Qt.UserRole)   # Get ID from the listitem
        self.dockWidget = propertiesDockWidget

        self.availableModules = searchModules()

        self.scene.selectionChanged.connect(self.sceneSelectionChanged)

        self.sheetMap = {}  # key: sheetid, value: sheetname   special thing for subsheets so you can pick a subsheet. FIXME: Make this less special-casey

        # --- Pass scene changes
        self.sceneUndoStackIndexChangedCallback = None
        self.scene.undostack.indexChanged.connect(self.sceneUndoStackIndexChanged)

        self.workerManagerSendNodeData = None

        if data is not None:
            self.deserialize(data)
        else:
            self.initnode = InitNode()
            self.scene.addItem(self.initnode)
            self.loopnode = LoopNode()
            self.scene.addItem(self.loopnode)
            self.loopnode.setPos(QPointF(0, 100))

            self.name = self.listItem.text()
项目:pyree-old    作者:DrLuke    | 项目源码 | 文件源码
def __init__(self, iostart=None, ioend=None):
                super().__init__()

                self.setEnabled(False)  # Make it ignore events. Links can't be interacted with.

                self.iostart = iostart
                self.ioend = ioend

                if iostart is not None and ioend is not None:
                    self.update()
                else:
                    self.update(QPointF(0, 0))
项目:pyree-old    作者:DrLuke    | 项目源码 | 文件源码
def mousePressEvent(self, event):
            if event.button() == Qt.LeftButton:
                if self.iodir == "output":
                    self.newbezier = Node.io.BezierCurve(self, None)
                elif self.iodir == "input":
                    self.newbezier = Node.io.BezierCurve(None, self)

                if self.newbezier is not None:
                    self.newbezier.update(QPointF(event.pos() + self.pos() + self.parent.pos()))

                self.parent.parent.scene.addItem(self.newbezier)
            elif event.button() == Qt.RightButton:
                self.delAllBezier()
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def intersectLineGeometry(self, lineGeo, breakShape):
        """
        Try to break lineGeo with the given breakShape. Will return the intersection points of lineGeo with breakShape.
        """
        # TODO geos should be abs
        intersections = []
        line = QLineF(lineGeo.Ps.x, lineGeo.Ps.y, lineGeo.Pe.x, lineGeo.Pe.y)
        for breakGeo in breakShape.geos.abs_iter():
            if isinstance(breakGeo, LineGeo):
                breakLine = QLineF(breakGeo.Ps.x, breakGeo.Ps.y, breakGeo.Pe.x, breakGeo.Pe.y)
                intersection = QPointF(0, 0)  # values do not matter
                res = line.intersect(breakLine, intersection)
                if res == QLineF.BoundedIntersection:
                    intersections.append(Point(intersection.x(), intersection.y()))
        return intersections
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def draw_wp_zero(self):
        """
        This function is called while the drawing of all items is done. It plots
        the WPZero to the Point x=0 and y=0. This item will be enabled or
        disabled to be shown or not.
        """
        self.wpzero = WpZero(QtCore.QPointF(0, 0))
        self.addItem(self.wpzero)
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def __init__(self, sourceNode, destNode):
        super(VGraphEdge, self).__init__()

        self.arrowSize = 10.0
        self.sourcePoint = QPointF()
        self.destPoint = QPointF()

        self.setAcceptedMouseButtons(Qt.NoButton)
        self.source = sourceNode
        self.dest = destNode
        self.source.addEdge(self)
        self.dest.addEdge(self)
        self.adjust()
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def paint(self, painter, option, widget):
        if not self.source or not self.dest:
            return

        # Draw the line itself.
        line = QLineF(self.sourcePoint, self.destPoint)

        if line.length() == 0.0:
            return

        painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(line)

        # Draw the arrows if there's enough room.
        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = VGraphEdge.TwoPi - angle

        sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + VGraphEdge.Pi / 3) * self.arrowSize)
        sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize,
                                                          math.cos(angle + VGraphEdge.Pi - VGraphEdge.Pi / 3) * self.arrowSize);
        destArrowP1 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - VGraphEdge.Pi / 3) * self.arrowSize)
        destArrowP2 = self.destPoint + QPointF(math.sin(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize,
                                                      math.cos(angle - VGraphEdge.Pi + VGraphEdge.Pi / 3) * self.arrowSize)

        painter.setBrush(Qt.black)
        painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
        painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def fitScaleMetrics(self):
        """
        Scales and centers the viewport around the font’s metrics.
        """
        scrollArea = self._scrollArea
        if scrollArea:
            fitHeight = scrollArea.viewport().height()
        else:
            fitHeight = self.height()
        glyphWidth, glyphHeight = self._getGlyphWidthHeight()
        glyphHeight += self._noPointSizePadding * 2
        self.setScale(fitHeight / glyphHeight)
        self.centerOn(self.mapFromCanvas(
            QPointF(glyphWidth / 2, self._descender + self._unitsPerEm / 2)))
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def fitScaleBBox(self):
        """
        Scales and centers the viewport around the *glyph*’s bounding box.
        """
        if self._glyph is None:
            return
        if self._glyph.bounds is None:
            self.fitScaleMetrics()
            return
        scrollArea = self._scrollArea
        if scrollArea:
            viewport = scrollArea.viewport()
            fitHeight = viewport.height()
            fitWidth = viewport.width()
        else:
            fitHeight = self.height()
            fitWidth = self.width()
        left, bottom, right, top = self._glyph.bounds
        glyphHeight = top - bottom
        glyphHeight += self._noPointSizePadding * 2
        glyphWidth = right - left
        glyphWidth += self._noPointSizePadding * 2
        self.setScale(min(
            fitHeight / glyphHeight, fitWidth / glyphWidth))
        self.centerOn(self.mapFromCanvas(
            QPointF(left + (right - left) / 2, bottom + (top - bottom) / 2)))
        self.pointSizeModified.emit(self._impliedPointSize)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def mapRectFromCanvas(self, rect):
        x, y, w, h = rect.getRect()
        origin = self.mapFromCanvas(QPointF(x, y))
        w *= self._scale
        h *= self._scale
        return rect.__class__(origin.x(), origin.y() - h, w, h)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def mapRectToCanvas(self, rect):
        x, y, w, h = rect.getRect()
        origin = self.mapToCanvas(QPointF(x, y))
        w *= self._inverseScale
        h *= self._inverseScale
        return rect.__class__(origin.x(), origin.y() - h, w, h)

    # --------------------
    # Notification Support
    # --------------------
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def calculate_clip_offset(self):
        if self.clip_start_x is not None:
            main_offset = QtCore.QPointF(
                -1 * unit_to_qt_float(self.clip_start_x / self.scale_factor),
                0)
        else:
            main_offset = QtCore.QPointF(0, 0)
        return (self.origin_offset * -1) + main_offset
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def qt_point_to_point(qt_point, unit=None):
    """Create a Point from a QPoint or QPointF

    Args:
        qt_point (QPoint or QPointF): The source point
        unit (Unit): An optional unit to convert
            values to in the output `Point`. If omitted, values
            in the output `Point` will be plain `int` or `float` values.

    Returns: Point
    """
    if unit:
        return Point(qt_point.x(), qt_point.y()).to_unit(unit)
    else:
        return Point(qt_point.x(), qt_point.y())
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def point_to_qt_point_f(point):
    """Create a QPointF from a Point

    Args:
        point (Point): The source point

    Returns: QPointF
    """
    return QPointF(unit_to_qt_float(point.x), unit_to_qt_float(point.y))
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def test_pos_setter_changesqt_object(self):
        grob = MockGraphicObjectInterface(
            None, (GraphicUnit(0), GraphicUnit(0)))
        grob.pos = (GraphicUnit(10), GraphicUnit(11))
        expected = QPointF(10, 11)
        assert(grob.x == grob.pos.x)
        assert(grob.y == grob.pos.y)
        self.assertAlmostEqual(expected.x(), grob.qt_object.x())
        self.assertAlmostEqual(expected.y(), grob.qt_object.y())
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def test_x_setter_changesqt_object(self):
        grob = MockGraphicObjectInterface(
            None, (GraphicUnit(5), GraphicUnit(6)))
        grob.x = GraphicUnit(100)
        expected = QPointF(100, 6)
        self.assertAlmostEqual(expected.x(), grob.qt_object.x())
        self.assertAlmostEqual(expected.y(), grob.qt_object.y())
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def test_y_setter_changesqt_object(self):
        grob = MockGraphicObjectInterface(
            None, (GraphicUnit(5), GraphicUnit(6)))
        grob.y = GraphicUnit(100)
        expected = QPointF(5, 100)
        self.assertAlmostEqual(expected.x(), grob.qt_object.x())
        self.assertAlmostEqual(expected.y(), grob.qt_object.y())
项目:brown    作者:ajyoon    | 项目源码 | 文件源码
def test_qt_point_to_point_with_q_point_f():
    point = qt_point_to_point(QPointF(1.5, 2.5))
    assert(isinstance(point, Point))
    assert(point.x == 1.5)
    assert(point.y == 2.5)