Skip to content

Commit

Permalink
feat: Optimized the highlight color for unaligned merged units. resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
bookfere committed Mar 26, 2024
1 parent a046c1e commit a8fdd17
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions components/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from qt.core import (
Qt, QTableWidget, QHeaderView, QMenu, QAbstractItemView, QCursor,
QBrush, QTableWidgetItem, pyqtSignal, QTableWidgetSelectionRange,
QColor, QT_VERSION_STR)
QColor, QPalette, QT_VERSION_STR)
except ImportError:
from PyQt5.Qt import (
Qt, QTableWidget, QHeaderView, QMenu, QAbstractItemView, QCursor,
QBrush, QTableWidgetItem, pyqtSignal, QTableWidgetSelectionRange,
QColor, QT_VERSION_STR)
QColor, QPalette, QT_VERSION_STR)

load_translations()

Expand Down Expand Up @@ -55,9 +55,6 @@ def layout(self):
for row, paragraph in enumerate(self.paragraphs):
vheader = QTableWidgetItem(str(row))
vheader.setTextAlignment(Qt.AlignCenter)
# vheader.setBackground(QBrush(QColor(255, 255, 0, 255)))
# vheader.setBackground(QBrush(Qt.NoBrush))
# vheader.setData(Qt.BackgroundRole, QColor(255, 255, 100, 100))
self.setVerticalHeaderItem(row, vheader)

original = QTableWidgetItem(paragraph.original)
Expand All @@ -76,8 +73,9 @@ def layout(self):
self.track_row_data(row)

header = self.horizontalHeader()
stretch = (getattr(QHeaderView.ResizeMode, 'Stretch', None)
or QHeaderView.Stretch)
stretch = (
getattr(QHeaderView.ResizeMode, 'Stretch', None)
or QHeaderView.Stretch)
header.setSectionResizeMode(0, stretch)

def track_row_data(self, row):
Expand All @@ -96,16 +94,19 @@ def check_row_alignment(self, paragraph):
a native background for PyQt versions lower than 6.0.0, as using
Qt.NoBrush results in a fully black background.
"""
foreground = QBrush(Qt.black)
engine = get_engine_class(paragraph.engine_name)
if engine is None or paragraph.is_alignment(engine.separator):
vh_background = background = QBrush(Qt.NoBrush)
vh_background = vh_foreground = background = QBrush(Qt.NoBrush)
if QT_VERSION_STR < '6.0.0':
vh_background = QBrush(QColor(235, 235, 235, 255))
vh_foreground = QBrush(Qt.black)
tip = ''
paragraph.aligned = True
else:
vh_background = QBrush(QColor(255, 255, 0, 255))
is_light = self.palette().color(QPalette.Window).lightness() > 127
vh_background = QBrush(
QColor(255, 255, 100) if is_light else QColor(100, 100, 0))
vh_foreground = QBrush(Qt.black if is_light else Qt.white)
background = QBrush(QColor(255, 255, 0, 100))
tip = _(
'The number of lines differs between the original text and '
Expand All @@ -114,12 +115,11 @@ def check_row_alignment(self, paragraph):

item = self.verticalHeaderItem(paragraph.row)
item.setBackground(vh_background)
item.setForeground(foreground)
item.setForeground(vh_foreground)
item.setToolTip(tip)
for column in range(self.columnCount()):
item = self.item(paragraph.row, column)
item.setBackground(background)
item.setForeground(foreground)
item.setToolTip(tip)

def non_aligned_count(self):
Expand Down

0 comments on commit a8fdd17

Please sign in to comment.