From 6d709d9fd8db7f2dae50d692d0b70a2cf5f522f9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 18 Feb 2014 19:05:56 +0100 Subject: [PATCH] Allow completion widget height to be configured in % --- qutebrowser/qutebrowser.conf | 5 +++-- qutebrowser/widgets/browser.py | 13 +++++++++++++ qutebrowser/widgets/completion.py | 24 ++++++++++++++++++++++-- qutebrowser/widgets/mainwindow.py | 1 + 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/qutebrowser/qutebrowser.conf b/qutebrowser/qutebrowser.conf index d99106b2d..1edcad69d 100644 --- a/qutebrowser/qutebrowser.conf +++ b/qutebrowser/qutebrowser.conf @@ -16,7 +16,8 @@ [general] # show_completion: bool, whether to show the autocompletion window or not. -# completion_height: the height of the completion, in pixels +# completion_height: the height of the completion, in pixels or as percentage +# of the browser size. # ignorecase: bool, whether to do case-insensitive searching. # wrapsearch: bool, whether to wrap search to the top when arriving at the end. # startpage: The default pages to open at the start, multiple pages can be @@ -27,7 +28,7 @@ # dns: Use DNS matching (might be slow) # false: Never search automatically show_completion = true -completion_height = 400 +completion_height = 50% ignorecase = true wrapsearch = true startpage = http://www.duckduckgo.com/ diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 7752c921d..1f09bf6f2 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -76,6 +76,9 @@ class TabbedBrowser(TabWidget): arg: The QKeyEvent leading to the keypress. shutdown_complete: The shuttdown is completed. quit: The last tab was closed, quit application. + resized: Emitted when the browser window has resized, so the completion + widget can adjust its size to it. + arg: The new size. """ @@ -90,6 +93,7 @@ class TabbedBrowser(TabWidget): keypress = pyqtSignal('QKeyEvent') shutdown_complete = pyqtSignal() quit = pyqtSignal() + resized = pyqtSignal('QRect') def __init__(self, parent=None): super().__init__(parent) @@ -479,6 +483,15 @@ class TabbedBrowser(TabWidget): self.keypress.emit(e) super().keyPressEvent(e) + def resizeEvent(self, e): + """Extend resizeEvent of QWidget to emit a resized signal afterwards. + + e -- The QResizeEvent. + + """ + super().resizeEvent(e) + self.resized.emit(self.geometry()) + class BrowserTab(QWebView): diff --git a/qutebrowser/widgets/completion.py b/qutebrowser/widgets/completion.py index 48d8107b1..34fe1e783 100644 --- a/qutebrowser/widgets/completion.py +++ b/qutebrowser/widgets/completion.py @@ -52,6 +52,7 @@ class CompletionView(QTreeView): _enabled: Whether showing the CompletionView is enabled. _completing: Whether we're currently completing something. _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. Signals: @@ -94,8 +95,13 @@ class CompletionView(QTreeView): def __init__(self, parent=None): super().__init__(parent) - height = int(config.config.get('general', 'completion_height')) - self._height = QPoint(0, height) + height = config.config.get('general', 'completion_height') + if height.endswith('%'): + self._height = QPoint(0, 200) # just a temporary sane value + self._height_perc = int(height.rstrip('%')) + else: + self._height = QPoint(0, int(height)) + self._height_perc = None self._enabled = config.config.getboolean('general', 'show_completion') self._completion_models = {} self._completion_models[''] = None @@ -172,6 +178,20 @@ class CompletionView(QTreeView): assert topleft.y() < bottomright.y() self.setGeometry(QRect(topleft, bottomright)) + @pyqtSlot('QRect') + def on_browser_resized(self, geom): + """Slot for the resized signal of the browser window. + + Adjust the height of the completion if it was configured as a + percentage. + + """ + if self._height_perc is None: + return + else: + height = int(geom.height() * self._height_perc / 100) + self._height = QPoint(0, height) + @pyqtSlot('QPoint') def move_to_bar(self, pos): """Move the completion area to the statusbar geometry. diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index 006037259..2e4fb5898 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -74,6 +74,7 @@ class MainWindow(QWidget): self.status.resized.connect(self.completion.resize_to_bar) self.status.moved.connect(self.completion.move_to_bar) + self.tabs.resized.connect(self.completion.on_browser_resized) self.tabs.cur_progress.connect(self.status.prog.setValue) self.tabs.cur_load_finished.connect(lambda *args: self.status.prog.hide())