From a3dbdf78750fec6d07f1942926b253b9c2b2cd34 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Oct 2019 20:40:07 +0530 Subject: [PATCH] More dark mode fixes --- src/calibre/gui2/comments_editor.py | 10 +++++----- src/calibre/gui2/metadata/single_download.py | 2 +- src/calibre/gui2/tag_browser/view.py | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 5b3595db1f..7aa647e209 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -14,10 +14,10 @@ from lxml import html from PyQt5.Qt import ( QAction, QApplication, QBrush, QByteArray, QCheckBox, QColor, QColorDialog, QDialog, QDialogButtonBox, QFont, QFontInfo, QFontMetrics, QFormLayout, - QHBoxLayout, QIcon, QKeySequence, QLabel, QLineEdit, QMenu, QPlainTextEdit, - QPushButton, QSize, QSyntaxHighlighter, Qt, QTabWidget, QTextBlockFormat, - QTextCharFormat, QTextCursor, QTextEdit, QTextListFormat, QToolBar, QUrl, - QVBoxLayout, QWidget, pyqtSignal, pyqtSlot + QHBoxLayout, QIcon, QKeySequence, QLabel, QLineEdit, QMenu, QPalette, + QPlainTextEdit, QPushButton, QSize, QSyntaxHighlighter, Qt, QTabWidget, + QTextBlockFormat, QTextCharFormat, QTextCursor, QTextEdit, QTextListFormat, + QToolBar, QUrl, QVBoxLayout, QWidget, pyqtSignal, pyqtSlot ) from calibre import xml_replace_entities @@ -591,7 +591,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ fmt = QTextCharFormat() fmt.setAnchor(True) fmt.setAnchorHref(url) - fmt.setForeground(QBrush(QColor('blue'))) + fmt.setForeground(QBrush(self.palette().color(QPalette.Link))) if name or not c.hasSelection(): c.mergeCharFormat(fmt) c.insertText(name or url) diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index aa8a60c769..a9c1d50299 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -361,7 +361,7 @@ class Comments(HTMLDisplay): # {{{ diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index c5c072d979..f125a25c5a 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -58,6 +58,17 @@ class TagDelegate(QStyledItemDelegate): # {{{ icon = option.icon icon.paint(painter, r, option.decorationAlignment, icon.Normal, icon.On) + def paint_text(self, painter, rect, flags, text, hover): + set_color = hover and QApplication.instance().is_dark_theme + if set_color: + painter.save() + pen = painter.pen() + pen.setColor(QColor(Qt.black)) + painter.setPen(pen) + painter.drawText(rect, flags, text) + if set_color: + painter.restore() + def draw_text(self, style, painter, option, widget, index, item): tr = style.subElementRect(style.SE_ItemViewItemText, option, widget) text = index.data(Qt.DisplayRole) @@ -67,7 +78,7 @@ class TagDelegate(QStyledItemDelegate): # {{{ width = painter.fontMetrics().boundingRect(count).width() r = QRect(tr) r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4) - painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count) + self.paint_text(painter, r, Qt.AlignCenter | Qt.TextSingleLine, count, hover) tr.setRight(r.left() - 1) else: tr.setRight(tr.right() - 1) @@ -88,7 +99,7 @@ class TagDelegate(QStyledItemDelegate): # {{{ pen = QPen() pen.setBrush(QBrush(g)) painter.setPen(pen) - painter.drawText(tr, flags, text) + self.paint_text(painter, tr, flags, text, hover) def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, empty_index) @@ -186,7 +197,6 @@ class TagsView(QTreeView): # {{{ QTreeView::item:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); - color: black; border: 1px solid #bfcde4; border-radius: 6px; }