本文整理汇总了Python中PyQt5.QtCore.QLineF.dy方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.dy方法的具体用法?Python QLineF.dy怎么用?Python QLineF.dy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.dy方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: timerEvent
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def timerEvent(self):
# Don't move too far away.
lineToCenter = QLineF(QPointF(0, 0), self.mapFromScene(0, 0))
if lineToCenter.length() > 150:
angleToCenter = math.acos(lineToCenter.dx() / lineToCenter.length())
if lineToCenter.dy() < 0:
angleToCenter = Mouse.TwoPi - angleToCenter;
angleToCenter = Mouse.normalizeAngle((Mouse.Pi - angleToCenter) + Mouse.Pi / 2)
if angleToCenter < Mouse.Pi and angleToCenter > Mouse.Pi / 4:
# Rotate left.
self.angle += [-0.25, 0.25][self.angle < -Mouse.Pi / 2]
elif angleToCenter >= Mouse.Pi and angleToCenter < (Mouse.Pi + Mouse.Pi / 2 + Mouse.Pi / 4):
# Rotate right.
self.angle += [-0.25, 0.25][self.angle < Mouse.Pi / 2]
elif math.sin(self.angle) < 0:
self.angle += 0.25
elif math.sin(self.angle) > 0:
self.angle -= 0.25
# Try not to crash with any other mice.
dangerMice = self.scene().items(QPolygonF([self.mapToScene(0, 0),
self.mapToScene(-30, -50),
self.mapToScene(30, -50)]))
for item in dangerMice:
if item is self:
continue
lineToMouse = QLineF(QPointF(0, 0), self.mapFromItem(item, 0, 0))
angleToMouse = math.acos(lineToMouse.dx() / lineToMouse.length())
if lineToMouse.dy() < 0:
angleToMouse = Mouse.TwoPi - angleToMouse
angleToMouse = Mouse.normalizeAngle((Mouse.Pi - angleToMouse) + Mouse.Pi / 2)
if angleToMouse >= 0 and angleToMouse < Mouse.Pi / 2:
# Rotate right.
self.angle += 0.5
elif angleToMouse <= Mouse.TwoPi and angleToMouse > (Mouse.TwoPi - Mouse.Pi / 2):
# Rotate left.
self.angle -= 0.5
# Add some random movement.
if len(dangerMice) > 1 and (qrand() % 10) == 0:
if qrand() % 1:
self.angle += (qrand() % 100) / 500.0
else:
self.angle -= (qrand() % 100) / 500.0
self.speed += (-50 + qrand() % 100) / 100.0
dx = math.sin(self.angle) * 10
self.mouseEyeDirection = 0.0 if qAbs(dx / 5) < 1 else dx / 5
self.setRotation(self.rotation() + dx)
self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
示例2: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def paint(self, painter, option, widget):
"""
Customize line adding an arrow head
:param QPainter painter: Painter instance of the item
:param option: Painter option of the item
:param widget: Widget instance
"""
if not self.source or not self.destination:
return
line = QLineF(self.source_point, self.destination_point)
if qFuzzyCompare(line.length(), 0):
return
# Draw the line itself
color = QColor()
color.setHsv(120 - 60 / self.steps_max * self.steps,
180 + 50 / self.steps_max * self.steps,
150 + 80 / self.steps_max * self.steps)
if self.highlighted:
color.setHsv(0, 0, 0)
style = self.line_style
painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin))
painter.drawLine(line)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
# Draw the arrows
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (2.0 * math.pi) - angle
# arrow in the middle of the arc
hpx = line.p1().x() + (line.dx() / 2.0)
hpy = line.p1().y() + (line.dy() / 2.0)
head_point = QPointF(hpx, hpy)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
destination_arrow_p1 = head_point + QPointF(
math.sin(angle - math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi / 3) * self.arrow_size)
destination_arrow_p2 = head_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi + math.pi / 3) * self.arrow_size)
painter.setBrush(color)
painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2]))
if self.metadata["confirmation_text"]:
painter.drawText(head_point, self.metadata["confirmation_text"])
示例3: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def paint(self, painter, option, widget):
"""
Customize line adding an arrow head
:param QPainter painter: Painter instance of the item
:param option: Painter option of the item
:param widget: Widget instance
"""
if not self.source or not self.destination:
return
line = QLineF(self.source_point, self.destination_point)
if qFuzzyCompare(line.length(), 0):
return
# Draw the line itself
color = QColor()
style = Qt.SolidLine
if self.status == ARC_STATUS_STRONG:
color.setNamedColor('blue')
if self.status == ARC_STATUS_WEAK:
color.setNamedColor('salmon')
style = Qt.DashLine
painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin))
painter.drawLine(line)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
# Draw the arrows
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (2.0 * math.pi) - angle
# arrow in the middle of the arc
hpx = line.p1().x() + (line.dx() / 2.0)
hpy = line.p1().y() + (line.dy() / 2.0)
head_point = QPointF(hpx, hpy)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
destination_arrow_p1 = head_point + QPointF(
math.sin(angle - math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi / 3) * self.arrow_size)
destination_arrow_p2 = head_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi + math.pi / 3) * self.arrow_size)
painter.setBrush(color)
painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2]))
if self.metadata["confirmation_text"]:
painter.drawText(head_point, self.metadata["confirmation_text"])
示例4: GuideLine
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
class GuideLine(Guide):
def __init__(self, line_or_point, follows=None):
super(GuideLine, self).__init__(follows)
if isinstance(line_or_point, QLineF):
self.line = line_or_point
elif follows is not None:
self.line = QLineF(self.prevGuide.endPos(), line_or_point)
else:
self.line = QLineF(QPointF(0, 0), line_or_point)
def length(self):
return self.line.length()
def startPos(self):
return QPointF(self.line.p1().x() * self.scaleX,
self.line.p1().y() * self.scaleY)
def endPos(self):
return QPointF(self.line.p2().x() * self.scaleX,
self.line.p2().y() * self.scaleY)
def guide(self, item, moveSpeed):
frame = item.guideFrame - self.startLength
endX = (self.line.p1().x() + (frame * self.line.dx() / self.length())) * self.scaleX
endY = (self.line.p1().y() + (frame * self.line.dy() / self.length())) * self.scaleY
pos = QPointF(endX, endY)
self.move(item, pos, moveSpeed)
示例5: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
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 = Edge.TwoPi - angle
sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + Edge.Pi / 3) * self.arrowSize,
math.cos(angle + Edge.Pi / 3) * self.arrowSize)
sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize,
math.cos(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize);
destArrowP1 = self.destPoint + QPointF(math.sin(angle - Edge.Pi / 3) * self.arrowSize,
math.cos(angle - Edge.Pi / 3) * self.arrowSize)
destArrowP2 = self.destPoint + QPointF(math.sin(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize,
math.cos(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize)
painter.setBrush(Qt.black)
painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
示例6: move
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def move(self, item, dest, moveSpeed):
walkLine = QLineF(item.getGuidedPos(), dest)
if moveSpeed >= 0 and walkLine.length() > moveSpeed:
# The item is too far away from it's destination point so we move
# it towards it instead.
dx = walkLine.dx()
dy = walkLine.dy()
if abs(dx) > abs(dy):
# Walk along x-axis.
if dx != 0:
d = moveSpeed * dy / abs(dx)
if dx > 0:
s = moveSpeed
else:
s = -moveSpeed
dest.setX(item.getGuidedPos().x() + s)
dest.setY(item.getGuidedPos().y() + d)
else:
# Walk along y-axis.
if dy != 0:
d = moveSpeed * dx / abs(dy)
if dy > 0:
s = moveSpeed
else:
s = -moveSpeed
dest.setX(item.getGuidedPos().x() + d)
dest.setY(item.getGuidedPos().y() + s)
item.setGuidedPos(dest)
示例7: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def paint(self, painter, option, widget):
assert self.fromSquare is not None
assert self.toSquare is not None
line = QLineF(self.sourcePoint, self.destPoint)
assert(line.length() != 0.0)
# Draw the arrows if there's enough room.
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (math.pi*2.0) - angle
destArrowP1 = self.destPoint + QPointF(
math.sin(angle - math.pi / 3) * self.arrowSize,
math.cos(angle - math.pi / 3) * self.arrowSize
)
destArrowP2 = self.destPoint + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrowSize,
math.cos(angle - math.pi + math.pi / 3) * self.arrowSize
)
painter.setPen(self.pen)
painter.setBrush(self.brush)
# arrowhead1 = QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])
arrowhead2 = QPolygonF([line.p2(), destArrowP1, destArrowP2])
painter.drawPolygon(arrowhead2)
painter.setPen(self.pen)
painter.drawLine(line)
示例8: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def paint(self, painter, option, widget=None):
"""
Public method to paint the item in local coordinates.
@param painter reference to the painter object (QPainter)
@param option style options (QStyleOptionGraphicsItem)
@param widget optional reference to the widget painted on (QWidget)
"""
if (option.state & QStyle.State_Selected) == \
QStyle.State(QStyle.State_Selected):
width = 2
else:
width = 1
# draw the line first
line = QLineF(self._origin, self._end)
painter.setPen(
QPen(Qt.black, width, Qt.SolidLine, Qt.FlatCap, Qt.MiterJoin))
painter.drawLine(line)
# draw the arrow head
arrowAngle = self._type * ArrowheadAngleFactor
slope = math.atan2(line.dy(), line.dx())
# Calculate left arrow point
arrowSlope = slope + arrowAngle
a1 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
self._end.y() - self._halfLength * math.sin(arrowSlope))
# Calculate right arrow point
arrowSlope = slope - arrowAngle
a2 = QPointF(self._end.x() - self._halfLength * math.cos(arrowSlope),
self._end.y() - self._halfLength * math.sin(arrowSlope))
if self._filled:
painter.setBrush(Qt.black)
else:
painter.setBrush(Qt.white)
polygon = QPolygonF()
polygon.append(line.p2())
polygon.append(a1)
polygon.append(a2)
painter.drawPolygon(polygon)
示例9: adjust
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
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()
示例10: angle_arrow
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
def angle_arrow(self, path, origin='head'):
''' Compute the two points of the arrow head with the right angle '''
if origin == 'tail':
path = path.toReversed()
length = path.length()
percent = path.percentAtLength(length - 10.0)
src = path.pointAtPercent(percent)
#path.moveTo(path.pointAtPercent(1))
end_point = path.pointAtPercent(1)
#end_point = path.currentPosition()
line = QLineF(src, end_point)
angle = math.acos(line.dx() / (line.length() or 1))
if line.dy() >= 0:
angle = math.pi * 2 - angle
arrow_size = 10.0
arrow_p1 = end_point + QPointF(
math.sin(angle - math.pi / 3) * arrow_size,
math.cos(angle - math.pi / 3) * arrow_size)
arrow_p2 = end_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * arrow_size,
math.cos(angle - math.pi + math.pi / 3) * arrow_size)
return (arrow_p1, arrow_p2)
示例11: calculateForces
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import dy [as 别名]
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))