Add a column_widths property to the base class for completion models.
This commit is contained in:
parent
0acbd77ada
commit
5c2d3ec96a
@ -38,15 +38,13 @@ class CompletionView(QTreeView):
|
|||||||
Based on QTreeView but heavily customized so root elements show as category
|
Based on QTreeView but heavily customized so root elements show as category
|
||||||
headers, and children show as flat list.
|
headers, and children show as flat list.
|
||||||
|
|
||||||
Class attributes:
|
|
||||||
COLUMN_WIDTHS: A list of column widths, in percent.
|
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
enabled: Whether showing the CompletionView is enabled.
|
enabled: Whether showing the CompletionView is enabled.
|
||||||
_win_id: The ID of the window this CompletionView is associated with.
|
_win_id: The ID of the window this CompletionView is associated with.
|
||||||
_height: The height to use for the CompletionView.
|
_height: The height to use for the CompletionView.
|
||||||
_height_perc: Either None or a percentage if height should be relative.
|
_height_perc: Either None or a percentage if height should be relative.
|
||||||
_delegate: The item delegate used.
|
_delegate: The item delegate used.
|
||||||
|
column_widths: A list of column widths, in percent.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
resize_completion: Emitted when the completion should be resized.
|
resize_completion: Emitted when the completion should be resized.
|
||||||
@ -82,7 +80,6 @@ class CompletionView(QTreeView):
|
|||||||
border: 0px;
|
border: 0px;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
COLUMN_WIDTHS = (20, 70, 10)
|
|
||||||
|
|
||||||
# FIXME style scrollbar
|
# FIXME style scrollbar
|
||||||
# https://github.com/The-Compiler/qutebrowser/issues/117
|
# https://github.com/The-Compiler/qutebrowser/issues/117
|
||||||
@ -103,6 +100,8 @@ class CompletionView(QTreeView):
|
|||||||
# FIXME handle new aliases.
|
# FIXME handle new aliases.
|
||||||
# objreg.get('config').changed.connect(self.init_command_completion)
|
# 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._delegate = completiondelegate.CompletionItemDelegate(self)
|
||||||
self.setItemDelegate(self._delegate)
|
self.setItemDelegate(self._delegate)
|
||||||
style.set_register_stylesheet(self)
|
style.set_register_stylesheet(self)
|
||||||
@ -128,9 +127,9 @@ class CompletionView(QTreeView):
|
|||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
|
|
||||||
def _resize_columns(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()
|
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():
|
if self.verticalScrollBar().isVisible():
|
||||||
pixel_widths[-1] -= self.style().pixelMetric(
|
pixel_widths[-1] -= self.style().pixelMetric(
|
||||||
QStyle.PM_ScrollBarExtent) + 5
|
QStyle.PM_ScrollBarExtent) + 5
|
||||||
@ -203,6 +202,10 @@ class CompletionView(QTreeView):
|
|||||||
sel_model.deleteLater()
|
sel_model.deleteLater()
|
||||||
for i in range(model.rowCount()):
|
for i in range(model.rowCount()):
|
||||||
self.expand(model.index(i, 0))
|
self.expand(model.index(i, 0))
|
||||||
|
|
||||||
|
if model.column_widths:
|
||||||
|
self.column_widths = model.column_widths
|
||||||
|
|
||||||
self._resize_columns()
|
self._resize_columns()
|
||||||
self.maybe_resize_completion()
|
self.maybe_resize_completion()
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ from PyQt5.QtCore import Qt
|
|||||||
from PyQt5.QtGui import QStandardItemModel, QStandardItem
|
from PyQt5.QtGui import QStandardItemModel, QStandardItem
|
||||||
|
|
||||||
from qutebrowser.utils import usertypes, qtutils
|
from qutebrowser.utils import usertypes, qtutils
|
||||||
|
from qutebrowser.config import config
|
||||||
|
|
||||||
|
|
||||||
Role = usertypes.enum('Role', ['sort', 'userdata'], start=Qt.UserRole,
|
Role = usertypes.enum('Role', ['sort', 'userdata'], start=Qt.UserRole,
|
||||||
@ -44,6 +45,8 @@ class BaseCompletionModel(QStandardItemModel):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setColumnCount(3)
|
self.setColumnCount(3)
|
||||||
|
self.column_widths = config.get('completion',
|
||||||
|
'base-column-width-percentages')
|
||||||
self.columns_to_filter = [0]
|
self.columns_to_filter = [0]
|
||||||
|
|
||||||
def new_category(self, name, sort=None):
|
def new_category(self, name, sort=None):
|
||||||
|
@ -53,6 +53,7 @@ class CompletionFilterModel(QSortFilterProxyModel):
|
|||||||
else:
|
else:
|
||||||
self.setSortRole(completion.Role.sort)
|
self.setSortRole(completion.Role.sort)
|
||||||
self._sort_order = dumb_sort
|
self._sort_order = dumb_sort
|
||||||
|
self.column_widths = source.column_widths
|
||||||
|
|
||||||
def set_pattern(self, val):
|
def set_pattern(self, val):
|
||||||
"""Setter for pattern.
|
"""Setter for pattern.
|
||||||
|
@ -75,6 +75,8 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
|||||||
|
|
||||||
objreg.get('config').changed.connect(self.reformat_timestamps)
|
objreg.get('config').changed.connect(self.reformat_timestamps)
|
||||||
|
|
||||||
|
self.column_widths = (40, 50, 10)
|
||||||
|
|
||||||
def _fmt_atime(self, atime):
|
def _fmt_atime(self, atime):
|
||||||
"""Format an atime to a human-readable string."""
|
"""Format an atime to a human-readable string."""
|
||||||
fmt = config.get('completion', 'timestamp-format')
|
fmt = config.get('completion', 'timestamp-format')
|
||||||
|
@ -398,6 +398,11 @@ def data(readonly=False):
|
|||||||
"Whether to shrink the completion to be smaller than the "
|
"Whether to shrink the completion to be smaller than the "
|
||||||
"configured size if there are no scrollbars."),
|
"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
|
readonly=readonly
|
||||||
)),
|
)),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user