support files over 2 GB
This commit is contained in:
36
ScaledScrollBar.py
Normal file
36
ScaledScrollBar.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import math
|
||||
|
||||
from PyQt6.QtWidgets import QScrollBar
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("scaledScrollBar")
|
||||
|
||||
|
||||
class ScaledScrollBar(QScrollBar):
|
||||
is_huge = False
|
||||
|
||||
def __init__(self):
|
||||
super(ScaledScrollBar, self).__init__()
|
||||
self.real_maximum = self.maximum()
|
||||
|
||||
def setValue(self, value: int) -> None:
|
||||
if self.is_huge:
|
||||
real_position = value / self.real_maximum
|
||||
super().setValue(self.maximum() * real_position)
|
||||
else:
|
||||
super().setValue(value)
|
||||
|
||||
def setMaximum(self, maximum: int) -> None:
|
||||
if maximum > 2 ** 31:
|
||||
new_maximum = 1000 * math.log2(maximum)
|
||||
super().setMaximum(new_maximum)
|
||||
self.real_maximum = maximum
|
||||
|
||||
if not self.is_huge:
|
||||
old_position = self.value() / self.maximum()
|
||||
self.setValue(new_maximum * old_position)
|
||||
|
||||
self.is_huge = True
|
||||
else:
|
||||
self.is_huge = False
|
||||
super().setMaximum(maximum)
|
||||
@@ -11,6 +11,7 @@ from PyQt6.QtGui import *
|
||||
from PyQt6.QtGui import QMouseEvent
|
||||
from PyQt6.QtWidgets import *
|
||||
|
||||
from ScaledScrollBar import ScaledScrollBar
|
||||
from highlight import Highlight
|
||||
from highlight_regex import HighlightRegex
|
||||
from highlight_selection import HighlightSelection
|
||||
@@ -80,7 +81,7 @@ class BigText(QWidget):
|
||||
self.h_scroll_bar.setMaximum(1)
|
||||
self.h_scroll_bar.valueChanged.connect(big_text.h_scroll_event)
|
||||
|
||||
self.v_scroll_bar = QScrollBar()
|
||||
self.v_scroll_bar = ScaledScrollBar()
|
||||
self.v_scroll_bar.setPageStep(1)
|
||||
self.v_scroll_bar.valueChanged.connect(big_text.v_scroll_event)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user