scroll horizontally when dragging a selection
This commit is contained in:
30
bigtext.py
30
bigtext.py
@@ -79,8 +79,6 @@ class InnerBigText(QWidget):
|
||||
self.selection_highlight,
|
||||
]
|
||||
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
self.draw()
|
||||
|
||||
def keyPressEvent(self, e: QKeyEvent) -> None:
|
||||
lines_to_scroll = math.floor(self.lines_shown()) -1
|
||||
@@ -118,10 +116,18 @@ class InnerBigText(QWidget):
|
||||
self.update()
|
||||
# print("-> %s,%s" %(self._selection_start_byte, self._selection_end_byte))
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
column_in_line = self.x_pos_to_column(e.pos().x())
|
||||
if line_number == 0:
|
||||
self.scroll_by_lines(-1)
|
||||
if line_number+1 >= int(self.lines_shown()):
|
||||
self.scroll_by_lines(1)
|
||||
if column_in_line <= 1:
|
||||
self._left_offset = max(0, self._left_offset-2)
|
||||
self.update()
|
||||
if column_in_line+1 >= self.columns_shown():
|
||||
self._left_offset = self._left_offset+2
|
||||
self.update()
|
||||
|
||||
|
||||
def h_scroll_event(self, left_offset: int):
|
||||
self._left_offset = left_offset
|
||||
@@ -140,16 +146,26 @@ class InnerBigText(QWidget):
|
||||
maximum = max(0, length - width_in_chars+1)
|
||||
self.parent.h_scroll_bar.setMaximum(maximum)
|
||||
|
||||
def y_pos_to_line(self, y: int):
|
||||
def y_pos_to_line(self, y: int) -> int:
|
||||
return int(y / self.char_height)
|
||||
|
||||
def x_pos_to_column(self, x: int) -> int:
|
||||
return round(x / self.char_width)
|
||||
|
||||
def lines_shown(self) -> float:
|
||||
return self.height() / float(self.char_height)
|
||||
|
||||
def columns_shown(self) -> float:
|
||||
return self.width() / float(self.char_width)
|
||||
|
||||
|
||||
def to_byte_offset(self, e: QMouseEvent) -> int:
|
||||
line_number = self.y_pos_to_line(e.pos().y())
|
||||
|
||||
if line_number < len(self.lines):
|
||||
line = self.lines[line_number]
|
||||
char_in_line = round(e.pos().x() / self.char_width) + self._left_offset
|
||||
char_in_line = min(char_in_line, line.length())
|
||||
column_in_line = self.x_pos_to_column(e.pos().x()) + self._left_offset
|
||||
char_in_line = min(column_in_line, line.length())
|
||||
# print("%s in line %s" % (char_in_line, line_number))
|
||||
|
||||
current_byte = line.byte_offset() + char_in_line
|
||||
@@ -158,10 +174,8 @@ class InnerBigText(QWidget):
|
||||
current_byte = self.model.byte_count()
|
||||
return current_byte
|
||||
|
||||
def lines_shown(self):
|
||||
return self.height() / float(self.char_height)
|
||||
|
||||
def draw(self):
|
||||
def paintEvent(self, event: QPaintEvent) -> None:
|
||||
painter = QPainter(self)
|
||||
painter.setFont(self.font)
|
||||
painter.setPen(QColor(0, 0, 0))
|
||||
|
||||
Reference in New Issue
Block a user