diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index b022fdac64..861e1bf70c 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -292,13 +292,17 @@ maximum_resort_levels = 5 generate_cover_title_font = None generate_cover_foot_font = None -#: Control behavior of double clicks on the book list -# Behavior of doubleclick on the books list. Choices: open_viewer, do_nothing, +#: Control behavior of the book list +# You can control the behavior of doubleclicks on the books list. +# Choices: open_viewer, do_nothing, # edit_cell, edit_metadata. Selecting edit_metadata has the side effect of # disabling editing a field using a single click. # Default: open_viewer. # Example: doubleclick_on_library_view = 'do_nothing' +# You can also control whether the book list scrolls horizontal per column or +# per pixel. Default is per column. doubleclick_on_library_view = 'open_viewer' +horizontal_scrolling_per_column = True #: Language to use when sorting. # Setting this tweak will force sorting to use the diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 54ef308f65..27939c3519 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -51,7 +51,8 @@ class BooksView(QTableView): # {{{ def __init__(self, parent, modelcls=BooksModel, use_edit_metadata_dialog=True): QTableView.__init__(self, parent) - self.setHorizontalScrollMode(self.ScrollPerPixel) + if not tweaks['horizontal_scrolling_per_column']: + self.setHorizontalScrollMode(self.ScrollPerPixel) self.setEditTriggers(self.EditKeyPressed) if tweaks['doubleclick_on_library_view'] == 'edit_cell': @@ -112,6 +113,7 @@ class BooksView(QTableView): # {{{ self.column_header.sectionMoved.connect(self.save_state) self.column_header.setContextMenuPolicy(Qt.CustomContextMenu) self.column_header.customContextMenuRequested.connect(self.show_column_header_context_menu) + self.column_header.sectionResized.connect(self.column_resized, Qt.QueuedConnection) # }}} self._model.database_changed.connect(self.database_changed) @@ -216,6 +218,9 @@ class BooksView(QTableView): # {{{ self.column_header_context_menu.addSeparator() + self.column_header_context_menu.addAction( + _('Shrink column if it is too wide to fit'), + partial(self.resize_column_to_fit, column=self.column_map[idx])) self.column_header_context_menu.addAction( _('Restore default layout'), partial(self.column_header_context_handler, @@ -464,6 +469,19 @@ class BooksView(QTableView): # {{{ self.was_restored = True + def resize_column_to_fit(self, column): + col = self.column_map.index(column) + self.column_resized(col, self.columnWidth(col), self.columnWidth(col)) + + def column_resized(self, col, old_size, new_size): + # arbitrary: scroll bar + header + some + max_width = self.width() - (self.verticalScrollBar().width() + + self.verticalHeader().width() + 10) + if new_size > max_width: + self.column_header.blockSignals(True) + self.setColumnWidth(col, max_width) + self.column_header.blockSignals(False) + # }}} # Initialization/Delegate Setup {{{