From 5343c00b40a6c163eb70ced39175ba3366f4d569 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Tue, 2 Mar 2021 21:16:45 +0300 Subject: [PATCH] Improve code that sets custom CSS for dark themes - Enable it for Qt WebEngine too. - Include style for background color and links. - Disable it for export to HTML (webenv == True). See #255 and #492 for discussion related to dark themes. --- ReText/tab.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ReText/tab.py b/ReText/tab.py index fd0171ed..1254f808 100644 --- a/ReText/tab.py +++ b/ReText/tab.py @@ -203,10 +203,18 @@ def getHtmlFromConverted(self, converted, includeStyleSheet=True, webenv=False): style += 'table { border-collapse: collapse; }\n' style += 'img { max-width: 100%; }\n' # QTextDocument seems to use media=screen even for printing - if globalSettings.useWebKit: + if not isinstance(self.previewBox, QTextEdit) and not webenv: # https://github.com/retext-project/retext/pull/187 palette = QApplication.palette() - style += '@media screen { html { color: %s; } }\n' % palette.color(QPalette.ColorRole.WindowText).name() + fgColor = palette.color(QPalette.ColorRole.WindowText).name() + bgColor = palette.color(QPalette.ColorRole.Window).name() + linkColor = palette.color(QPalette.ColorRole.Link).name() + visitedLinkColor = palette.color(QPalette.ColorRole.LinkVisited).name() + style += ('@media screen {\n' + f' html {{ color: {fgColor}; background-color: {bgColor}; }}\n' + f' a, a * {{ color: {linkColor}; }}\n' + f' a:visited, a:visited * {{ color: {visitedLinkColor}; }}\n' + '}\n') # https://github.com/retext-project/retext/issues/408 style += '@media print { html { background-color: white; } }\n' headers += '\n'