Implement ScrollPercent{X,Y}, gg and G with count

This commit is contained in:
Florian Bruhin 2014-01-20 17:59:01 +01:00
parent ac570be7aa
commit fdf765b267
4 changed files with 46 additions and 30 deletions

View File

@ -1,4 +1,3 @@
go-percent
:bind :bind
autostart/config autostart/config
statusbar with widgets statusbar with widgets

View File

@ -123,8 +123,8 @@ class QuteBrowser(QApplication):
'forward': self.mainwindow.tabs.cur_forward, 'forward': self.mainwindow.tabs.cur_forward,
'print': self.mainwindow.tabs.cur_print, 'print': self.mainwindow.tabs.cur_print,
'scroll': self.mainwindow.tabs.cur_scroll, 'scroll': self.mainwindow.tabs.cur_scroll,
'scrollstart': self.mainwindow.tabs.cur_scroll_start, 'scrollpercentx': self.mainwindow.tabs.cur_scroll_percent_x,
'scrollend': self.mainwindow.tabs.cur_scroll_end, 'scrollpercenty': self.mainwindow.tabs.cur_scroll_percent_y,
'undo': self.mainwindow.tabs.undo_close, 'undo': self.mainwindow.tabs.undo_close,
'pyeval': self.pyeval, 'pyeval': self.pyeval,
} }

View File

@ -59,11 +59,13 @@ class Scroll(Command):
class Undo(Command): class Undo(Command):
nargs = 0 nargs = 0
class ScrollStart(Command): class ScrollPercentX(Command):
nargs = 0 nargs = '?'
count = True
class ScrollEnd(Command): class ScrollPercentY(Command):
nargs = 0 nargs = '?'
count = True
class PyEval(Command): class PyEval(Command):
nargs = 1 nargs = 1

View File

@ -92,18 +92,33 @@ class TabbedBrowser(TabWidget):
dy = int(count) * int(dy) dy = int(count) * int(dy)
self.currentWidget().page().mainFrame().scroll(dx, dy) self.currentWidget().page().mainFrame().scroll(dx, dy)
def cur_scroll_start(self): def cur_scroll_percent_x(self, perc=None, count=None):
"""Scrolls the current tab to the beginning""" """Scrolls the current tab to a specific percent of the page.
frame = self.currentWidget().page().mainFrame() Accepts percentage either as argument, or as count.
cur_pos = frame.scrollPosition() """
frame.setScrollPosition(QPoint(cur_pos.x(), 0)) if perc is None and count is None:
perc = 0
def cur_scroll_end(self): elif perc is None:
"""Scrolls the current tab to the end""" perc = count
frame = self.currentWidget().page().mainFrame() frame = self.currentWidget().page().mainFrame()
cur_pos = frame.scrollPosition() cur_pos = frame.scrollPosition()
size = frame.contentsSize() size = frame.contentsSize()
frame.setScrollPosition(QPoint(cur_pos.x(), size.height())) x = size.width() / 100 * int(perc)
frame.setScrollPosition(QPoint(x, cur_pos.y()))
def cur_scroll_percent_y(self, perc=None, count=None):
"""Scrolls the current tab to a specific percent of the page
Accepts percentage either as argument, or as count.
"""
if perc is None and count is None:
perc = 100
elif perc is None:
perc = count
frame = self.currentWidget().page().mainFrame()
cur_pos = frame.scrollPosition()
size = frame.contentsSize()
y = size.height() / 100 * int(perc)
frame.setScrollPosition(QPoint(cur_pos.x(), y))
def switch_prev(self): def switch_prev(self):
"""Switches to the previous tab""" """Switches to the previous tab"""