mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book details: Automatically adjust the link color when using a dark theme
This commit is contained in:
parent
551c868899
commit
9fa545f5d9
@ -666,6 +666,13 @@ else:
|
||||
choose_files, choose_images, choose_dir, choose_save_file
|
||||
|
||||
|
||||
def is_dark_theme():
|
||||
pal = QApplication.instance().palette()
|
||||
col = pal.color(pal.Window)
|
||||
h, s, v, a = col.getHsvF()
|
||||
return v < 0.45
|
||||
|
||||
|
||||
def choose_osx_app(window, name, title, default_dir='/Applications'):
|
||||
fd = FileDialog(title=title, parent=window, name=name, mode=QFileDialog.ExistingFile,
|
||||
default_dir=default_dir)
|
||||
|
@ -8,9 +8,9 @@ from collections import namedtuple
|
||||
from functools import partial
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QAction, QApplication, QColor, QEasingCurve, QIcon, QLayout, QMenu,
|
||||
QMimeData, QPainter, QPen, QPixmap, QPropertyAnimation, QRect, QSize,
|
||||
QSizePolicy, Qt, QUrl, QWidget, pyqtProperty, pyqtSignal
|
||||
QAction, QApplication, QColor, QEasingCurve, QIcon, QLayout, QMenu, QMimeData,
|
||||
QPainter, QPen, QPixmap, QPropertyAnimation, QRect, QSize, QSizePolicy, Qt, QUrl,
|
||||
QWidget, pyqtProperty, pyqtSignal
|
||||
)
|
||||
|
||||
from calibre import fit_image
|
||||
@ -23,7 +23,7 @@ from calibre.ebooks.metadata.search_internet import (
|
||||
)
|
||||
from calibre.gui2 import (
|
||||
NO_URL_FORMATTING, choose_save_file, config, default_author_link, gprefs,
|
||||
safe_open_url, pixmap_to_data, rating_font
|
||||
is_dark_theme, pixmap_to_data, rating_font, safe_open_url
|
||||
)
|
||||
from calibre.gui2.dnd import (
|
||||
dnd_get_files, dnd_get_image, dnd_has_extension, dnd_has_image, image_extensions
|
||||
@ -61,6 +61,13 @@ def css(reset=False):
|
||||
return css.ans
|
||||
|
||||
|
||||
def themed_css(reset=False):
|
||||
ans = css(reset)
|
||||
if is_dark_theme():
|
||||
ans = 'a { color: #6CB4EE }\n\n' + ans
|
||||
return ans
|
||||
|
||||
|
||||
def copy_all(text_browser):
|
||||
mf = getattr(text_browser, 'details', text_browser)
|
||||
c = QApplication.clipboard()
|
||||
@ -555,10 +562,10 @@ class BookInfo(HTMLDisplay):
|
||||
ac.data = (None, None, None)
|
||||
ac.triggered.connect(self.remove_item_triggered)
|
||||
self.setFocusPolicy(Qt.NoFocus)
|
||||
self.document().setDefaultStyleSheet(css())
|
||||
self.document().setDefaultStyleSheet(themed_css())
|
||||
|
||||
def refresh_css(self):
|
||||
self.document().setDefaultStyleSheet(css(True))
|
||||
self.document().setDefaultStyleSheet(themed_css(True))
|
||||
|
||||
def remove_item_triggered(self):
|
||||
field, value, book_id = self.remove_item_action.data
|
||||
|
@ -12,7 +12,7 @@ from PyQt5.Qt import (
|
||||
from calibre import fit_image
|
||||
from calibre.gui2 import NO_URL_FORMATTING, gprefs
|
||||
from calibre.gui2.book_details import (
|
||||
css, details_context_menu_event, render_html, set_html
|
||||
themed_css, details_context_menu_event, render_html, set_html
|
||||
)
|
||||
from calibre.gui2.ui import get_gui
|
||||
from calibre.gui2.widgets import CoverView
|
||||
@ -83,7 +83,7 @@ class Details(HTMLDisplay):
|
||||
def __init__(self, book_info, parent=None):
|
||||
HTMLDisplay.__init__(self, parent)
|
||||
self.book_info = book_info
|
||||
self.document().setDefaultStyleSheet(css())
|
||||
self.document().setDefaultStyleSheet(themed_css())
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(350, 350)
|
||||
|
Loading…
x
Reference in New Issue
Block a user