From cf2133bb9615307d8fa6061430759a1b11b14771 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 20 Feb 2014 19:50:48 +0100 Subject: [PATCH] Add zoomin/zoomout commands. --- qutebrowser/app.py | 2 ++ qutebrowser/commands/commands.py | 16 +++++++++++++ qutebrowser/qutebrowser.conf | 2 ++ qutebrowser/widgets/browser.py | 39 ++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 4e6cce6a9..ccadb32f1 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -376,6 +376,8 @@ class QuteBrowser(QApplication): 'paste': browser.paste, 'tabpaste': browser.tabpaste, 'crash': self.crash, + 'zoomin': browser.cur_zoom_in, + 'zoomout': browser.cur_zoom_out, } handler = handlers[cmd] diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index 116ce997e..fb1a34e7f 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -280,6 +280,22 @@ class TabPaste(Command): nargs = '?' +class ZoomIn(Command): + + """Zoom in in the current tab.""" + + nargs = 0 + count = True + + +class ZoomOut(Command): + + """Zoom out in the current tab.""" + + nargs = 0 + count = True + + class Crash(Command): """Simply raise an exception for debugging.""" diff --git a/qutebrowser/qutebrowser.conf b/qutebrowser/qutebrowser.conf index 635379883..faf330b32 100644 --- a/qutebrowser/qutebrowser.conf +++ b/qutebrowser/qutebrowser.conf @@ -110,6 +110,8 @@ pp = paste pP = paste sel Pp = tabpaste PP = tabpaste sel +- = zoomout ++ = zoomin @Ctrl-Q@ = quit @Ctrl-Shift-T@ = undo @Ctrl-W@ = tabclose diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index db584313e..53a6be3a0 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -539,6 +539,26 @@ class TabbedBrowser(TabWidget): self.cur_temp_message.emit('Title yanked to {}'.format( 'primary selection' if sel else 'clipboard')) + def cur_zoom_in(self, count=1): + """Zoom in in the current tab. + + Args: + count: How many steps to take. + + """ + tab = self.currentWidget() + tab.zoom(count) + + def cur_zoom_out(self, count=1): + """Zoom out in the current tab. + + Args: + count: How many steps to take. + + """ + tab = self.currentWidget() + tab.zoom(-count) + def switch_prev(self, count=1): """Switch to the ([count]th) previous tab. @@ -639,6 +659,7 @@ class BrowserTab(QWebView): Attributes: page_: The QWebPage behind the view signal_cache: The signal cache associated with the view. + _zoom: A NeighborList with the zoom levels. _scroll_pos: The old scroll position. _shutdown_callback: Callback to be called after shutdown. _open_new_tab: Whether to open a new tab for the next action. @@ -668,6 +689,10 @@ class BrowserTab(QWebView): self._shutdown_callback = None self._open_new_tab = False self._destroyed = {} + self._zoom = NeighborList( + config.config.get('general', 'zoomlevels').split(','), + default=config.config.get('general', 'defaultzoom'), + mode=NeighborList.BLOCK) self.page_ = BrowserPage(self) self.setPage(self.page_) self.signal_cache = SignalCache(uncached=['linkHovered']) @@ -704,6 +729,20 @@ class BrowserTab(QWebView): else: return self.load(u) + def zoom(self, offset): + """Increase/Decrease the zoom level. + + Args: + offset: The offset in the zoom level list. + + Emit: + temp_message: Emitted with new zoom level. + + """ + level = self._zoom.getitem(offset) + self.setZoomFactor(float(level) / 100) + self.temp_message.emit("Zoom level: {}%".format(level)) + @pyqtSlot(str) def on_link_clicked(self, url): """Handle a link.