fix computation of text width

This commit is contained in:
2021-10-24 16:35:27 +02:00
parent 3390ccf261
commit 80741a7249
9 changed files with 176 additions and 11 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ravenlog) (2)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ravenlog.iml" filepath="$PROJECT_DIR$/.idea/ravenlog.iml" />
</modules>
</component>
</project>

11
.idea/ravenlog.iml generated Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/venv39" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (ravenlog) (2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,3 +1,5 @@
import math
from PyQt6.QtCore import * from PyQt6.QtCore import *
from PyQt6.QtGui import * from PyQt6.QtGui import *
from PyQt6.QtWidgets import * from PyQt6.QtWidgets import *
@@ -16,7 +18,7 @@ class BigText(QWidget):
def __init__(self, model: LogFileModel): def __init__(self, model: LogFileModel):
super(BigText, self).__init__() super(BigText, self).__init__()
self.model = model self.model = model
self.font = QFont("monospace", 12) self.font = QFont("monospace", 20)
self.update_font_metrics(QPainter(self)) self.update_font_metrics(QPainter(self))
self.lines = [] self.lines = []
@@ -35,14 +37,14 @@ class BigText(QWidget):
if self._selection_end_byte != current_byte: if self._selection_end_byte != current_byte:
self._selection_end_byte = current_byte self._selection_end_byte = current_byte
self.update() self.update()
print("-> %s,%s" %(self._selection_start_byte, self._selection_end_byte)) #print("-> %s,%s" %(self._selection_start_byte, self._selection_end_byte))
def to_byte_offset(self, e: QMouseEvent) -> int: def to_byte_offset(self, e: QMouseEvent) -> int:
line_number = int(e.pos().y() / self.char_height) line_number = int(e.pos().y() / self.char_height)
if line_number < len(self.lines): if line_number < len(self.lines):
line = self.lines[line_number] line = self.lines[line_number]
char_in_line = int(e.pos().x() / self.char_width) + self._left_offset char_in_line = round(e.pos().x() / self.char_width) + self._left_offset
char_in_line = min(char_in_line, line.length()) char_in_line = min(char_in_line, line.length())
#print("%s in line %s" % (char_in_line, line_number)) #print("%s in line %s" % (char_in_line, line_number))
@@ -57,17 +59,22 @@ class BigText(QWidget):
painter.begin(self) painter.begin(self)
painter.setFont(self.font) painter.setFont(self.font)
painter.setPen(QColor(0, 0, 0)) painter.setPen(QColor(0, 0, 0))
self.update_font_metrics( painter) self.update_font_metrics(painter)
lines_to_show = self.height() / (self.fontMetrics().height()) lines_to_show = self.height() / (self.fontMetrics().height())
self.lines = self.model.data(self._byte_offset, lines_to_show) self.lines = self.model.data(self._byte_offset, lines_to_show)
# draw hightlights first - some characters may overlap to the next line
# by drawing the background hightlights first we prevent that the hightlight
# draws over a character
y_line_offset = self.char_height; y_line_offset = self.char_height;
for l in self.lines: for l in self.lines:
if l.intersects(self._selection_start_byte, self._selection_end_byte): if l.intersects(self._selection_start_byte, self._selection_end_byte):
self.draw_selection(painter, l, y_line_offset) self.draw_selection(painter, l, y_line_offset)
y_line_offset = y_line_offset + self.char_height
y_line_offset = self.char_height;
for l in self.lines:
painter.drawText(0, y_line_offset, l.line()) painter.drawText(0, y_line_offset, l.line())
y_line_offset = y_line_offset + self.char_height y_line_offset = y_line_offset + self.char_height
@@ -75,18 +82,19 @@ class BigText(QWidget):
def draw_selection(self, painter: QPainter, line: Line, y_line_offset: int): def draw_selection(self, painter: QPainter, line: Line, y_line_offset: int):
hightlight_color = QColor(255, 255, 0) hightlight_color = QColor(255, 255, 0)
if line.includes_byte(self._selection_start_byte): if line.includes_byte(self._selection_start_byte):
#print("%s bytes in line: " % (self._selection_start_byte - line.byte_offset()))
x1 = (self._selection_start_byte - line.byte_offset() - self._left_offset) * self.char_width x1 = (self._selection_start_byte - line.byte_offset() - self._left_offset) * self.char_width
else: else:
x1 = 0 x1 = 0
if line.includes_byte(self._selection_end_byte): if line.includes_byte(self._selection_end_byte):
width = (self._selection_end_byte - line.byte_offset() - self._left_offset) * self.char_width - x1 width = (self._selection_end_byte - line.byte_offset() - self._left_offset) * self.char_width - x1
#print("char in line: %d -> width: %d" % (self._selection_end_byte - line.byte_offset() - self._left_offset, width))
else: else:
width = len(line.line().rstrip()) * self.char_width -x1 width = len(line.line().rstrip()) * self.char_width -x1
y1 = y_line_offset- self.char_height y1 = y_line_offset- self.char_height + self.char_height / 7
height = self.char_height height = self.char_height
rect = QRect(x1,y1,width,height) rect = QRect(x1,y1,width,height)
#print(rect) #print(rect)
@@ -96,9 +104,8 @@ class BigText(QWidget):
old_brush = painter.brush() old_brush = painter.brush()
old_pen = painter.pen() old_pen = painter.pen()
painter.setBrush(color) painter.setBrush(color)
painter.setPen(color) painter.setPen(Qt.PenStyle.NoPen)
painter.drawRoundedRect(rect, 3.0, 3.0) painter.drawRoundedRect(rect, 3.0, 3.0)
#painter.drawRect(rect)
painter.setBrush(old_brush) painter.setBrush(old_brush)
painter.setPen(old_pen) painter.setPen(old_pen)
@@ -106,4 +113,7 @@ class BigText(QWidget):
fm: QFontMetrics = painter.fontMetrics() fm: QFontMetrics = painter.fontMetrics()
self.char_height = fm.height() self.char_height = fm.height()
self.char_width = fm.averageCharWidth()# all chars have same with for monospace font self.char_width = fm.averageCharWidth()# all chars have same with for monospace font
print("font width=%s height=%s" % (self.char_width, self.char_height)) text = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
self.char_width = fm.horizontalAdvance(text)/float(len(text))
#print("bounding rect: %s"%(boundingRect))
#print("font width=%s height=%s" % (self.char_width, self.char_height))

View File

@@ -3,3 +3,111 @@
0123456789012345678901234567890123456789 0123456789012345678901234567890123456789
01234567890123456789 01234567890123456789
0123456789012345678901234567890123456789 0123456789012345678901234567890123456789
01234567890123456789
0123456789012345678901234567890123456789
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
...............................|
|
äääääääääääääääääääääääääääääää|
2018-09-06T00:00:16.381Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful
2018-09-06T00:00:18.096Z,0,vapfacbk01,HealthCheckService.isOperable,AXC_5.14_526,,successful
2018-09-06T00:00:27.114Z,64,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.115Z,66,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.130Z,11,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.131Z,12,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.133Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.182Z,9,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.183Z,10,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.185Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.256Z,15,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.257Z,16,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.259Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.295Z,49,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.307Z,61,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.309Z,9,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.310Z,11,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.312Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.317Z,6,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.318Z,7,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.354Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.355Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.357Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.402Z,7,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.402Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.404Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.447Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.448Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.450Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.495Z,9,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.496Z,10,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.498Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.543Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.544Z,10,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.545Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.591Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.591Z,8,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.593Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.637Z,9,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.637Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.639Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.683Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.683Z,8,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.685Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.728Z,9,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.729Z,10,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.730Z,1,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:27.774Z,8,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:27.775Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:27.777Z,2,vapfacbk01,ApplicationLockService.isLocked,AXC_5.14_526,,successful
2018-09-06T00:00:30.317Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.319Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.353Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.355Z,1,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.394Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.397Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.439Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.441Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.450Z,5,vapfacbk01,ViewService.getFieldViews,AXC_5.14_526,,successful
2018-09-06T00:00:30.485Z,35,vapfacbk01,ViewService.getFieldViews,AXC_5.14_526,,successful
2018-09-06T00:00:30.502Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.504Z,1,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.550Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.552Z,1,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.596Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.598Z,1,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.640Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.642Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.682Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.684Z,1,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.721Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.723Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.750Z,5,vapfacbk01,ViewService.getFieldViews,AXC_5.14_526,,successful
2018-09-06T00:00:30.761Z,11,vapfacbk01,ViewService.getFieldViews,AXC_5.14_526,,successful
2018-09-06T00:00:30.764Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.766Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.806Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.808Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.864Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.866Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.906Z,7,vapfacbk01,MatterApplicationService.search,AXC_5.14_526,,successful
2018-09-06T00:00:30.908Z,9,vapfacbk01,CollectionService.getApplications,AXC_5.14_526,,successful
2018-09-06T00:00:30.933Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.935Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:30.974Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:30.976Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.032Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.034Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.078Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.081Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.113Z,1,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.115Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.147Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.149Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.180Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.182Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.222Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.224Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.266Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.268Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful
2018-09-06T00:00:31.309Z,2,vapfacbk01,ApplicationLockService.getLocks,AXC_5.14_526,,successful
2018-09-06T00:00:31.311Z,2,vapfacbk01,ApplicationStateService.getState,AXC_5.14_526,,successful

View File

@@ -23,3 +23,12 @@ class Line:
result = start_byte < self._byte_end and end_byte > self._byte_offset result = start_byte < self._byte_end and end_byte > self._byte_offset
#print("%d,%d in %d,%d" % (start_byte, end_byte, self._byte_offset, self._byte_end)) #print("%d,%d in %d,%d" % (start_byte, end_byte, self._byte_offset, self._byte_end))
return result return result
def prefix(self, index: int) -> str:
return self._line[0:index]
def substr(self, offset: int, length: int) -> str:
return self._line[offset:offset+length]
def suffix(self, index: int) -> str:
return self._line[index:]