Mostly working clickables.
This commit is contained in:
@@ -457,30 +457,12 @@ class Definition(QWidget):
|
|||||||
line.finalizeLine(self.width(), base)
|
line.finalizeLine(self.width(), base)
|
||||||
base += line.getLineSpacing()
|
base += line.getLineSpacing()
|
||||||
|
|
||||||
for line in self._lines:
|
|
||||||
for frag in line.getLine():
|
|
||||||
layout = frag.layout()
|
|
||||||
for fmtRng in layout.formats():
|
|
||||||
if fmtRng.format.isAnchor():
|
|
||||||
runs = layout.glyphRuns(fmtRng.start, fmtRng.length)
|
|
||||||
bb = runs[0].boundingRect()
|
|
||||||
pos = layout.position()
|
|
||||||
text = frag.text()[fmtRng.start:fmtRng.start + fmtRng.length]
|
|
||||||
new = bb.topLeft() + pos
|
|
||||||
print(f"({bb.left()}, {bb.top()}), ({pos.x()}, {pos.y()}), ({new.x()}, {new.y()}): {text}")
|
|
||||||
bb.moveTo(bb.topLeft() + pos)
|
|
||||||
self._buttons.append(
|
|
||||||
{'bb': bb,
|
|
||||||
'fmt': fmtRng.format,
|
|
||||||
'frag': frag,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
self.setFixedHeight(base)
|
self.setFixedHeight(base)
|
||||||
return
|
return
|
||||||
|
|
||||||
def resizeEvent(self, event: Optional[QResizeEvent] = None) -> None:
|
def resizeEvent(self, event: Optional[QResizeEvent] = None) -> None:
|
||||||
base = 0
|
base = 0
|
||||||
for idx, line in enumerate(self._lines):
|
for line in self._lines:
|
||||||
line.finalizeLine(self.width(), base)
|
line.finalizeLine(self.width(), base)
|
||||||
base += line.getLineSpacing()
|
base += line.getLineSpacing()
|
||||||
self.setFixedHeight(base)
|
self.setFixedHeight(base)
|
||||||
@@ -520,7 +502,6 @@ class Definition(QWidget):
|
|||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
painter.setBrush(QBrush())
|
painter.setBrush(QBrush())
|
||||||
painter.setPen(QColor("white"))
|
painter.setPen(QColor("white"))
|
||||||
red = QColor("red")
|
|
||||||
#
|
#
|
||||||
# Each line needs a base calculated. To do that, we need to find the
|
# Each line needs a base calculated. To do that, we need to find the
|
||||||
# bounding rectangle of the text. Once we have the bounding rectangle,
|
# bounding rectangle of the text. Once we have the bounding rectangle,
|
||||||
@@ -529,18 +510,29 @@ class Definition(QWidget):
|
|||||||
#
|
#
|
||||||
# All text on this line needs to be on the same baseline
|
# All text on this line needs to be on the same baseline
|
||||||
#
|
#
|
||||||
|
buildButtons = (len(self._buttons) < 1)
|
||||||
|
|
||||||
assert self._lines is not None
|
assert self._lines is not None
|
||||||
for idx, line in enumerate(self._lines):
|
for line in self._lines:
|
||||||
text = ''
|
|
||||||
for frag in line.getLine():
|
|
||||||
text += frag.text() + '_'
|
|
||||||
line.paintEvent(painter)
|
line.paintEvent(painter)
|
||||||
green = QColor("green")
|
if not buildButtons:
|
||||||
for clickRect in self._buttons:
|
continue
|
||||||
painter.setPen(green)
|
for frag in line.getLine():
|
||||||
painter.drawRect(clickRect['bb'])
|
for fmtRng in frag.layout().formats():
|
||||||
painter.setPen(red)
|
if fmtRng.format.isAnchor():
|
||||||
bb = clickRect['frag'].layout().boundingRect()
|
runs = frag.layout().glyphRuns(fmtRng.start,fmtRng.start+fmtRng.length)
|
||||||
bb.moveTo(clickRect['frag'].layout().position())
|
run = runs[0]
|
||||||
painter.drawRect(bb)
|
bb = run.boundingRect()
|
||||||
|
bb.moveTo(bb.topLeft() + frag.layout().position())
|
||||||
|
self._buttons.append(
|
||||||
|
{
|
||||||
|
'bb': bb,
|
||||||
|
'frag': frag,
|
||||||
|
'fmt': fmtRng.format,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
painter.setPen(QColor("cyan"))
|
||||||
|
for click in self._buttons:
|
||||||
|
if click['fmt'].isAnchor():
|
||||||
|
painter.drawRect(click['bb'])
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user