Merge branch 'acogneau-dynamic-column-widths'
This commit is contained in:
commit
3e2aafa7a4
@ -48,6 +48,8 @@ Changed
|
||||
mode and is not hidden anymore.
|
||||
- `minimal_webkit_testbrowser.py` now has a `--webengine` switch to test
|
||||
QtWebEngine if it's installed.
|
||||
- The column width percentages for the completion view now depend on the
|
||||
completion model.
|
||||
|
||||
Fixed
|
||||
~~~~~
|
||||
|
@ -143,12 +143,12 @@ Contributors, sorted by the number of commits in descending order:
|
||||
* Lamar Pavel
|
||||
* Austin Anderson
|
||||
* Artur Shaik
|
||||
* Alexander Cogneau
|
||||
* ZDarian
|
||||
* Peter Vilim
|
||||
* John ShaggyTwoDope Jenkins
|
||||
* Daniel
|
||||
* Jimmy
|
||||
* Alexander Cogneau
|
||||
* Zach-Button
|
||||
* rikn00
|
||||
* Patric Schmitz
|
||||
|
@ -28,6 +28,7 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QItemSelectionModel
|
||||
|
||||
from qutebrowser.config import config, style
|
||||
from qutebrowser.completion import completiondelegate, completer
|
||||
from qutebrowser.completion.models import base
|
||||
from qutebrowser.utils import qtutils, objreg, utils
|
||||
|
||||
|
||||
@ -38,15 +39,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 +81,6 @@ class CompletionView(QTreeView):
|
||||
border: 0px;
|
||||
}
|
||||
"""
|
||||
COLUMN_WIDTHS = (20, 70, 10)
|
||||
|
||||
# FIXME style scrollbar
|
||||
# https://github.com/The-Compiler/qutebrowser/issues/117
|
||||
@ -103,6 +101,8 @@ class CompletionView(QTreeView):
|
||||
# FIXME handle new aliases.
|
||||
# objreg.get('config').changed.connect(self.init_command_completion)
|
||||
|
||||
self._column_widths = base.BaseCompletionModel.COLUMN_WIDTHS
|
||||
|
||||
self._delegate = completiondelegate.CompletionItemDelegate(self)
|
||||
self.setItemDelegate(self._delegate)
|
||||
style.set_register_stylesheet(self)
|
||||
@ -128,9 +128,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 +203,8 @@ class CompletionView(QTreeView):
|
||||
sel_model.deleteLater()
|
||||
for i in range(model.rowCount()):
|
||||
self.expand(model.index(i, 0))
|
||||
|
||||
self._column_widths = model.srcmodel.COLUMN_WIDTHS
|
||||
self._resize_columns()
|
||||
self.maybe_resize_completion()
|
||||
|
||||
|
@ -39,8 +39,14 @@ class BaseCompletionModel(QStandardItemModel):
|
||||
|
||||
Used for showing completions later in the CompletionView. Supports setting
|
||||
marks and adding new categories/items easily.
|
||||
|
||||
Class Attributes:
|
||||
COLUMN_WIDTHS: The width percentages of the columns used in the
|
||||
completion view.
|
||||
"""
|
||||
|
||||
COLUMN_WIDTHS = (30, 70, 0)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setColumnCount(3)
|
||||
|
@ -32,6 +32,8 @@ class SettingSectionCompletionModel(base.BaseCompletionModel):
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
COLUMN_WIDTHS = (20, 70, 10)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
cat = self.new_category("Sections")
|
||||
@ -51,6 +53,8 @@ class SettingOptionCompletionModel(base.BaseCompletionModel):
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
COLUMN_WIDTHS = (20, 70, 10)
|
||||
|
||||
def __init__(self, section, parent=None):
|
||||
super().__init__(parent)
|
||||
cat = self.new_category(section)
|
||||
@ -104,6 +108,8 @@ class SettingValueCompletionModel(base.BaseCompletionModel):
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
|
||||
COLUMN_WIDTHS = (20, 70, 10)
|
||||
|
||||
def __init__(self, section, option, parent=None):
|
||||
super().__init__(parent)
|
||||
self._section = section
|
||||
|
@ -40,6 +40,8 @@ class UrlCompletionModel(base.BaseCompletionModel):
|
||||
TEXT_COLUMN = 1
|
||||
TIME_COLUMN = 2
|
||||
|
||||
COLUMN_WIDTHS = (40, 50, 10)
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
|
53
tests/completion/test_column_widths.py
Normal file
53
tests/completion/test_column_widths.py
Normal file
@ -0,0 +1,53 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2015 Alexander Cogneau <alexander.cogneau@gmail.com>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Tests for qutebrowser.completion.models column widths"""
|
||||
|
||||
import pytest
|
||||
|
||||
from qutebrowser.completion.models.base import BaseCompletionModel
|
||||
from qutebrowser.completion.models.configmodel import (
|
||||
SettingOptionCompletionModel, SettingSectionCompletionModel,
|
||||
SettingValueCompletionModel)
|
||||
from qutebrowser.completion.models.miscmodels import (
|
||||
CommandCompletionModel, HelpCompletionModel, QuickmarkCompletionModel,
|
||||
BookmarkCompletionModel, SessionCompletionModel)
|
||||
from qutebrowser.completion.models.urlmodel import UrlCompletionModel
|
||||
|
||||
|
||||
class TestColumnWidths:
|
||||
|
||||
"""Tests for the column widths of the completion models"""
|
||||
|
||||
CLASSES = [BaseCompletionModel, SettingOptionCompletionModel,
|
||||
SettingOptionCompletionModel, SettingSectionCompletionModel,
|
||||
SettingValueCompletionModel, CommandCompletionModel,
|
||||
HelpCompletionModel, QuickmarkCompletionModel,
|
||||
BookmarkCompletionModel, SessionCompletionModel,
|
||||
UrlCompletionModel]
|
||||
|
||||
@pytest.mark.parametrize("model", CLASSES)
|
||||
def test_list_size(self, model):
|
||||
"""Test if there are 3 items in the COLUMN_WIDTHS property"""
|
||||
assert len(model.COLUMN_WIDTHS) == 3
|
||||
|
||||
@pytest.mark.parametrize("model", CLASSES)
|
||||
def test_column_width_sum(self, model):
|
||||
"""Test if the sum of the widths asserts to 100"""
|
||||
assert sum(model.COLUMN_WIDTHS) == 100
|
Loading…
Reference in New Issue
Block a user