From fe9653fa130562c5338df839a868feb7c435b059 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 31 Jul 2020 19:43:33 +0530 Subject: [PATCH] Book list: When a series column is not wide enough, elide text in the middle so that the series number is visible --- src/calibre/gui2/library/delegates.py | 16 ++++++++++++++++ src/calibre/gui2/library/views.py | 7 ++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 9b86fe9f9c..4d40fa0856 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -322,6 +322,14 @@ class TextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ # }}} +class SeriesDelegate(TextDelegate): # {{{ + + def initStyleOption(self, option, index): + TextDelegate.initStyleOption(self, option, index) + option.textElideMode = Qt.ElideMiddle +# }}} + + class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ def __init__(self, parent, sep, items_func_name, space_before_sep=False): @@ -482,6 +490,14 @@ class CcTextDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ # }}} +class CcSeriesDelegate(CcTextDelegate): # {{{ + + def initStyleOption(self, option, index): + CcTextDelegate.initStyleOption(self, option, index) + option.textElideMode = Qt.ElideMiddle +# }}} + + class CcLongTextDelegate(QStyledItemDelegate): # {{{ ''' diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 8d77c646ee..aea6101a35 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -19,7 +19,7 @@ from calibre.constants import islinux from calibre.gui2.library.delegates import (RatingDelegate, PubDateDelegate, TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate, CcLongTextDelegate, CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate, - CcEnumDelegate, CcNumberDelegate, LanguagesDelegate) + CcEnumDelegate, CcNumberDelegate, LanguagesDelegate, SeriesDelegate, CcSeriesDelegate) from calibre.gui2.library.models import BooksModel, DeviceBooksModel from calibre.gui2.pin_columns import PinTableView from calibre.gui2.library.alternate_views import AlternateViews, setup_dnd_interface, handle_enter_press @@ -267,10 +267,11 @@ class BooksView(QTableView): # {{{ self.tags_delegate = CompleteDelegate(self, ',', 'all_tag_names') self.authors_delegate = CompleteDelegate(self, '&', 'all_author_names', True) self.cc_names_delegate = CompleteDelegate(self, '&', 'all_custom', True) - self.series_delegate = TextDelegate(self) + self.series_delegate = SeriesDelegate(self) self.publisher_delegate = TextDelegate(self) self.text_delegate = TextDelegate(self) self.cc_text_delegate = CcTextDelegate(self) + self.cc_series_delegate = CcSeriesDelegate(self) self.cc_longtext_delegate = CcLongTextDelegate(self) self.cc_enum_delegate = CcEnumDelegate(self) self.cc_bool_delegate = CcBoolDelegate(self) @@ -924,7 +925,7 @@ class BooksView(QTableView): # {{{ else: set_item_delegate(colhead, self.cc_text_delegate) elif cc['datatype'] == 'series': - set_item_delegate(colhead, self.cc_text_delegate) + set_item_delegate(colhead, self.cc_series_delegate) elif cc['datatype'] in ('int', 'float'): set_item_delegate(colhead, self.cc_number_delegate) elif cc['datatype'] == 'bool':