More dark mode fixes

This commit is contained in:
Kovid Goyal 2019-10-23 20:40:07 +05:30
parent a3dfc924e2
commit a3dbdf7875
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 19 additions and 9 deletions

View File

@ -14,10 +14,10 @@ from lxml import html
from PyQt5.Qt import ( from PyQt5.Qt import (
QAction, QApplication, QBrush, QByteArray, QCheckBox, QColor, QColorDialog, QAction, QApplication, QBrush, QByteArray, QCheckBox, QColor, QColorDialog,
QDialog, QDialogButtonBox, QFont, QFontInfo, QFontMetrics, QFormLayout, QDialog, QDialogButtonBox, QFont, QFontInfo, QFontMetrics, QFormLayout,
QHBoxLayout, QIcon, QKeySequence, QLabel, QLineEdit, QMenu, QPlainTextEdit, QHBoxLayout, QIcon, QKeySequence, QLabel, QLineEdit, QMenu, QPalette,
QPushButton, QSize, QSyntaxHighlighter, Qt, QTabWidget, QTextBlockFormat, QPlainTextEdit, QPushButton, QSize, QSyntaxHighlighter, Qt, QTabWidget,
QTextCharFormat, QTextCursor, QTextEdit, QTextListFormat, QToolBar, QUrl, QTextBlockFormat, QTextCharFormat, QTextCursor, QTextEdit, QTextListFormat,
QVBoxLayout, QWidget, pyqtSignal, pyqtSlot QToolBar, QUrl, QVBoxLayout, QWidget, pyqtSignal, pyqtSlot
) )
from calibre import xml_replace_entities from calibre import xml_replace_entities
@ -591,7 +591,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
fmt = QTextCharFormat() fmt = QTextCharFormat()
fmt.setAnchor(True) fmt.setAnchor(True)
fmt.setAnchorHref(url) fmt.setAnchorHref(url)
fmt.setForeground(QBrush(QColor('blue'))) fmt.setForeground(QBrush(self.palette().color(QPalette.Link)))
if name or not c.hasSelection(): if name or not c.hasSelection():
c.mergeCharFormat(fmt) c.mergeCharFormat(fmt)
c.insertText(name or url) c.insertText(name or url)

View File

@ -361,7 +361,7 @@ class Comments(HTMLDisplay): # {{{
<head> <head>
<style type="text/css"> <style type="text/css">
body, td {background-color: transparent; color: %s } body, td {background-color: transparent; color: %s }
a { text-decoration: none; color: blue } a { text-decoration: none; }
div.description { margin-top: 0; padding-top: 0; text-indent: 0 } div.description { margin-top: 0; padding-top: 0; text-indent: 0 }
table { margin-bottom: 0; padding-bottom: 0; } table { margin-bottom: 0; padding-bottom: 0; }
</style> </style>

View File

@ -58,6 +58,17 @@ class TagDelegate(QStyledItemDelegate): # {{{
icon = option.icon icon = option.icon
icon.paint(painter, r, option.decorationAlignment, icon.Normal, icon.On) 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): def draw_text(self, style, painter, option, widget, index, item):
tr = style.subElementRect(style.SE_ItemViewItemText, option, widget) tr = style.subElementRect(style.SE_ItemViewItemText, option, widget)
text = index.data(Qt.DisplayRole) text = index.data(Qt.DisplayRole)
@ -67,7 +78,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)
painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count) self.paint_text(painter, r, Qt.AlignCenter | Qt.TextSingleLine, count, hover)
tr.setRight(r.left() - 1) tr.setRight(r.left() - 1)
else: else:
tr.setRight(tr.right() - 1) tr.setRight(tr.right() - 1)
@ -88,7 +99,7 @@ class TagDelegate(QStyledItemDelegate): # {{{
pen = QPen() pen = QPen()
pen.setBrush(QBrush(g)) pen.setBrush(QBrush(g))
painter.setPen(pen) painter.setPen(pen)
painter.drawText(tr, flags, text) self.paint_text(painter, tr, flags, text, hover)
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)
@ -186,7 +197,6 @@ class TagsView(QTreeView): # {{{
QTreeView::item:hover { QTreeView::item:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1);
color: black;
border: 1px solid #bfcde4; border: 1px solid #bfcde4;
border-radius: 6px; border-radius: 6px;
} }