cleanup
This commit is contained in:
@@ -315,43 +315,6 @@ class BiggerText(QWidget):
|
||||
elided_text = elided_text[0:-1] if elided_text.endswith('…') else elided_text # remove the trailing '…'
|
||||
return elided_text
|
||||
|
||||
def to_byte_offset_old(self, pos: QPoint) -> (int, int, str):
|
||||
line_number = self.y_pos_to_line_number_on_screen(pos.y())
|
||||
|
||||
w = self.font_metric.horizontalAdvanceChar('…')
|
||||
line = self.lines_to_render[line_number]
|
||||
text: str = line.text()
|
||||
text = text.replace("\n", "").replace("\r", "")
|
||||
elidedText = self.font_metric.elidedText(text + "………", Qt.TextElideMode.ElideRight, pos.x() + w,
|
||||
Qt.TextFlag.TextWrapAnywhere)
|
||||
elidedText = elidedText[0:-1] if elidedText.endswith('…') else elidedText # remove the trailing '…'
|
||||
byte = line.byte_offset() + len(elidedText.encode("utf8"))
|
||||
|
||||
print(
|
||||
f"line: {line_number} elidetText: '{elidedText}' byte: {byte} char_in_line: {len(elidedText)}")
|
||||
return byte, len(elidedText), elidedText
|
||||
|
||||
def _text_left_of_pos(x: int, text: str, font_metric: QFontMetrics):
|
||||
w = font_metric.horizontalAdvanceChar('…')
|
||||
elidedText = font_metric.elidedText(text, Qt.TextElideMode.ElideRight, x + w,
|
||||
Qt.TextFlag.TextWrapAnywhere)
|
||||
elidedText = elidedText[0:-1] if elidedText.endswith('…') else elidedText # remove the trailing '…'
|
||||
|
||||
bounding_box_elided = font_metric.horizontalAdvance(elidedText)
|
||||
|
||||
if len(elidedText) + 1 < len(text): # there is a next character
|
||||
elidet_text_plus_one_char = text[0:len(elidedText) + 1]
|
||||
# print(f"elidet_text_plus_one_char: {elidet_text_plus_one_char}")
|
||||
bounding_box_elided_plus_one = font_metric.horizontalAdvance(elidet_text_plus_one_char)
|
||||
diff = bounding_box_elided_plus_one - bounding_box_elided.width()
|
||||
|
||||
if bounding_box_elided + diff / 2 >= x:
|
||||
return elidet_text_plus_one_char
|
||||
else:
|
||||
return elidedText
|
||||
|
||||
return elidedText
|
||||
|
||||
def y_pos_to_line_number_on_screen(self, y: int) -> int:
|
||||
return int(y / self.char_height)
|
||||
|
||||
@@ -363,13 +326,7 @@ class BiggerText(QWidget):
|
||||
painter.setFont(font)
|
||||
|
||||
# ---
|
||||
|
||||
#painter.drawLine(QLine(273, 0, 273, self.height()))
|
||||
# ---
|
||||
|
||||
# ----
|
||||
|
||||
self.font_metric: QFontMetrics = painter.fontMetrics()
|
||||
self.font_metric = painter.fontMetrics()
|
||||
self.char_height = self.font_metric.height()
|
||||
lines_to_read = self.height() / self.char_height + 1
|
||||
|
||||
@@ -377,60 +334,6 @@ class BiggerText(QWidget):
|
||||
|
||||
painter.setPen(QColor(0, 0, 0))
|
||||
|
||||
if False:
|
||||
line_on_screen = 0
|
||||
for line in self.lines_to_render:
|
||||
text = line.text()
|
||||
text = text.replace("\n", "").replace("\r", "")
|
||||
|
||||
start = 0
|
||||
end = 1
|
||||
|
||||
if start < len(text) and end <= len(text):
|
||||
x_start = self.font_metric.horizontalAdvance(text[0:start])
|
||||
# x_width = self.font_metric.horizontalAdvance(text[start:end])
|
||||
x_width = self.font_metric.boundingRect(text[start:end]).width()
|
||||
elidet_text = self.font_metric.elidedText(text, Qt.TextElideMode.ElideNone, 50,
|
||||
Qt.TextFlag.TextWrapAnywhere)
|
||||
# x_width = self.font_metric.boundingRect(elidet_text).width()
|
||||
print(f"-> {text[start:end]} width: {x_width} elidet_text: {elidet_text}")
|
||||
|
||||
y = int(line_on_screen * self.char_height)
|
||||
painter.setBrush(QBrush(QColor(233, 133, 233)))
|
||||
painter.drawRect(QRect(x_start, y, x_width, self.char_height))
|
||||
line_on_screen = line_on_screen + 1
|
||||
|
||||
if False:
|
||||
line_on_screen = 0
|
||||
for line in self.lines_to_render:
|
||||
text = line.text()
|
||||
text = text.replace("\n", "").replace("\r", "")
|
||||
r = self.font_metric.boundingRect(text[0:1])
|
||||
|
||||
w = self.font_metric.horizontalAdvanceChar('…')
|
||||
|
||||
xpos = r.x() + r.width() + w + 1
|
||||
|
||||
elidet_text = self.font_metric.elidedText(text, Qt.TextElideMode.ElideRight, xpos)
|
||||
|
||||
print(f"-> {elidet_text} -- {text}")
|
||||
|
||||
y = int(line_on_screen * self.char_height)
|
||||
painter.setBrush(QBrush(QColor(233, 233, 233)))
|
||||
painter.drawRect(QRect(0, y, r.x() + r.width(), self.char_height))
|
||||
line_on_screen = line_on_screen + 1
|
||||
|
||||
if False:
|
||||
line_on_screen = 0
|
||||
for line in self.lines_to_render:
|
||||
text = line.text()
|
||||
text = text.replace("\n", "").replace("\r", "")
|
||||
x = self.font_metric.horizontalAdvance(text)
|
||||
y = int(line_on_screen * self.char_height)
|
||||
painter.setBrush(QBrush(QColor(233, 233, 233)))
|
||||
painter.drawRect(QRect(0, y, x, self.char_height))
|
||||
line_on_screen = line_on_screen + 1
|
||||
|
||||
line_on_screen = 1
|
||||
for line in self.lines_to_render:
|
||||
x_start = -1
|
||||
|
||||
Reference in New Issue
Block a user