Elide long items in the middle when showing the completion popup for tags, to make it easier to use with hierarchical tags. Fixes #1925247 [Enhancement request: Autocomplete elision options](https://bugs.launchpad.net/calibre/+bug/1925247)

This commit is contained in:
Kovid Goyal 2021-04-27 11:15:14 +05:30
parent afa4433c2b
commit da99ac4280
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 11 additions and 0 deletions

View File

@ -335,6 +335,9 @@ class LineEdit(QLineEdit, LineEditECM):
@disable_popup.setter
def disable_popup(self, val):
self.mcompleter.disable_popup = bool(val)
def set_elide_mode(self, val):
self.mcompleter.setTextElideMode(val)
# }}}
def event(self, ev):
@ -474,6 +477,9 @@ class EditWithComplete(EnComboBox):
@disable_popup.setter
def disable_popup(self, val):
self.lineEdit().disable_popup = bool(val)
def set_elide_mode(self, val):
self.lineEdit().set_elide_mode(val)
# }}}
def text(self):

View File

@ -510,7 +510,9 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
all_tags = self.db.new_api.all_field_names('tags')
self.tags.update_items_cache(all_tags)
self.tags.set_elide_mode(Qt.TextElideMode.ElideMiddle)
self.remove_tags.update_items_cache(all_tags)
self.remove_tags.set_elide_mode(Qt.TextElideMode.ElideMiddle)
self.initialize_combos()

View File

@ -358,6 +358,8 @@ class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
m.setData(index, self.sep.join(d.tags), Qt.ItemDataRole.EditRole)
return None
editor = EditWithComplete(parent)
if col == 'tags':
editor.set_elide_mode(Qt.TextElideMode.ElideMiddle)
editor.set_separator(self.sep)
editor.set_space_before_sep(self.space_before_sep)
if self.sep == '&':

View File

@ -1379,6 +1379,7 @@ class TagsEdit(EditWithComplete, ToMetadataMixin): # {{{
def __init__(self, parent):
EditWithComplete.__init__(self, parent)
self.set_elide_mode(Qt.TextElideMode.ElideMiddle)
self.currentTextChanged.connect(self.data_changed)
self.lineEdit().setMaxLength(655360) # see https://bugs.launchpad.net/bugs/1630944
self.books_to_refresh = set()