Shrink completion if configured to do so
This commit is contained in:
parent
c7b2ff4db5
commit
58c1646e9b
1
TODO
1
TODO
@ -55,7 +55,6 @@ Improvements / minor features
|
||||
- if a cookie is a http-only cookie domain is prepended with a #HttpOnly_
|
||||
- Zoom with ctrl + mousewheel
|
||||
- search highlighting
|
||||
- max height for completion (be smaller if possible)
|
||||
- vertical tabbar
|
||||
- reload config command
|
||||
- config changed signals for sections (optimization)
|
||||
|
@ -270,6 +270,11 @@ DATA = OrderedDict([
|
||||
SettingValue(types.Bool(), 'true'),
|
||||
"Whether to move on to the next part when there's only one possible "
|
||||
"completion left."),
|
||||
|
||||
('shrink',
|
||||
SettingValue(types.Bool(), 'false'),
|
||||
"Whether to shrink the completion to be smaller than the configured "
|
||||
"size if there are no scrollbars."),
|
||||
)),
|
||||
|
||||
('input', sect.KeyValue(
|
||||
|
@ -68,6 +68,7 @@ class CompletionView(QTreeView):
|
||||
arg 1: True if the text should be set
|
||||
immediately, without continuing
|
||||
completing the current field.
|
||||
resize_completion: Emitted when the completion should be resized.
|
||||
"""
|
||||
|
||||
STYLESHEET = """
|
||||
@ -103,6 +104,7 @@ class CompletionView(QTreeView):
|
||||
# FIXME style scrollbar
|
||||
|
||||
change_completed_part = pyqtSignal(str, bool)
|
||||
resize_completion = pyqtSignal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
@ -276,6 +278,9 @@ class CompletionView(QTreeView):
|
||||
self._model = model
|
||||
self.expandAll()
|
||||
self._resize_columns()
|
||||
self._model.rowsRemoved.connect(self.resize_completion)
|
||||
self._model.rowsInserted.connect(self.resize_completion)
|
||||
self.resize_completion.emit()
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, option):
|
||||
|
@ -72,10 +72,12 @@ class MainWindow(QWidget):
|
||||
self._vbox.addWidget(self.tabs)
|
||||
|
||||
self.completion = CompletionView(self)
|
||||
self.completion.resize_completion.connect(self.resize_completion)
|
||||
|
||||
self.status = StatusBar()
|
||||
self._vbox.addWidget(self.status)
|
||||
|
||||
self.resize_completion()
|
||||
#self.retranslateUi(MainWindow)
|
||||
#self.tabWidget.setCurrentIndex(0)
|
||||
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
@ -87,17 +89,26 @@ class MainWindow(QWidget):
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, option):
|
||||
"""Resize completion if config changed."""
|
||||
if section == 'completion' and option == 'height':
|
||||
if section == 'completion' and option in ['height', 'shrink']:
|
||||
self.resize_completion()
|
||||
|
||||
@pyqtSlot()
|
||||
def resize_completion(self):
|
||||
"""Adjust completion according to config."""
|
||||
# Get the configured height/percentage.
|
||||
confheight = str(config.get('completion', 'height'))
|
||||
if confheight.endswith('%'):
|
||||
perc = int(confheight.rstrip('%'))
|
||||
height = self.height() * perc / 100
|
||||
else:
|
||||
height = int(confheight)
|
||||
# Shrink to content size if needed and shrinking is enabled
|
||||
if config.get('completion', 'shrink'):
|
||||
contents_height = (
|
||||
self.completion.viewportSizeHint().height() +
|
||||
self.completion.horizontalScrollBar().sizeHint().height())
|
||||
if contents_height <= height:
|
||||
height = contents_height
|
||||
# hpoint now would be the bottom-left edge of the widget if it was on
|
||||
# the top of the main window.
|
||||
topleft_y = self.height() - self.status.height() - height
|
||||
|
Loading…
Reference in New Issue
Block a user