From 029813c8eb5b94ea41fab103fe66bf002fd9421e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 13 Feb 2014 10:28:09 +0100 Subject: [PATCH] Implement page-wise scrolling. --- TODO | 12 ------------ qutebrowser/app.py | 1 + qutebrowser/commands/commands.py | 16 ++++++++++++++++ qutebrowser/utils/config.py | 5 ++++- qutebrowser/widgets/browser.py | 23 +++++++++-------------- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/TODO b/TODO index c7bd96d9c..97a3cbac1 100644 --- a/TODO +++ b/TODO @@ -60,18 +60,6 @@ https://code.google.com/p/devicenzo/source/browse/trunk/devicenzo.py Keybinding stuff (from dwb) =========================== -[n]C-f -Scroll [n] pages down (command: scroll_page_down, aliases: pagedown). - -[n]C-b -Scroll [n] pages up (command: scroll_page_up, aliases: pageup). - -[n]C-d -Scroll [n] half pages down (command: scroll_halfpage_down, aliases: halfdown). - -[n]C-u -Scroll [n] half pages up (command: scroll_halfpage_up, aliases: halfup). - xo Open url in a new tab in background, the argument $URI will be repaced with the current uri (command: backopen, aliases: bopen ). diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 318fa87bd..aca39801e 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -271,6 +271,7 @@ class QuteBrowser(QApplication): 'forward': self.mainwindow.tabs.cur_forward, 'print': self.mainwindow.tabs.cur_print, 'scroll': self.mainwindow.tabs.cur_scroll, + 'scroll_page': self.mainwindow.tabs.cur_scroll_page, 'scroll_perc_x': self.mainwindow.tabs.cur_scroll_percent_x, 'scroll_perc_y': self.mainwindow.tabs.cur_scroll_percent_y, 'undo': self.mainwindow.tabs.undo_close, diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index c321f93cb..32bfc3bfa 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -162,6 +162,22 @@ class Scroll(Command): hide = True +class ScrollPage(Command): + + """Scroll N pages up/down. + + arg 1: pages in x-direction + arg 2: pages in y-direction + count: multiplicator + + """ + + nargs = 2 + count = True + hide = True + name = 'scroll_page' + + class Undo(Command): """Undo closing a tab.""" diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index e4bb52d60..39be8a377 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -37,7 +37,6 @@ fontdict = {} default_config = """ [general] show_completion = true -space_scroll = 200 ignorecase = true wrapsearch = true startpage = http://www.duckduckgo.com/ @@ -93,6 +92,10 @@ PP = tabpaste sel @Ctrl-Shift-T@ = undo @Ctrl-W@ = tabclose @Ctrl-T@ = tabopen about:blank +@Ctrl-F@ = scroll_page 0 1 +@Ctrl-B@ = scroll_page 0 -1 +@Ctrl-D@ = scroll_page 0 0.5 +@Ctrl-U@ = scroll_page 0 -0.5 [colors] completion.fg = #333333 diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 5990f2c92..b389e552b 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -32,7 +32,6 @@ from PyQt5.QtPrintSupport import QPrintPreviewDialog from PyQt5.QtWebKitWidgets import QWebView, QWebPage import qutebrowser.utils.about as about -import qutebrowser.utils.config as config import qutebrowser.utils.url as urlutils from qutebrowser.widgets.tabbar import TabWidget from qutebrowser.utils.signals import dbg_signal, SignalCache @@ -73,7 +72,7 @@ class TabbedBrowser(TabWidget): space = QShortcut(self) space.setKey(Qt.Key_Space) space.setContext(Qt.WidgetWithChildrenShortcut) - space.activated.connect(self.space_scroll) + space.activated.connect(lambda: self.cur_scroll_page(0, 1)) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) def tabopen(self, url): @@ -258,6 +257,14 @@ class TabbedBrowser(TabWidget): return frame.setScrollBarValue(orientation, int(m * perc / 100)) + def cur_scroll_page(self, mx, my, count=1): + """Scroll the frame mx pages to the right and my pages down.""" + # FIXME this might not work with HTML frames + page = self.currentWidget().page() + size = page.viewportSize() + page.mainFrame().scroll(int(count) * float(mx) * size.width(), + int(count) * float(my) * size.height()) + def switch_prev(self, count=1): """Switch to the ([count]th) previous tab. @@ -284,18 +291,6 @@ class TabbedBrowser(TabWidget): # FIXME pass - def space_scroll(self): - """Scroll when space is pressed. - - This gets called from the space QShortcut in __init__. - - """ - try: - amount = config.config['general']['space_scroll'] - except KeyError: - amount = 200 - self.cur_scroll(0, amount) - def cur_yank(self, sel=False): """Yank the current url to the clipboard or primary selection.