Add option to restore alternating row colors to the Tag Browser under Preferences->Look & Feel->Tag Browser

This commit is contained in:
Kovid Goyal 2012-06-14 15:07:23 +05:30
parent afe5f09583
commit 43edf15118
4 changed files with 46 additions and 25 deletions

View File

@ -107,6 +107,7 @@ gprefs.defaults['auto_add_check_for_duplicates'] = False
gprefs.defaults['blocked_auto_formats'] = []
gprefs.defaults['auto_add_auto_convert'] = True
gprefs.defaults['ui_style'] = 'calibre' if iswindows or isosx else 'system'
gprefs.defaults['tag_browser_old_look'] = False
# }}}
NONE = QVariant() #: Null value to return from the data function of item models

View File

@ -104,6 +104,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('ui_style', gprefs, restart_required=True, choices=
[(_('System default'), 'system'), (_('Calibre style'),
'calibre')])
r('tag_browser_old_look', gprefs, restart_required=True)
r('cover_flow_queue_length', config, restart_required=True)

View File

@ -312,6 +312,18 @@ Manage Authors. You can use the values {author} and
<string>Tag Browser</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_10">
<item row="3" column="2" colspan="3">
<widget class="MultiCompleteLineEdit" name="opt_categories_using_hierarchy">
<property name="toolTip">
<string>A comma-separated list of categories in which items containing
periods are displayed in the tag browser trees. For example, if
this box contains 'tags' then tags of the form 'Mystery.English'
and 'Mystery.Thriller' will be displayed with English and Thriller
both under 'Mystery'. If 'tags' is not in this box,
then the tags will be displayed each on their own line.</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_9">
<property name="text">
@ -354,6 +366,19 @@ up into subcategories. If the partition method is set to disable, this value is
</property>
</widget>
</item>
<item row="5" column="0" colspan="5">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>690</width>
<height>252</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_8111">
<property name="text">
@ -396,27 +421,9 @@ a few top-level elements.</string>
</widget>
</item>
<item row="4" column="0" colspan="5">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>690</width>
<height>252</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2" colspan="3">
<widget class="MultiCompleteLineEdit" name="opt_categories_using_hierarchy">
<property name="toolTip">
<string>A comma-separated list of categories in which items containing
periods are displayed in the tag browser trees. For example, if
this box contains 'tags' then tags of the form 'Mystery.English'
and 'Mystery.Thriller' will be displayed with English and Thriller
both under 'Mystery'. If 'tags' is not in this box,
then the tags will be displayed each on their own line.</string>
<widget class="QCheckBox" name="opt_tag_browser_old_look">
<property name="text">
<string>Use &amp;alternating row colors in the Tag Browser</string>
</property>
</widget>
</item>

View File

@ -22,6 +22,10 @@ from calibre.utils.icu import sort_key
class TagDelegate(QStyledItemDelegate): # {{{
def __init__(self, *args, **kwargs):
QStyledItemDelegate.__init__(self, *args, **kwargs)
self.old_look = gprefs['tag_browser_old_look']
def paint(self, painter, option, index):
item = index.data(Qt.UserRole).toPyObject()
QStyledItemDelegate.paint(self, painter, option, index)
@ -46,7 +50,12 @@ class TagDelegate(QStyledItemDelegate): # {{{
nr = r.adjusted(0, 0, 0, 0)
nr.setBottom(r.bottom()-int(r.height()*(rating/5.0)))
painter.setClipRect(nr)
painter.fillRect(r, widget.palette().window())
bg = option.palette.window()
if self.old_look:
bg = (option.palette.alternateBase() if
option.features&option.Alternate else
option.palette.base())
painter.fillRect(r, bg)
style.proxy().drawPrimitive(style.PE_PanelItemViewItem, option,
painter, widget)
painter.setOpacity(0.3)
@ -108,13 +117,14 @@ class TagsView(QTreeView): # {{{
self._model.user_categories_edited.connect(self.user_categories_edited,
type=Qt.QueuedConnection)
self._model.drag_drop_finished.connect(self.drag_drop_finished)
self.setStyleSheet('''
stylish_tb = '''
QTreeView {
background-color: palette(window);
color: palette(window-text);
border: none;
}
'''
self.setStyleSheet('''
QTreeView::item {
border: 1px solid transparent;
padding-top:0.9ex;
@ -126,7 +136,9 @@ class TagsView(QTreeView): # {{{
border: 1px solid #bfcde4;
border-radius: 6px;
}
''')
''' + ('' if gprefs['tag_browser_old_look'] else stylish_tb))
if gprefs['tag_browser_old_look']:
self.setAlternatingRowColors(True)
@property
def hidden_categories(self):