本文整理汇总了Python中PyQt5.QtCore.QLineF.y2方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.y2方法的具体用法?Python QLineF.y2怎么用?Python QLineF.y2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.y2方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import y2 [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
示例2: rotateUIPointAroundRefLine
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import y2 [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()
示例3: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import y2 [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
示例4: _drawGuidelines
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import y2 [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()