Skip to content

Commit

Permalink
Book list: When a series column is not wide enough, elide text in the…
Browse files Browse the repository at this point in the history
… middle so that the series number is visible
  • Loading branch information
kovidgoyal committed Jul 31, 2020
1 parent a91d7dd commit fe9653f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/calibre/gui2/library/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ def setModelData(self, editor, model, index):
# }}}


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):
Expand Down Expand Up @@ -482,6 +490,14 @@ def setModelData(self, editor, model, index):
# }}}


class CcSeriesDelegate(CcTextDelegate): # {{{

def initStyleOption(self, option, index):
CcTextDelegate.initStyleOption(self, option, index)
option.textElideMode = Qt.ElideMiddle
# }}}


class CcLongTextDelegate(QStyledItemDelegate): # {{{

'''
Expand Down
7 changes: 4 additions & 3 deletions src/calibre/gui2/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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
Expand Down Expand Up @@ -267,10 +267,11 @@ def __init__(self, parent, modelcls=BooksModel, use_edit_metadata_dialog=True):
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)
Expand Down Expand Up @@ -924,7 +925,7 @@ def set_item_delegate(colhead, delegate):
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':
Expand Down

0 comments on commit fe9653f

Please sign in to comment.