Mostly working clickables.

This commit is contained in:
Christopher T. Johnson
2024-05-08 14:20:32 -04:00
parent 7d2532d775
commit f97305e36e

View File

@@ -457,30 +457,12 @@ class Definition(QWidget):
line.finalizeLine(self.width(), base)
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)
return
def resizeEvent(self, event: Optional[QResizeEvent] = None) -> None:
base = 0
for idx, line in enumerate(self._lines):
for line in self._lines:
line.finalizeLine(self.width(), base)
base += line.getLineSpacing()
self.setFixedHeight(base)
@@ -520,7 +502,6 @@ class Definition(QWidget):
painter = QPainter(self)
painter.setBrush(QBrush())
painter.setPen(QColor("white"))
red = QColor("red")
#
# 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,
@@ -529,18 +510,29 @@ class Definition(QWidget):
#
# All text on this line needs to be on the same baseline
#
buildButtons = (len(self._buttons) < 1)
assert self._lines is not None
for idx, line in enumerate(self._lines):
text = ''
for frag in line.getLine():
text += frag.text() + '_'
for line in self._lines:
line.paintEvent(painter)
green = QColor("green")
for clickRect in self._buttons:
painter.setPen(green)
painter.drawRect(clickRect['bb'])
painter.setPen(red)
bb = clickRect['frag'].layout().boundingRect()
bb.moveTo(clickRect['frag'].layout().position())
painter.drawRect(bb)
if not buildButtons:
continue
for frag in line.getLine():
for fmtRng in frag.layout().formats():
if fmtRng.format.isAnchor():
runs = frag.layout().glyphRuns(fmtRng.start,fmtRng.start+fmtRng.length)
run = runs[0]
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