diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index 1358bbb56..6bab39b74 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -405,6 +405,29 @@ class CurCommandDispatcher(QObject): tab = self._tabs.currentWidget() tab.zoom(-count) + @cmdutils.register(instance='mainwindow.tabs.cur', name='zoom') + def zoom_perc(self, zoom=None, count=None): + """Zoom the current tab to [count] or 100 percent. + + Args: + count: How many steps to take. + """ + if zoom is not None and count is not None: + message.error("Either argument or count must be given!") + return + if zoom is not None: + try: + level = int(zoom) + except ValueError: + message.error("Argument {} must be an integer!".format(zoom)) + return + elif count is not None: + level = count + else: + level = 100 + tab = self._tabs.currentWidget() + tab.zoom_perc(level) + @cmdutils.register(instance='mainwindow.tabs.cur', split=False) def spawn(self, cmd): """Spawn a command in a shell. {} gets replaced by the current URL. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 3188efa24..7d7f8da6d 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -595,6 +595,7 @@ DATA = OrderedDict([ ('sk', 'set keybind'), ('-', 'zoomout'), ('+', 'zoomin'), + ('=', 'zoom'), ('[[', 'prevpage'), (']]', 'nextpage'), ('{{', 'tabprevpage'), diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index 58a53601f..83c449651 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -170,6 +170,18 @@ class WebView(QWebView): self.urlChanged.emit(urlutils.qurl(u)) return self.load(u) + def zoom_perc(self, perc, fuzzyval=True): + """Zoom to a given zoom percentage. + + Args: + perc: The zoom percentage as int. + fuzzyval: Whether to set the NeighborLists fuzzyval. + """ + if fuzzyval: + self._zoom.fuzzyval = int(perc) + self.setZoomFactor(float(perc) / 100) + message.info("Zoom level: {}%".format(perc)) + def zoom(self, offset): """Increase/Decrease the zoom level. @@ -177,8 +189,7 @@ class WebView(QWebView): offset: The offset in the zoom level list. """ level = self._zoom.getitem(offset) - self.setZoomFactor(float(level) / 100) - message.info("Zoom level: {}%".format(level)) + self.zoom_perc(level, fuzzyval=False) def shutdown(self, callback=None): """Shut down the tab cleanly and remove it.