replace ScaledScrollBar with BigScrollBar
step 2 - connect the line up/down, page up/down events
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from PySide6.QtWidgets import QWidget, QStylePainter, QStyle, QStyleOptionSlider, QSlider
|
||||
import enum
|
||||
|
||||
from PySide6.QtWidgets import QWidget, QStylePainter, QStyle, QStyleOptionSlider, QSlider, QAbstractSlider
|
||||
from PySide6.QtCore import Qt, QSize, QEvent, QRect, QPoint, Signal
|
||||
|
||||
|
||||
@@ -11,6 +13,14 @@ class BigScrollBar(QWidget):
|
||||
code involved. We work around this by converting the python int
|
||||
into a string."""
|
||||
|
||||
class ScrollEvent(enum.IntEnum):
|
||||
PageUp = 1
|
||||
PageDown = 2
|
||||
LinesUp = 3
|
||||
LinesDown = 4
|
||||
|
||||
scroll_event = Signal(ScrollEvent)
|
||||
|
||||
pressedControl = QStyle.SubControl.SC_None
|
||||
click_offset = 0
|
||||
|
||||
@@ -104,13 +114,13 @@ class BigScrollBar(QWidget):
|
||||
|
||||
self.pressedControl = self.style().hitTestComplexControl(QStyle.ComplexControl.CC_ScrollBar, style_options,
|
||||
event.position().toPoint(), self)
|
||||
# print(f"pressedControl {self.pressedControl}")
|
||||
print(f"pressedControl {self.pressedControl}")
|
||||
|
||||
sr: QRect = self.style().subControlRect(QStyle.ComplexControl.CC_ScrollBar, style_options,
|
||||
QStyle.SubControl.SC_ScrollBarSlider, self)
|
||||
click: QPoint = event.position().toPoint()
|
||||
pressYValue = click.y() - sr.center().y() + sr.topLeft().y()
|
||||
pressYValue = self.pixelPosToRangeValue(pressYValue)
|
||||
press_y_value = click.y() - sr.center().y() + sr.topLeft().y()
|
||||
press_y_value = self.pixelPosToRangeValue(press_y_value)
|
||||
# print(f"pressYValue {pressYValue}")
|
||||
|
||||
if self.pressedControl == QStyle.SubControl.SC_ScrollBarSlider:
|
||||
@@ -126,6 +136,27 @@ class BigScrollBar(QWidget):
|
||||
self.click_offset = slider_length / 2
|
||||
pass
|
||||
|
||||
self.activateControl(self.pressedControl)
|
||||
# self.repaint(self.style().subControlRect(QStyle.ComplexControl.CC_ScrollBar, style_options, self.pressedControl))
|
||||
|
||||
def activateControl(self, control):
|
||||
action = QAbstractSlider.SliderAction.SliderNoAction
|
||||
match control:
|
||||
case QStyle.SubControl.SC_ScrollBarAddPage:
|
||||
self.scroll_event.emit(self.ScrollEvent.PageDown)
|
||||
case QStyle.SubControl.SC_ScrollBarSubPage:
|
||||
self.scroll_event.emit(self.ScrollEvent.PageUp)
|
||||
case QStyle.SubControl.SC_ScrollBarAddLine:
|
||||
self.scroll_event.emit(self.ScrollEvent.LinesDown)
|
||||
case QStyle.SubControl.SC_ScrollBarSubLine:
|
||||
self.scroll_event.emit(self.ScrollEvent.LinesUp)
|
||||
case QStyle.SubControl.SC_ScrollBarFirst:
|
||||
self.set_value(self.minimun)
|
||||
case QStyle.SubControl.SC_ScrollBarLast:
|
||||
self.set_value(self.maximum)
|
||||
case _:
|
||||
pass
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
self.pressedControl = QStyle.SubControl.SC_None
|
||||
|
||||
@@ -169,5 +200,5 @@ class BigScrollBar(QWidget):
|
||||
|
||||
def set_value(self, value: int):
|
||||
self.value = value
|
||||
self.value_changed.emit(str(value))
|
||||
self.value_changed.emit(str(self.value))
|
||||
self.repaint()
|
||||
|
||||
@@ -98,7 +98,8 @@ class BigText(QWidget):
|
||||
self.h_scroll_bar.valueChanged.connect(self.big_text.h_scroll_event)
|
||||
|
||||
# self.v_scroll_bar.setPageStep(1)
|
||||
self.v_scroll_bar.value_changed.connect(self.big_text.v_scroll_event)
|
||||
self.v_scroll_bar.value_changed.connect(self.big_text.v_scroll_value_changed)
|
||||
self.v_scroll_bar.scroll_event.connect(self.big_text.v_scroll_event)
|
||||
|
||||
if show_range_slider:
|
||||
self.range_limit = RangeSlider()
|
||||
@@ -399,10 +400,22 @@ class InnerBigText(QWidget):
|
||||
self.update()
|
||||
|
||||
@Slot()
|
||||
def v_scroll_event(self, byte_offset: str):
|
||||
def v_scroll_value_changed(self, byte_offset: str):
|
||||
self._byte_offset = int(byte_offset)
|
||||
self.update()
|
||||
|
||||
@Slot()
|
||||
def v_scroll_event(self, event: BigScrollBar.ScrollEvent):
|
||||
match event:
|
||||
case BigScrollBar.ScrollEvent.LinesUp:
|
||||
self.scroll_by_lines(-3)
|
||||
case BigScrollBar.ScrollEvent.LinesDown:
|
||||
self.scroll_by_lines(3)
|
||||
case BigScrollBar.ScrollEvent.PageUp:
|
||||
self.scroll_by_lines(-(int(self.lines_shown()) - 1))
|
||||
case BigScrollBar.ScrollEvent.PageDown:
|
||||
self.scroll_by_lines(int(self.lines_shown()) - 1)
|
||||
|
||||
def update_longest_line(self, length: int):
|
||||
width_in_chars = self.width() / self.char_width
|
||||
# print("width_in_chars: %d" % width_in_chars)
|
||||
|
||||
Reference in New Issue
Block a user