diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index a3bea931a..af31143c4 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -38,15 +38,13 @@ class CompletionView(QTreeView): Based on QTreeView but heavily customized so root elements show as category headers, and children show as flat list. - Class attributes: - COLUMN_WIDTHS: A list of column widths, in percent. - Attributes: enabled: Whether showing the CompletionView is enabled. _win_id: The ID of the window this CompletionView is associated with. _height: The height to use for the CompletionView. _height_perc: Either None or a percentage if height should be relative. _delegate: The item delegate used. + column_widths: A list of column widths, in percent. Signals: resize_completion: Emitted when the completion should be resized. @@ -82,7 +80,6 @@ class CompletionView(QTreeView): border: 0px; } """ - COLUMN_WIDTHS = (20, 70, 10) # FIXME style scrollbar # https://github.com/The-Compiler/qutebrowser/issues/117 @@ -103,6 +100,8 @@ class CompletionView(QTreeView): # FIXME handle new aliases. # objreg.get('config').changed.connect(self.init_command_completion) + self.column_widths = config.get('completion', + 'base-column-width-percentages') self._delegate = completiondelegate.CompletionItemDelegate(self) self.setItemDelegate(self._delegate) style.set_register_stylesheet(self) @@ -128,9 +127,9 @@ class CompletionView(QTreeView): return utils.get_repr(self) def _resize_columns(self): - """Resize the completion columns based on COLUMN_WIDTHS.""" + """Resize the completion columns based on column_widths.""" width = self.size().width() - pixel_widths = [(width * perc // 100) for perc in self.COLUMN_WIDTHS] + pixel_widths = [(width * perc // 100) for perc in self.column_widths] if self.verticalScrollBar().isVisible(): pixel_widths[-1] -= self.style().pixelMetric( QStyle.PM_ScrollBarExtent) + 5 @@ -203,6 +202,10 @@ class CompletionView(QTreeView): sel_model.deleteLater() for i in range(model.rowCount()): self.expand(model.index(i, 0)) + + if model.column_widths: + self.column_widths = model.column_widths + self._resize_columns() self.maybe_resize_completion() diff --git a/qutebrowser/completion/models/base.py b/qutebrowser/completion/models/base.py index 0d4bf7fca..9036df385 100644 --- a/qutebrowser/completion/models/base.py +++ b/qutebrowser/completion/models/base.py @@ -27,6 +27,7 @@ from PyQt5.QtCore import Qt from PyQt5.QtGui import QStandardItemModel, QStandardItem from qutebrowser.utils import usertypes, qtutils +from qutebrowser.config import config Role = usertypes.enum('Role', ['sort', 'userdata'], start=Qt.UserRole, @@ -44,6 +45,8 @@ class BaseCompletionModel(QStandardItemModel): def __init__(self, parent=None): super().__init__(parent) self.setColumnCount(3) + self.column_widths = config.get('completion', + 'base-column-width-percentages') self.columns_to_filter = [0] def new_category(self, name, sort=None): diff --git a/qutebrowser/completion/models/sortfilter.py b/qutebrowser/completion/models/sortfilter.py index 3c247a0a2..db4e8e425 100644 --- a/qutebrowser/completion/models/sortfilter.py +++ b/qutebrowser/completion/models/sortfilter.py @@ -53,6 +53,7 @@ class CompletionFilterModel(QSortFilterProxyModel): else: self.setSortRole(completion.Role.sort) self._sort_order = dumb_sort + self.column_widths = source.column_widths def set_pattern(self, val): """Setter for pattern. diff --git a/qutebrowser/completion/models/urlmodel.py b/qutebrowser/completion/models/urlmodel.py index 2da1d0b71..b33366f22 100644 --- a/qutebrowser/completion/models/urlmodel.py +++ b/qutebrowser/completion/models/urlmodel.py @@ -75,6 +75,8 @@ class UrlCompletionModel(base.BaseCompletionModel): objreg.get('config').changed.connect(self.reformat_timestamps) + self.column_widths = (40, 50, 10) + def _fmt_atime(self, atime): """Format an atime to a human-readable string.""" fmt = config.get('completion', 'timestamp-format') diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 7a1f4f236..19dd18db2 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -398,6 +398,11 @@ def data(readonly=False): "Whether to shrink the completion to be smaller than the " "configured size if there are no scrollbars."), + ('base-column-width-percentages', + SettingValue(typ.IntList(), '20,70,10'), + "List of width percentages of the base completion columns." + "These can be overridden by child classes."), + readonly=readonly )),