move emblem_style setting into EditRules class

This commit is contained in:
un-pogaz 2026-02-23 07:10:26 +01:00
parent f213ae2c07
commit 09493941d7
3 changed files with 25 additions and 50 deletions

View File

@ -1163,7 +1163,8 @@ class EditRules(QWidget): # {{{
def restore_defaults(self):
match self.pref_name:
case 'cover_grid_icon_rules':
self.enabled.setChecked(gprefs.defaults['show_emblems'])
idx = self.choices.findData(gprefs.defaults['emblem_style'])
self.choices.setCurrentIndex(max(0, idx))
case 'bookshelf_icon_rules':
idx = self.choices.findData(gprefs.defaults['bookshelf_emblem_position'])
self.choices.setCurrentIndex(max(0, idx))
@ -1180,9 +1181,15 @@ class EditRules(QWidget): # {{{
'<p>You can <b>change an existing rule</b> by double clicking it.')
self.l1.setText('<p>'+ text)
match pref_name:
case 'cover_grid_icon_rules':
self.choices_label.setText(_('Emblem &style:'))
choice_map = (
(_('No emblems'), 'none'),
(_('Show next to cover'), 'gutter'),
(_('Show on top of cover'), 'emboss')
)
pref_key = 'emblem_style'
case 'bookshelf_icon_rules':
self.choices_label.setVisible(True)
self.choices.setVisible(True)
self.choices_label.setText(_('&Position of the emblem:'))
self.choices.setToolTip(_(
'<p>Display an icon of your choosing on the book spine in Bookshelf view.'
@ -1196,11 +1203,18 @@ class EditRules(QWidget): # {{{
(_('Top of the spine'), 'top'),
(_('Bottom of the spine'), 'bottom'),
)
for idx, (text, data) in enumerate(choice_map):
self.choices.addItem(text, data)
if data == gprefs['bookshelf_emblem_position']:
self.choices.setCurrentIndex(idx)
self.choices.currentIndexChanged.connect(self.changed)
pref_key = 'bookshelf_emblem_position'
case _:
choice_map = None
pref_key = None
if choice_map:
self.choices_label.setVisible(True)
self.choices.setVisible(True)
for idx, (text, data) in enumerate(choice_map):
self.choices.addItem(text, data)
if data == gprefs[pref_key]:
self.choices.setCurrentIndex(idx)
self.choices.currentIndexChanged.connect(self.changed)
def enabled_toggled(self):
enabled = self.enabled.isChecked()
@ -1350,7 +1364,8 @@ class EditRules(QWidget): # {{{
self.model.commit(prefs)
match self.pref_name:
case 'cover_grid_icon_rules':
gprefs['show_emblems'] = self.enabled.isChecked()
idx = max(0, self.choices.currentIndex())
gprefs['emblem_style'] = self.choices.itemData(idx)
case 'bookshelf_icon_rules':
idx = max(0, self.choices.currentIndex())
gprefs['bookshelf_emblem_position'] = self.choices.itemData(idx)

View File

@ -38,11 +38,6 @@ class CoverGridTab(QTabWidget, LazyConfigWidgetBase, Ui_cover_grid_tab):
r('emblem_size', gprefs)
r('emblem_position', gprefs, choices=[
(_('Left'), 'left'), (_('Top'), 'top'), (_('Right'), 'right'), (_('Bottom'), 'bottom')])
r('emblem_style', gprefs, choices=[
(_('No emblems'), 'none'),
(_('Show next to cover'), 'gutter'),
(_('Show on top of cover'), 'emboss')
])
fm = db.field_metadata
choices = sorted((('{} ({})'.format(fm[k]['name'], k), k) for k in fm.displayable_field_keys() if fm[k]['name']),

View File

@ -288,45 +288,10 @@ A value of zero means calculate automatically.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_emblems">
<widget class="EditRulesWidget" name="opt_cover_grid_icon_rules">
<attribute name="title">
<string>&amp;Emblems</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_emblems">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_emblems">
<item>
<widget class="QLabel" name="label_emblem_style">
<property name="text">
<string>Emblem &amp;style:</string>
</property>
<property name="buddy">
<cstring>opt_emblem_style</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="opt_emblem_style"/>
</item>
<item>
<spacer name="horizontalSpacer_emblems">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="EditRulesWidget" name="opt_cover_grid_icon_rules"/>
</item>
</layout>
</widget>
<widget class="CoverCacheConfig" name="config_cache">
<attribute name="title">