diff --git a/TODO b/TODO index 105678b4f..9b37df6e3 100644 --- a/TODO +++ b/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) diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index b1f905f20..601073135 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -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( diff --git a/qutebrowser/widgets/_completion.py b/qutebrowser/widgets/_completion.py index 6ee1c52c5..8f1d2e509 100644 --- a/qutebrowser/widgets/_completion.py +++ b/qutebrowser/widgets/_completion.py @@ -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): diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index e2ad3095a..35c47731d 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -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