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
autostart/config
statusbar with widgets

View File

@ -111,22 +111,22 @@ class QuteBrowser(QApplication):
args = argv[1:]
handlers = {
'open': self.mainwindow.tabs.openurl,
'tabopen': self.mainwindow.tabs.tabopen,
'quit': self.quit,
'tabclose': self.mainwindow.tabs.cur_close,
'tabprev': self.mainwindow.tabs.switch_prev,
'tabnext': self.mainwindow.tabs.switch_next,
'reload': self.mainwindow.tabs.cur_reload,
'stop': self.mainwindow.tabs.cur_stop,
'back': self.mainwindow.tabs.cur_back,
'forward': self.mainwindow.tabs.cur_forward,
'print': self.mainwindow.tabs.cur_print,
'scroll': self.mainwindow.tabs.cur_scroll,
'scrollstart': self.mainwindow.tabs.cur_scroll_start,
'scrollend': self.mainwindow.tabs.cur_scroll_end,
'undo': self.mainwindow.tabs.undo_close,
'pyeval': self.pyeval,
'open': self.mainwindow.tabs.openurl,
'tabopen': self.mainwindow.tabs.tabopen,
'quit': self.quit,
'tabclose': self.mainwindow.tabs.cur_close,
'tabprev': self.mainwindow.tabs.switch_prev,
'tabnext': self.mainwindow.tabs.switch_next,
'reload': self.mainwindow.tabs.cur_reload,
'stop': self.mainwindow.tabs.cur_stop,
'back': self.mainwindow.tabs.cur_back,
'forward': self.mainwindow.tabs.cur_forward,
'print': self.mainwindow.tabs.cur_print,
'scroll': self.mainwindow.tabs.cur_scroll,
'scrollpercentx': self.mainwindow.tabs.cur_scroll_percent_x,
'scrollpercenty': self.mainwindow.tabs.cur_scroll_percent_y,
'undo': self.mainwindow.tabs.undo_close,
'pyeval': self.pyeval,
}
handler = handlers[cmd]

View File

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

View File

@ -92,18 +92,33 @@ class TabbedBrowser(TabWidget):
dy = int(count) * int(dy)
self.currentWidget().page().mainFrame().scroll(dx, dy)
def cur_scroll_start(self):
"""Scrolls the current tab to the beginning"""
frame = self.currentWidget().page().mainFrame()
cur_pos = frame.scrollPosition()
frame.setScrollPosition(QPoint(cur_pos.x(), 0))
def cur_scroll_end(self):
"""Scrolls the current tab to the end"""
def cur_scroll_percent_x(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 = 0
elif perc is None:
perc = count
frame = self.currentWidget().page().mainFrame()
cur_pos = frame.scrollPosition()
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):
"""Switches to the previous tab"""