Skip to content

Commit

Permalink
increase contrast for dark themes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
knipknap committed Jan 16, 2024
1 parent 21d5181 commit ec70e2c
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions btl/ui/tablecell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def isub(text, old, repl_pattern):
pattern = '|'.join(re.escape(o) for o in old)
return re.sub('('+pattern+')', repl_pattern, text, flags=re.I)

def interpolate_colors(start_color, end_color, ratio):
r = 1.0 - ratio
red = start_color.red() * r + end_color.red() * ratio
green = start_color.green() * r + end_color.green() * ratio
blue = start_color.blue() * r + end_color.blue() * ratio
return QtGui.QColor(int(red), int(green), int(blue))


class TwoLineTableCell(QtGui.QWidget):
def __init__ (self, parent=None):
super(TwoLineTableCell, self).__init__(parent)
Expand All @@ -17,25 +25,38 @@ def __init__ (self, parent=None):
self.lower_text = ''
self.search_highlight = ''

palette = self.palette()
bg_role = self.backgroundRole()
bg_color = palette.color(bg_role)
fg_role = self.foregroundRole()
fg_color = palette.color(fg_role)

self.vbox = QtGui.QVBoxLayout()
self.label_upper = QtGui.QLabel()
self.label_upper.setStyleSheet("margin-top: 8px")

color = interpolate_colors(bg_color, fg_color, .8)
style = "margin-bottom: 8px; color: {};".format(color.name())
self.label_lower = QtGui.QLabel()
self.label_lower.setStyleSheet("margin-bottom: 8px")
self.label_lower.setStyleSheet(style)
self.vbox.addWidget(self.label_upper)
self.vbox.addWidget(self.label_lower)

style = "color: {}".format(fg_color.name())
self.label_left = QtGui.QLabel()
self.label_left.setMinimumWidth(40)
self.label_left.setTextFormat(QtCore.Qt.RichText)
self.label_left.setAlignment(QtCore.Qt.AlignCenter|QtCore.Qt.AlignVCenter)
self.label_left.setStyleSheet(style)

self.icon_widget = QtGui.QLabel()

style = "color: {}".format(fg_color.name())
self.label_right = QtGui.QLabel()
self.label_right.setMinimumWidth(40)
self.label_right.setTextFormat(QtCore.Qt.RichText)
self.label_right.setAlignment(QtCore.Qt.AlignCenter)
self.label_right.setStyleSheet(style)

self.hbox = QtGui.QHBoxLayout()
self.hbox.addWidget(self.label_left, 0)
Expand All @@ -48,7 +69,7 @@ def __init__ (self, parent=None):
def _highlight(self, text):
if not self.search_highlight:
return text
highlight_fmt = r'<font style="background: yellow">\1</font>'
highlight_fmt = r'<font style="background: yellow; color: black">\1</font>'
return isub(text, self.search_highlight.split(' '), highlight_fmt)

def _update(self):
Expand All @@ -66,7 +87,7 @@ def _update(self):

text = self._highlight(self.lower_text)
self.label_lower.setText(text)
self.label_lower.setText(f'<font color="#444">{text}</font>')
self.label_lower.setText(f'{text}')

def set_tool_no(self, no):
self.tool_no = str(no)
Expand Down

0 comments on commit ec70e2c

Please sign in to comment.