本文整理汇总了Python中PyQt4.QtCore.QLineF.p2方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.p2方法的具体用法?Python QLineF.p2怎么用?Python QLineF.p2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.p2方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_arrow
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def draw_arrow(self, line, width, color):
(x1, y1), (x2, y2) = line
# compute points
line = QLineF(x1, y1, x2, y2)
# If the line is very small, we make our arrowhead smaller
arrowsize = min(14, line.length())
lineangle = radians(line.angle())
arrowpt1 = line.p2() + QPointF(sin(lineangle - (pi/3)) * arrowsize, cos(lineangle - (pi/3)) * arrowsize)
arrowpt2 = line.p2() + QPointF(sin(lineangle - pi + (pi/3)) * arrowsize, cos(lineangle - pi + (pi/3)) * arrowsize)
head = QPolygonF([line.p2(), arrowpt1, arrowpt2])
# We have to draw the actual line a little short for the tip of the arrowhead not to be too wide
adjustedLine = QLineF(line)
adjustedLine.setLength(line.length() - arrowsize/2)
# draw line
painter = self.current_painter
color = COLORS[color]
painter.save()
pen = QPen(painter.pen())
pen.setColor(color)
pen.setWidthF(width)
painter.setPen(pen)
painter.drawLine(adjustedLine)
# draw arrowhead
painter.setPen(Qt.NoPen)
brush = painter.brush()
brush.setColor(color)
brush.setStyle(Qt.SolidPattern)
painter.setBrush(brush)
painter.drawPolygon(head)
painter.restore()
示例2: _updateTextAnchors
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def _updateTextAnchors(self):
n = len(self._items)
items = self._items
dist = 15
shape = reduce(QPainterPath.united, [item.path() for item in items])
brect = shape.boundingRect()
bradius = max(brect.width() / 2, brect.height() / 2)
center = self.boundingRect().center()
anchors = _category_anchors(items)
self._textanchors = []
for angle, anchor_h, anchor_v in anchors:
line = QLineF.fromPolar(bradius, angle)
ext = QLineF.fromPolar(dist, angle)
line = QLineF(line.p1(), line.p2() + ext.p2())
line = line.translated(center)
anchor_pos = line.p2()
self._textanchors.append((anchor_pos, anchor_h, anchor_v))
for i in range(n):
self._updateTextItemPos(i)
示例3: plot_vert_line_graph
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def plot_vert_line_graph(self, qp, x_line, color, c, arrow_up=False,
arrow_down=False):
if x_line < self._start_date or x_line > self._end_date:
return
x_line -= self._start_date
qp.save()
qp.setPen(color)
qp.setBrush(color)
qp.setRenderHint(QPainter.Antialiasing)
arrowSize = 2.0
x, y = self.origGraph(c)
line = QLineF(x + self.convX(x_line), y + 10, x + self.convX(x_line),
y + 50)
qp.drawLine(line)
if arrow_up:
arrowP1 = line.p1() + QPointF(arrowSize, arrowSize * 3)
arrowP2 = line.p1() + QPointF(-arrowSize, arrowSize * 3)
qp.drawLine(line.p1(), arrowP1)
qp.drawLine(line.p1(), arrowP2)
if arrow_down:
arrowP1 = line.p2() + QPointF(arrowSize, - arrowSize * 3)
arrowP2 = line.p2() + QPointF(-arrowSize, - arrowSize * 3)
qp.drawLine(line.p2(), arrowP1)
qp.drawLine(line.p2(), arrowP2)
qp.restore()
示例4: setLine
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def setLine(self, line):
"""
Set the arrow base line (a `QLineF` in object coordinates).
"""
if self.__line != line:
self.__line = line
# local item coordinate system
geom = self.geometry().translated(-self.pos())
if geom.isNull() and not line.isNull():
geom = QRectF(0, 0, 1, 1)
arrow_shape = arrow_path_concave(line, self.lineWidth())
arrow_rect = arrow_shape.boundingRect()
if not (geom.contains(arrow_rect)):
geom = geom.united(arrow_rect)
if self.__autoAdjustGeometry:
# Shrink the geometry if required.
geom = geom.intersected(arrow_rect)
# topLeft can move changing the local coordinates.
diff = geom.topLeft()
line = QLineF(line.p1() - diff, line.p2() - diff)
self.__arrowItem.setLine(line)
self.__line = line
# parent item coordinate system
geom.translate(self.pos())
self.setGeometry(geom)
示例5: arrow_path_concave
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def arrow_path_concave(line, width):
"""
Return a :class:`QPainterPath` of a pretty looking arrow.
"""
path = QPainterPath()
p1, p2 = line.p1(), line.p2()
if p1 == p2:
return path
baseline = QLineF(line)
# Require some minimum length.
baseline.setLength(max(line.length() - width * 3, width * 3))
start, end = baseline.p1(), baseline.p2()
mid = (start + end) / 2.0
normal = QLineF.fromPolar(1.0, baseline.angle() + 90).p2()
path.moveTo(start)
path.lineTo(start + (normal * width / 4.0))
path.quadTo(mid + (normal * width / 4.0),
end + (normal * width / 1.5))
path.lineTo(end - (normal * width / 1.5))
path.quadTo(mid - (normal * width / 4.0),
start - (normal * width / 4.0))
path.closeSubpath()
arrow_head_len = width * 4
arrow_head_angle = 50
line_angle = line.angle() - 180
angle_1 = line_angle - arrow_head_angle / 2.0
angle_2 = line_angle + arrow_head_angle / 2.0
points = [p2,
p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
baseline.p2(),
p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(),
p2]
poly = QPolygonF(points)
path_head = QPainterPath()
path_head.addPolygon(poly)
path = path.united(path_head)
return path
示例6: paintArc
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def paintArc(self, painter, option, widget):
assert self.source is self.dest
node = self.source
def best_angle():
"""...is the one furthest away from all other angles"""
angles = [
QLineF(node.pos(), other.pos()).angle()
for other in chain(
(edge.source for edge in node.edges if edge.dest == node and edge.source != node),
(edge.dest for edge in node.edges if edge.dest != node and edge.source == node),
)
]
angles.sort()
if not angles: # If this self-constraint is the only edge
return 225
deltas = np.array(angles[1:] + [360 + angles[0]]) - angles
return (angles[deltas.argmax()] + deltas.max() / 2) % 360
angle = best_angle()
inf = QPointF(-1e20, -1e20) # Doesn't work with real -np.inf!
line0 = QLineF(node.pos(), inf)
line1 = QLineF(node.pos(), inf)
line2 = QLineF(node.pos(), inf)
line0.setAngle(angle)
line1.setAngle(angle - 13)
line2.setAngle(angle + 13)
p0 = shape_line_intersection(node.shape(), node.pos(), line0)
p1 = shape_line_intersection(node.shape(), node.pos(), line1)
p2 = shape_line_intersection(node.shape(), node.pos(), line2)
path = QtGui.QPainterPath()
path.moveTo(p1)
line = QLineF(node.pos(), p0)
line.setLength(3 * line.length())
pt = line.p2()
path.quadTo(pt, p2)
line = QLineF(node.pos(), pt)
self.setLine(line) # This invalidates DeviceCoordinateCache
painter.drawPath(path)
# Draw arrow head
line = QLineF(pt, p2)
self.arrowHead.clear()
for point in self._arrowhead_points(line):
self.arrowHead.append(point)
painter.setBrush(self.pen().color())
painter.drawPolygon(self.arrowHead)
# Update label position
self.label.setPos(path.pointAtPercent(0.5))
if 90 < angle < 270: # Right-align the label
pos = self.label.pos()
x, y = pos.x(), pos.y()
self.label.setPos(x - self.label.boundingRect().width(), y)
self.squares.placeBelow(self.label)
示例7: drawPath
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def drawPath(self, startPoint, endPoint):
path = QPainterPath()
one = (QPointF(endPoint.x(), startPoint.y()) + startPoint) / 2
two = (QPointF(startPoint.x(), endPoint.y()) + endPoint) / 2
path.moveTo(startPoint)
if startPoint.x() > endPoint.x():
dist = (startPoint.x() - endPoint.x()) * 2
tLine = QLineF((dist / 2), 0.0, -(dist / 2), 0.0).translated(QLineF(startPoint, endPoint).pointAt(0.5))
one = tLine.p1()
two = tLine.p2()
path.cubicTo(one, two, endPoint)
self.__path = path
return path, QLineF(one, two)
示例8: arrow_path_plain
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def arrow_path_plain(line, width):
"""
Return an :class:`QPainterPath` of a plain looking arrow.
"""
path = QPainterPath()
p1, p2 = line.p1(), line.p2()
if p1 == p2:
return path
baseline = QLineF(line)
# Require some minimum length.
baseline.setLength(max(line.length() - width * 3, width * 3))
path.moveTo(baseline.p1())
path.lineTo(baseline.p2())
stroker = QPainterPathStroker()
stroker.setWidth(width)
path = stroker.createStroke(path)
arrow_head_len = width * 4
arrow_head_angle = 50
line_angle = line.angle() - 180
angle_1 = line_angle - arrow_head_angle / 2.0
angle_2 = line_angle + arrow_head_angle / 2.0
points = [
p2,
p2 + QLineF.fromPolar(arrow_head_len, angle_1).p2(),
p2 + QLineF.fromPolar(arrow_head_len, angle_2).p2(),
p2,
]
poly = QPolygonF(points)
path_head = QPainterPath()
path_head.addPolygon(poly)
path = path.united(path_head)
return path
示例9: adjustGeometry
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def adjustGeometry(self):
"""
Adjust the widget geometry to exactly fit the arrow inside
while preserving the arrow path scene geometry.
"""
# local system coordinate
geom = self.geometry().translated(-self.pos())
line = self.__line
arrow_rect = self.__arrowItem.shape().boundingRect()
if geom.isNull() and not line.isNull():
geom = QRectF(0, 0, 1, 1)
if not (geom.contains(arrow_rect)):
geom = geom.united(arrow_rect)
geom = geom.intersected(arrow_rect)
diff = geom.topLeft()
line = QLineF(line.p1() - diff, line.p2() - diff)
geom.translate(self.pos())
self.setGeometry(geom)
self.setLine(line)
示例10: ControlPointLine
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
class ControlPointLine(QGraphicsObject):
lineChanged = Signal(QLineF)
lineEdited = Signal(QLineF)
def __init__(self, parent=None, **kwargs):
QGraphicsObject.__init__(self, parent, **kwargs)
self.setFlag(QGraphicsItem.ItemHasNoContents)
self.setFlag(QGraphicsItem.ItemIsFocusable)
self.__line = QLineF()
self.__points = \
[ControlPoint(self, ControlPoint.TopLeft), # TopLeft is line start
ControlPoint(self, ControlPoint.BottomRight) # line end
]
self.__activeControl = None
if self.scene():
self.__installFilter()
for p in self.__points:
p.setFlag(QGraphicsItem.ItemIsFocusable)
p.setFocusProxy(self)
def setLine(self, line):
if not isinstance(line, QLineF):
raise TypeError()
if line != self.__line:
self.__line = line
self.__pointsLayout()
self.lineChanged.emit(line)
def line(self):
return self.__line
def isControlActive(self):
"""Return the state of the control. True if the control is
active (user is dragging one of the points) False otherwise.
"""
return self.__activeControl is not None
def __installFilter(self):
for p in self.__points:
p.installSceneEventFilter(self)
def itemChange(self, change, value):
if change == QGraphicsItem.ItemSceneHasChanged:
if self.scene():
self.__installFilter()
return QGraphicsObject.itemChange(self, change, value)
def sceneEventFilter(self, obj, event):
try:
obj = toGraphicsObjectIfPossible(obj)
if isinstance(obj, ControlPoint):
etype = event.type()
if etype == QEvent.GraphicsSceneMousePress:
self.__setActiveControl(obj)
elif etype == QEvent.GraphicsSceneMouseRelease:
self.__setActiveControl(None)
return QGraphicsObject.sceneEventFilter(self, obj, event)
except Exception:
log.error("", exc_info=True)
def __pointsLayout(self):
self.__points[0].setPos(self.__line.p1())
self.__points[1].setPos(self.__line.p2())
def __setActiveControl(self, control):
if self.__activeControl != control:
if self.__activeControl is not None:
self.__activeControl.positionChanged[QPointF].disconnect(
self.__activeControlMoved
)
self.__activeControl = control
if control is not None:
control.positionChanged[QPointF].connect(
self.__activeControlMoved
)
def __activeControlMoved(self, pos):
line = QLineF(self.__line)
control = self.__activeControl
if control.anchor() == ControlPoint.TopLeft:
line.setP1(pos)
elif control.anchor() == ControlPoint.BottomRight:
line.setP2(pos)
if self.__line != line:
self.blockSignals(True)
self.setLine(line)
self.blockSignals(False)
self.lineEdited.emit(line)
#.........这里部分代码省略.........
示例11: EEdge
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
class EEdge(QGraphicsObject):
def __init__(self, head, tail, uuid):
QGraphicsObject.__init__(self)
if not issubclass(head.__class__, dict) and not isinstance(tail.__class__, dict):
raise AttributeError
self.setZValue(0.0)
self.__kId = uuid
self.__head = head
self.__tail = tail
if head[ENode.kGuiAttributeType].match(EAttribute.kTypeInput):
self.__head = tail
self.__tail = head
self.__head[ENode.kGuiAttributeParent].onMove.connect(self.update)
self.__tail[ENode.kGuiAttributeParent].onMove.connect(self.update)
self.__headPoint = QPointF(0.0, 0.0)
self.__tailPoint = QPointF(0.0, 0.0)
self.__pen = QPen(QColor(43, 43, 43), 2, Qt.SolidLine)
self.update()
@property
def Id(self):
return self.__kId
@property
def Head(self):
return self.__head
@property
def Tail(self):
return self.__tail
def pen(self):
return self.__pen
def setPen(self, pen):
if not isinstance(pen, QPen):
raise AttributeError
self.__pen = pen
def update(self):
QGraphicsObject.prepareGeometryChange(self)
self.__headPoint = self.mapFromItem(self.__head[ENode.kGuiAttributeParent],
self.__head[ENode.kGuiAttributePlug])
self.__tailPoint = self.mapFromItem(self.__tail[ENode.kGuiAttributeParent],
self.__tail[ENode.kGuiAttributePlug])
self.__headOffsetLine = QLineF(self.__headPoint, QPointF(self.__headPoint.x() + 15, self.__headPoint.y()))
self.__tailOffsetLine = QLineF(self.__tailPoint, QPointF(self.__tailPoint.x() - 15, self.__tailPoint.y()))
line = QLineF(self.__headPoint, self.__tailPoint)
self.__line = line
def boundingRect(self):
extra = (self.pen().width() * 64) / 2
return QRectF(self.__line.p1(),
QSizeF(self.__line.p2().x() - self.__line.p1().x(),
self.__line.p2().y() - self.__line.p1().y())).normalized().adjusted(-extra,
-extra,
extra,
extra)
def shape(self):
return QGraphicsObject.shape(self)
def drawPath(self, startPoint, endPoint):
path = QPainterPath()
one = (QPointF(endPoint.x(), startPoint.y()) + startPoint) / 2
two = (QPointF(startPoint.x(), endPoint.y()) + endPoint) / 2
path.moveTo(startPoint)
angle = math.pi / 2
bLine1 = QLineF()
bLine1.setP1(startPoint)
if startPoint.x() > endPoint.x():
dist = startPoint.x() - endPoint.x()
one = (bLine1.p1() + QPointF(math.sin(angle) * dist, math.cos(angle) * dist))
bLine1.setP1(endPoint)
two = (bLine1.p1() + QPointF(math.sin(angle) * dist, math.cos(angle) * dist))
path.cubicTo(one, two, endPoint)
return path, QLineF(one, two)
def paint(self, painter, option, widget=None):
painter.setPen(self.pen())
#.........这里部分代码省略.........
示例12: SliderLine
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
#.........这里部分代码省略.........
self._pen = QPen()
super().__init__(parent, **kwargs)
self.setAcceptedMouseButtons(Qt.LeftButton)
self.setPen(make_pen(brush=QColor(50, 50, 50), width=1, cosmetic=True))
if self._orientation == Qt.Vertical:
self.setCursor(Qt.SizeVerCursor)
else:
self.setCursor(Qt.SizeHorCursor)
def setPen(self, pen):
pen = QPen(pen)
if self._pen != pen:
self.prepareGeometryChange()
self._pen = pen
self._line = None
self.update()
def pen(self):
return QPen(self._pen)
def setValue(self, value):
value = min(max(value, self._min), self._max)
if self._value != value:
self.prepareGeometryChange()
self._value = value
self._line = None
self.valueChanged.emit(value)
def value(self):
return self._value
def setRange(self, minval, maxval):
maxval = max(minval, maxval)
if minval != self._min or maxval != self._max:
self._min = minval
self._max = maxval
self.rangeChanged.emit(minval, maxval)
self.setValue(self._value)
def setLength(self, length):
if self._length != length:
self.prepareGeometryChange()
self._length = length
self._line = None
def length(self):
return self._length
def setOrientation(self, orientation):
if self._orientation != orientation:
self.prepareGeometryChange()
self._orientation = orientation
self._line = None
if self._orientation == Qt.Vertical:
self.setCursor(Qt.SizeVerCursor)
else:
self.setCursor(Qt.SizeHorCursor)
def mousePressEvent(self, event):
event.accept()
self.linePressed.emit()
def mouseMoveEvent(self, event):
pos = event.pos()
if self._orientation == Qt.Vertical:
self.setValue(pos.y())
else:
self.setValue(pos.x())
self.lineMoved.emit()
event.accept()
def mouseReleaseEvent(self, event):
if self._orientation == Qt.Vertical:
self.setValue(event.pos().y())
else:
self.setValue(event.pos().x())
self.lineReleased.emit()
event.accept()
def boundingRect(self):
if self._line is None:
if self._orientation == Qt.Vertical:
self._line = QLineF(0, self._value, self._length, self._value)
else:
self._line = QLineF(self._value, 0, self._value, self._length)
r = QRectF(self._line.p1(), self._line.p2())
penw = self.pen().width()
return r.adjusted(-penw, -penw, penw, penw)
def paint(self, painter, *args):
if self._line is None:
self.boundingRect()
painter.save()
painter.setPen(self.pen())
painter.drawLine(self._line)
painter.restore()
示例13: EEdge
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
class EEdge(QGraphicsObject):
def __init__(self, head, tail, uuid, arrowed=False):
QGraphicsObject.__init__(self)
self.__arrowed = arrowed
if not issubclass(head.__class__, dict) and not isinstance(tail.__class__, dict):
raise AttributeError
self.setZValue(0.0)
self.__kId = uuid
self.__head = head
self.__tail = tail
self.__path = QPainterPath()
self.__headPoint = QPointF(0.0, 0.0)
self.__tailPoint = QPointF(0.0, 0.0)
self.__head[ENode.kGuiAttributeParent].onMove.connect(self.update)
self.__tail[ENode.kGuiAttributeParent].onMove.connect(self.update)
self.__pen = QPen(QColor(43, 43, 43), 2, Qt.SolidLine)
self.update()
@property
def Id(self):
return self.__kId
@property
def Line(self):
return QLineF(self.__headPoint, self.__tailPoint)
@property
def Head(self):
return self.__head
@Head.setter
def Head(self, newHead):
self.__head = newHead
@property
def Tail(self):
return self.__tail
@Tail.setter
def Tail(self, newTail):
self.__tail = newTail
def pen(self):
return self.__pen
def setPen(self, pen):
if not isinstance(pen, QPen):
raise AttributeError
self.__pen = pen
def update(self):
QGraphicsObject.prepareGeometryChange(self)
self.__headPoint = self.mapFromItem(self.__head[ENode.kGuiAttributeParent],
self.__head[ENode.kGuiAttributePlug])
self.__tailPoint = self.mapFromItem(self.__tail[ENode.kGuiAttributeParent],
self.__tail[ENode.kGuiAttributePlug])
self.__headOffsetLine = QLineF(self.__headPoint, QPointF(self.__headPoint.x() + 15, self.__headPoint.y()))
self.__tailOffsetLine = QLineF(self.__tailPoint, QPointF(self.__tailPoint.x() - 15, self.__tailPoint.y()))
line = QLineF(self.__headPoint, self.__tailPoint)
self.__line = line
def boundingRect(self):
extra = (self.pen().width() * 64) / 2
return QRectF(self.__line.p1(),
QSizeF(self.__line.p2().x() - self.__line.p1().x(),
self.__line.p2().y() - self.__line.p1().y())).normalized().adjusted(-extra,
-extra,
extra,
extra)
def shape(self):
if self.__arrowed:
return QGraphicsObject.shape(self)
return QPainterPath(self.__path)
def getIntersectPoint(self, polygon, point1, point2):
p1 = polygon[0] + point1
intersectPoint = QPointF()
for i in polygon:
p2 = i + point2
polyLine = QLineF(p1, p2)
intersectType = polyLine.intersect(QLineF(point1, point2), intersectPoint)
#.........这里部分代码省略.........
示例14: crop_line
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
def crop_line(self, line, line_point):
global_rect = self.globalBoundingRect()
# Go to local coordinate system - ellipse equations assume ellipse is centered on (0,0)
local_trans = global_rect.center()
local_line = QLineF(line.p1() - local_trans, line.p2() - local_trans)
if(local_line.dx() == 0):
return line
# Solve line equation
e_a = ((local_line.p2().y() - local_line.p1().y()) /
(local_line.p2().x() - local_line.p1().x()))
e_b = local_line.p1().y() - e_a * local_line.p1().x()
# ellipse params
e_c = global_rect.width()/2
e_d = global_rect.height()/2
# check condition
if(e_c * e_d == 0):
return line
# precalculate things that are used more than once
# a^2, b^2 ...
ak = math.pow(e_a, 2)
bk = math.pow(e_b, 2)
ck = math.pow(e_c, 2)
dk = math.pow(e_d, 2)
# check another condition
if((ak * ck + dk) == 0):
return line
# a^2*c^2, c^2*d^2
akck = ak * ck
ckdk = ck * dk
# a*b*c^2
abck = e_a*e_b*ck
# parts of denomiator and numerator of x
denom = (akck + dk)
numer = math.sqrt(ck*dk*(akck-bk+dk))
# Decide which points to take
xrel = (line.p1().x() > line.p2().x())
yrel = (line.p1().y() > line.p2().y())
if(line_point != 0):
xrel = not xrel
yrel = not yrel
if((xrel and yrel) or (xrel and not yrel)):
x1 = (-numer - abck) / denom
y1 = (e_b*dk - e_a*math.sqrt(-ckdk*(-akck+bk-dk))) / denom
intersectionPoint = QPointF(x1, y1)
elif((not xrel and yrel) or (not xrel and not yrel)):
x2 = (numer - abck) / denom
y2 = -(e_b*dk - e_a*math.sqrt(-ckdk*(-akck+bk-dk))) / denom
intersectionPoint = QPointF(x2, y2)
# Go back to global coordinate system
intersectionPoint = intersectionPoint + local_trans
if(line_point == 0):
return QLineF(intersectionPoint, line.p2())
else:
return QLineF(line.p1(), intersectionPoint)
return line
示例15: EDummy
# 需要导入模块: from PyQt4.QtCore import QLineF [as 别名]
# 或者: from PyQt4.QtCore.QLineF import p2 [as 别名]
class EDummy(QGraphicsObject):
onEditEnd = pyqtSignal(QLineF)
onPress = pyqtSignal()
def __init__(self):
QGraphicsObject.__init__(self)
self.__uuid = uuid.uuid1()
#self.setZValue(-0.5)
self.__polygon = EDraw.Circle(7, 12)
self.__isSnapMode = False
self.__snapPoint = QPointF(0.0, 0.0)
self.__gridSize = 10
self.__dummyLine = QLineF()
self.__dummyData = None
self.__editPointOne = None
self.__BBTemp = None
self.__angle = 0.0
def isEditMode(self):
if self.__editPointOne:
return True
return False
def toggleEditMode(self):
if self.__editPointOne is None:
self.__editPointOne = self.scenePos()
self.__BBTemp = self.scenePos()
self.setZValue(2.0)
self.update()
return
self.setZValue(-0.5)
self.onEditEnd.emit(QLineF(self.__editPointOne, self.scenePos()))
self.__editPointOne = None
self.__BBTemp = None
self.update()
def setSnapMode(self, snapMode):
self.__isSnapMode = snapMode
def setGridSize(self, gridSize):
self.__gridSize = gridSize
def setDummyData(self, dummyData):
self.__dummyData = dummyData
def getDummyData(self):
return self.__dummyData
@property
def Id(self):
return self.__uuid
@property
def Position(self):
if self.__isSnapMode:
return self.__snapPoint / self.__gridSize
return self.scenePos() / self.__gridSize
@property
def Angle(self):
return self.__angle
def boundingRect(self):
tempPoint = self.__snapPoint
if self.__BBTemp is not None:
tempPoint = self.__BBTemp
radius = math.sqrt((self.scenePos().x() - tempPoint.x()) ** 2 + (self.scenePos().y() - tempPoint.y()) ** 2)
return EDraw.Circle(radius + self.__gridSize / 2, 8).boundingRect().normalized().adjusted(-5, -5, 5, 5)
def shape(self):
path = QGraphicsItem.shape(self)
return path
def polygon(self):
return self.__polygon
def debug(self):
return self.__dummyLine.p2()
def dummyLine(self, angle=None, length=None):
if angle is not None and length is not None:
pt1 = QLineF(QPointF(0.0, 0.0), QPointF(0.0, 1.0))
pt1.setAngle(angle)
pt1.setLength(length + 16)
self.__dummyLine = pt1
return
#.........这里部分代码省略.........