本文整理汇总了Python中PyQt5.QtCore.QLineF.setLength方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.setLength方法的具体用法?Python QLineF.setLength怎么用?Python QLineF.setLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.setLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setWedgeGizmo
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def setWedgeGizmo(self, neighbor_virtual_helix: int,
neighbor_virtual_helix_item: GridVirtualHelixItemT):
"""Adds a WedgeGizmo to oriented toward the specified neighbor vhi.
Called by NucleicAcidPartItem _refreshVirtualHelixItemGizmos, in between
with beginAddWedgeGizmos and endAddWedgeGizmos.
Args:
neighbor_virtual_helix: the id_num of neighboring virtual helix
neighbor_virtual_helix_item:
the neighboring virtual helix item
"""
wg_dict = self.wedge_gizmos
nvhi = neighbor_virtual_helix_item
nvhi_name = nvhi.getProperty('name')
pos = self.scenePos()
line = QLineF(pos, nvhi.scenePos())
line.translate(_RADIUS, _RADIUS)
if line.length() > (_RADIUS*1.99):
color = '#5a8bff'
else:
color = '#cc0000'
nvhi_name = nvhi_name + '*' # mark as invalid
line.setLength(_RADIUS)
if neighbor_virtual_helix in wg_dict:
wedge_item = wg_dict[neighbor_virtual_helix]
else:
wedge_item = WedgeGizmo(_RADIUS, WEDGE_RECT, self)
wg_dict[neighbor_virtual_helix] = wedge_item
wedge_item.showWedge(line.angle(), color, outline_only=False)
self._added_wedge_gizmos.add(neighbor_virtual_helix)
示例2: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def moveUIPoint(contour, point, delta):
if point.segmentType is None:
# point is an offCurve. Get its sibling onCurve and the other
# offCurve.
onCurve, otherPoint = _getOffCurveSiblingPoints(contour, point)
# if the onCurve is selected, the offCurve will move along with it
if onCurve.selected:
return
point.move(delta)
if not onCurve.smooth:
contour.dirty = True
return
# if the onCurve is smooth, we need to either...
if otherPoint.segmentType is None and not otherPoint.selected:
# keep the other offCurve inline
line = QLineF(point.x, point.y, onCurve.x, onCurve.y)
otherLine = QLineF(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y)
line.setLength(line.length() + otherLine.length())
otherPoint.x = line.x2()
otherPoint.y = line.y2()
else:
# keep point in tangency with onCurve -> otherPoint segment,
# ie. do an orthogonal projection
line = QLineF(otherPoint.x, otherPoint.y, onCurve.x, onCurve.y)
n = line.normalVector()
n.translate(QPointF(point.x, point.y) - n.p1())
targetPoint = QPointF()
n.intersect(line, targetPoint)
# check that targetPoint is beyond its neighbor onCurve
# we do this by calculating position of the offCurve and second
# onCurve relative to the first onCurve. If there is no symmetry
# in at least one of the axis, then we need to clamp
onCurvePoint = line.p2()
onDistance = line.p1() - onCurvePoint
newDistance = targetPoint - onCurvePoint
if (onDistance.x() >= 0) != (newDistance.x() <= 0) or \
(onDistance.y() >= 0) != (newDistance.y() <= 0):
targetPoint = onCurvePoint
# ok, now set pos
point.x, point.y = targetPoint.x(), targetPoint.y()
else:
# point is an onCurve. Move its offCurves along with it.
index = contour.index(point)
point.move(delta)
for d in (-1, 1):
# edge-case: contour open, trailing offCurve and moving first
# onCurve in contour
if contour.open and index == 0 and d == -1:
continue
pt = contour.getPoint(index + d)
if pt.segmentType is None:
pt.move(delta)
contour.dirty = True
示例3: rotateUIPointAroundRefLine
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def rotateUIPointAroundRefLine(x1, y1, x2, y2, pt):
"""
Given three points p1, p2, pt this rotates pt around p2 such that p1,p2 and
p1,pt are collinear.
"""
line = QLineF(pt.x, pt.y, x2, y2)
p2p_l = line.length()
line.setP1(QPointF(x1, y1))
p1p2_l = line.length()
if not p1p2_l:
return
line.setLength(p1p2_l + p2p_l)
pt.x = line.x2()
pt.y = line.y2()
示例4: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def moveUIPoint(contour, point, delta):
if point.segmentType is None:
# point is an offCurve. Get its sibling onCurve and the other
# offCurve.
siblings = _getOffCurveSiblingPoints(contour, point)
# if an onCurve is selected, the offCurve will move along with it
if not siblings:
return
point.move(delta)
for onCurve, otherPoint in siblings:
if not onCurve.smooth:
continue
# if the onCurve is smooth, we need to either...
if otherPoint.segmentType is None and not otherPoint.selected:
# keep the other offCurve inline
line = QLineF(point.x, point.y, onCurve.x, onCurve.y)
otherLine = QLineF(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y)
line.setLength(line.length() + otherLine.length())
otherPoint.x = line.x2()
otherPoint.y = line.y2()
else:
# keep point in tangency with onCurve -> otherPoint segment,
# i.e. do an orthogonal projection
point.x, point.y, _ = bezierMath.lineProjection(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y,
point.x, point.y, False)
else:
# point is an onCurve. Move its offCurves along with it.
index = contour.index(point)
point.move(delta)
for d in (-1, 1):
# edge-case: contour open, trailing offCurve and moving first
# onCurve in contour
if contour.open and index == 0 and d == -1:
continue
pt = contour.getPoint(index + d)
if pt.segmentType is None:
# avoid double move for qCurve with single offCurve
if d > 0:
otherPt = contour.getPoint(index + 2 * d)
if otherPt.segmentType is not None and \
otherPt.segmentType != "move" and otherPt.selected:
continue
pt.move(delta)
maybeProjectUISmoothPointOffcurve(contour, point)
contour.dirty = True
示例5: _drawGuidelines
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def _drawGuidelines(painter, glyph, scale, rect, guidelines, drawLines=True,
drawText=True, drawSelection=True, color=None):
if not (drawLines or drawText):
return
xMin, yMin, width, height = rect
xMax = xMin + width
yMax = yMin + height
fontSize = painter.font().pointSize()
for line in guidelines:
color_ = color
if color_ is None:
if line.color:
color_ = colorToQColor(line.color)
else:
color_ = defaultColor("glyphGuideline")
painter.save()
painter.setPen(color)
line1 = None
if None not in (line.x, line.y):
if line.angle is not None:
# make an infinite line that intersects *(line.x, line.y)*
# 1. make horizontal line from *(line.x, line.y)* of length
# *diagonal*
diagonal = math.sqrt(width**2 + height**2)
line1 = QLineF(line.x, line.y, line.x + diagonal, line.y)
# 2. set the angle
# defcon guidelines are clockwise
line1.setAngle(line.angle)
# 3. reverse the line and set length to 2 * *diagonal*
line1.setPoints(line1.p2(), line1.p1())
line1.setLength(2 * diagonal)
else:
line1 = QLineF(xMin, line.y, xMax, line.y)
textX = 0
textY = 0
if drawLines:
if line1 is not None:
# line
drawLine(
painter, line1.x1(), line1.y1(), line1.x2(), line1.y2())
# point
x, y = line.x, line.y
smoothWidth = 8 * scale
smoothHalf = smoothWidth / 2.0
painter.save()
pointPath = QPainterPath()
x -= smoothHalf
y -= smoothHalf
pointPath.addEllipse(x, y, smoothWidth, smoothWidth)
pen = QPen(color_)
pen.setWidthF(1 * scale)
painter.setPen(pen)
if drawSelection and line.selected:
painter.fillPath(pointPath, color_)
painter.drawPath(pointPath)
painter.restore()
else:
if line.y is not None:
drawLine(painter, xMin, line.y, xMax, line.y)
elif line.x is not None:
drawLine(painter, line.x, yMin, line.x, yMax)
if drawText and line.name:
if line1 is not None:
textX = line.x
textY = line.y - 6 * scale
xAlign = "center"
else:
if line.y is not None:
textX = glyph.width + 6 * scale
textY = line.y - (fontSize / 3.5) * scale
elif line.x is not None:
textX = line.x + 6 * scale
textY = 0
xAlign = "left"
drawTextAtPoint(
painter, line.name, textX, textY, scale, xAlign=xAlign)
painter.restore()
示例6: showWedge
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import setLength [as 别名]
def showWedge(self, angle, color,
extended=False, rev_gradient=False, outline_only=False):
"""Summary
Args:
angle (TYPE): Description
color (TYPE): Description
extended (bool, optional): Description
rev_gradient (bool, optional): Description
outline_only (bool, optional): Description
"""
# Hack to keep wedge in front
# self.setRotation(self.pre_xover_item_group.rotation())
self._last_params = (angle, color, extended, rev_gradient, outline_only)
radius = self._radius
span = self.pre_xover_item_group.partCrossoverSpanAngle() / 2
radius_adjusted = radius + (_WEDGE_RECT_GAIN / 2)
tip = QPointF(radius_adjusted, radius_adjusted)
EXT = 1.35 if extended else 1.0
# print("wtf", tip, pos)
base_p2 = QPointF(1, 1)
line0 = QLineF(tip, QPointF(base_p2))
line1 = QLineF(tip, QPointF(base_p2))
line2 = QLineF(tip, QPointF(base_p2))
quad_scale = 1 + (.22*(span - 5) / 55) # lo+(hi-lo)*(val-min)/(max-min)
line0.setLength(radius_adjusted * EXT*quad_scale) # for quadTo control point
line1.setLength(radius_adjusted * EXT)
line2.setLength(radius_adjusted * EXT)
line0.setAngle(angle)
line1.setAngle(angle - span)
line2.setAngle(angle + span)
path = QPainterPath()
if outline_only:
self.setPen(getPenObj(color, 0.5, alpha=128, capstyle=Qt.RoundCap))
path.moveTo(line1.p2())
path.quadTo(line0.p2(), line2.p2())
else:
gradient = QRadialGradient(tip, radius_adjusted * EXT)
color1 = getColorObj(color, alpha=80)
color2 = getColorObj(color, alpha=0)
if rev_gradient:
color1, color2 = color2, color1
if extended:
gradient.setColorAt(0, color1)
gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT), color1)
gradient.setColorAt(radius_adjusted / (radius_adjusted * EXT) + 0.01, color2)
gradient.setColorAt(1, color2)
else:
gradient.setColorAt(0, getColorObj(color, alpha=50))
brush = QBrush(gradient)
self.setBrush(brush)
path.moveTo(line1.p1())
path.lineTo(line1.p2())
path.quadTo(line0.p2(), line2.p2())
path.lineTo(line2.p1())
self.setPath(path)
self.show()