label correctly follows oblique lines
This commit is contained in:
parent
069a5bfeea
commit
f3a584b8b7
|
@ -328,14 +328,25 @@ class InfLineLabel(TextItem):
|
||||||
# not in a viewbox, skip update
|
# not in a viewbox, skip update
|
||||||
return
|
return
|
||||||
|
|
||||||
# 1. determine view extents along line axis
|
lr = self.line.boundingRect()
|
||||||
tr = view.childGroup.itemTransform(self.line)[0]
|
pt1 = Point(lr.left(), 0)
|
||||||
vr = tr.mapRect(view.viewRect())
|
pt2 = Point(lr.right(), 0)
|
||||||
pt1 = Point(vr.left(), 0)
|
if self.line.angle % 90 != 0:
|
||||||
pt2 = Point(vr.right(), 0)
|
# more expensive to find text position for oblique lines.
|
||||||
|
p = QtGui.QPainterPath()
|
||||||
|
p.moveTo(pt1)
|
||||||
|
p.lineTo(pt2)
|
||||||
|
p = self.line.itemTransform(view)[0].map(p)
|
||||||
|
vr = QtGui.QPainterPath()
|
||||||
|
vr.addRect(view.boundingRect())
|
||||||
|
paths = vr.intersected(p).toSubpathPolygons()
|
||||||
|
if len(paths) > 0:
|
||||||
|
l = list(paths[0])
|
||||||
|
pt1 = self.line.mapFromItem(view, l[0])
|
||||||
|
pt2 = self.line.mapFromItem(view, l[1])
|
||||||
|
|
||||||
# 2. pick relative point between extents and set position
|
|
||||||
pt = pt2 * self.orthoPos + pt1 * (1-self.orthoPos)
|
pt = pt2 * self.orthoPos + pt1 * (1-self.orthoPos)
|
||||||
|
|
||||||
self.setPos(pt)
|
self.setPos(pt)
|
||||||
|
|
||||||
def setVisible(self, v):
|
def setVisible(self, v):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user