mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2085656 [Visual issues with tag browser notes icons](https://bugs.launchpad.net/calibre/+bug/2085656)
This commit is contained in:
parent
c2da702b0f
commit
307af7f526
@ -89,17 +89,10 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
icon = option.icon
|
icon = option.icon
|
||||||
icon.paint(painter, r, option.decorationAlignment, QIcon.Mode.Normal, QIcon.State.On)
|
icon.paint(painter, r, option.decorationAlignment, QIcon.Mode.Normal, QIcon.State.On)
|
||||||
|
|
||||||
def paint_text(self, painter, rect, flags, text, hover, option):
|
def text_color(self, hover, palette) -> QColor:
|
||||||
painter.save()
|
if QApplication.instance().is_dark_theme and hover:
|
||||||
pen = painter.pen()
|
return QColor(Qt.GlobalColor.black)
|
||||||
if QApplication.instance().is_dark_theme:
|
return palette.color(QPalette.ColorRole.WindowText)
|
||||||
if hover:
|
|
||||||
pen.setColor(QColor(Qt.GlobalColor.black))
|
|
||||||
else:
|
|
||||||
pen.setColor(option.palette.color(QPalette.ColorRole.WindowText))
|
|
||||||
painter.setPen(pen)
|
|
||||||
painter.drawText(rect, flags, text)
|
|
||||||
painter.restore()
|
|
||||||
|
|
||||||
def draw_text(self, style, painter, option, widget, index, item):
|
def draw_text(self, style, painter, option, widget, index, item):
|
||||||
tr = style.subElementRect(QStyle.SubElement.SE_ItemViewItemText, option, widget)
|
tr = style.subElementRect(QStyle.SubElement.SE_ItemViewItemText, option, widget)
|
||||||
@ -111,6 +104,9 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
hover = option.state & QStyle.StateFlag.State_MouseOver
|
hover = option.state & QStyle.StateFlag.State_MouseOver
|
||||||
is_search = (True if item.type == TagTreeItem.TAG and
|
is_search = (True if item.type == TagTreeItem.TAG and
|
||||||
item.tag.category == 'search' else False)
|
item.tag.category == 'search' else False)
|
||||||
|
pen = painter.pen()
|
||||||
|
pen.setColor(self.text_color(hover, option.palette))
|
||||||
|
painter.setPen(pen)
|
||||||
|
|
||||||
def render_count():
|
def render_count():
|
||||||
if not is_search and (hover or gprefs['tag_browser_show_counts']):
|
if not is_search and (hover or gprefs['tag_browser_show_counts']):
|
||||||
@ -118,7 +114,7 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
width = painter.fontMetrics().boundingRect(count).width()
|
width = painter.fontMetrics().boundingRect(count).width()
|
||||||
r = QRect(tr)
|
r = QRect(tr)
|
||||||
r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4)
|
r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4)
|
||||||
self.paint_text(painter, r, Qt.AlignmentFlag.AlignCenter | Qt.TextFlag.TextSingleLine, count, hover, option)
|
painter.drawText(r, Qt.AlignmentFlag.AlignCenter | Qt.TextFlag.TextSingleLine, count)
|
||||||
tr.setRight(r.left() - 1)
|
tr.setRight(r.left() - 1)
|
||||||
else:
|
else:
|
||||||
tr.setRight(tr.right() - 1)
|
tr.setRight(tr.right() - 1)
|
||||||
@ -185,7 +181,7 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
painter.setFont(self.rating_font)
|
painter.setFont(self.rating_font)
|
||||||
if text_rec.width() > tr.width():
|
if text_rec.width() > tr.width():
|
||||||
g = QLinearGradient(QPointF(tr.topLeft()), QPointF(tr.topRight()))
|
g = QLinearGradient(QPointF(tr.topLeft()), QPointF(tr.topRight()))
|
||||||
c = option.palette.color(QPalette.ColorRole.WindowText)
|
c = pen.color()
|
||||||
g.setColorAt(0, c), g.setColorAt(0.8, c)
|
g.setColorAt(0, c), g.setColorAt(0.8, c)
|
||||||
c = QColor(c)
|
c = QColor(c)
|
||||||
c.setAlpha(0)
|
c.setAlpha(0)
|
||||||
@ -193,7 +189,7 @@ class TagDelegate(QStyledItemDelegate): # {{{
|
|||||||
pen = QPen()
|
pen = QPen()
|
||||||
pen.setBrush(QBrush(g))
|
pen.setBrush(QBrush(g))
|
||||||
painter.setPen(pen)
|
painter.setPen(pen)
|
||||||
self.paint_text(painter, tr, flags, text, hover, option)
|
painter.drawText(tr, flags, text)
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
QStyledItemDelegate.paint(self, painter, option, empty_index)
|
QStyledItemDelegate.paint(self, painter, option, empty_index)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user