mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-05-27 17:22:34 -04:00
Bookshelf: allow override colors theme
This commit is contained in:
@@ -506,6 +506,7 @@ def create_defs():
|
||||
defs['bookshelf_divider_text_right'] = False
|
||||
defs['bookshelf_start_with_divider'] = False
|
||||
defs['bookshelf_divider_style'] = 'text'
|
||||
defs['bookshelf_theme_override'] = 'none'
|
||||
|
||||
# Migrate beta bookshelf_thumbnail
|
||||
if isinstance(btv := gprefs.get('bookshelf_thumbnail'), bool):
|
||||
|
||||
@@ -68,7 +68,7 @@ from xxhash import xxh3_64_intdigest
|
||||
from calibre import fit_image
|
||||
from calibre.db.cache import Cache
|
||||
from calibre.ebooks.metadata import authors_to_string, rating_to_stars
|
||||
from calibre.gui2 import config, gprefs, is_dark_theme
|
||||
from calibre.gui2 import config, gprefs
|
||||
from calibre.gui2.library.alternate_views import (
|
||||
ClickStartData,
|
||||
double_click_action,
|
||||
@@ -230,6 +230,13 @@ class WoodTheme(NamedTuple):
|
||||
)
|
||||
|
||||
|
||||
def is_dark_theme():
|
||||
from calibre.gui2 import is_dark_theme
|
||||
if gprefs['bookshelf_theme_override'] == 'none':
|
||||
return is_dark_theme()
|
||||
return gprefs['bookshelf_theme_override'] == 'dark'
|
||||
|
||||
|
||||
def color_with_alpha(c: QColor, a: int) -> QColor:
|
||||
ans = QColor(c)
|
||||
ans.setAlpha(a)
|
||||
@@ -1517,6 +1524,7 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea):
|
||||
'''Refresh the gui and render settings.'''
|
||||
self.template_inited = False
|
||||
self.calculate_shelf_geometry()
|
||||
self.palette_changed()
|
||||
if hasattr(self, 'cover_cache'):
|
||||
self.cover_cache.set_thumbnail_size(*self.thumbnail_size())
|
||||
self.cover_cache.set_disk_cache_max_size(gprefs['bookshelf_disk_cache_size'])
|
||||
@@ -1526,6 +1534,7 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea):
|
||||
def palette_changed(self):
|
||||
self.text_color_for_dark_background = dark_palette().color(QPalette.ColorRole.WindowText)
|
||||
self.text_color_for_light_background = light_palette().color(QPalette.ColorRole.WindowText)
|
||||
self.setPalette(dark_palette() if is_dark_theme() else light_palette())
|
||||
|
||||
def view_is_visible(self) -> bool:
|
||||
'''Return if the bookshelf view is visible.'''
|
||||
|
||||
@@ -112,6 +112,12 @@ class BookshelfTab(QTabWidget, LazyConfigWidgetBase, Ui_Form):
|
||||
r('bookshelf_author_template', db.prefs)
|
||||
r('bookshelf_spine_size_template', db.prefs)
|
||||
|
||||
r('bookshelf_theme_override', gprefs, choices=[
|
||||
(_('Global setting'), 'none'),
|
||||
(_('Light'), 'light'),
|
||||
(_('Dark'), 'dark'),
|
||||
])
|
||||
|
||||
self.config_cache.link(
|
||||
self.gui.bookshelf_view.cover_cache,
|
||||
'bookshelf_disk_cache_size', 'bookshelf_cache_size_multiple',
|
||||
|
||||
@@ -322,7 +322,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="11" column="0" colspan="2">
|
||||
<item row="11" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Colors &theme:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>opt_bookshelf_theme_override</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="11" column="1">
|
||||
<widget class="QComboBox" name="opt_bookshelf_theme_override">
|
||||
<property name="toolTip">
|
||||
<string>Control which colors theme to use for the bookshelf view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QPushButton" name="recount_button">
|
||||
@@ -356,7 +373,7 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="12" column="0">
|
||||
<item row="13" column="0">
|
||||
<spacer name="vertical_spacer_1">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
||||
Reference in New Issue
Block a user