Implement scroll.pos_perc for QtWebEngine

This commit is contained in:
Florian Bruhin 2016-07-04 16:47:50 +02:00
parent a1f4dcd542
commit 9c5143786c
3 changed files with 19 additions and 3 deletions

View File

@ -54,9 +54,21 @@ class WebEngineCaret(tab.AbstractCaret):
class WebEngineScroller(tab.AbstractScroller):
## TODO
def pos_perc(self):
page = self._widget.page()
try:
size = page.contentsSize()
pos = page.scrollPosition()
except AttributeError:
# Added in Qt 5.7
return (None, None)
else:
# FIXME is this correct?
perc_x = 100 / size.width() * pos.x()
perc_y = 100 / size.height() * pos.y()
return (perc_x, perc_y)
pass
## TODO
class WebEngineHistory(tab.AbstractHistory):

View File

@ -46,6 +46,8 @@ class Percentage(textbase.TextBase):
self.setText('[top]')
elif y == 100:
self.setText('[bot]')
elif y is None:
self.setText('[???]')
else:
self.setText('[{:2}%]'.format(y))

View File

@ -128,7 +128,9 @@ class TabWidget(QTabWidget):
fields['host'] = ''
y = widget.scroll.pos_perc()[1]
if y <= 0:
if y is None:
scroll_pos = '???'
elif y <= 0:
scroll_pos = 'top'
elif y >= 100:
scroll_pos = 'bot'