Add zoom command.

This commit is contained in:
Florian Bruhin 2014-05-09 14:20:26 +02:00
parent 7868e57520
commit f7e6dc0244
3 changed files with 37 additions and 2 deletions

View File

@ -405,6 +405,29 @@ class CurCommandDispatcher(QObject):
tab = self._tabs.currentWidget()
tab.zoom(-count)
@cmdutils.register(instance='mainwindow.tabs.cur', name='zoom')
def zoom_perc(self, zoom=None, count=None):
"""Zoom the current tab to [count] or 100 percent.
Args:
count: How many steps to take.
"""
if zoom is not None and count is not None:
message.error("Either argument or count must be given!")
return
if zoom is not None:
try:
level = int(zoom)
except ValueError:
message.error("Argument {} must be an integer!".format(zoom))
return
elif count is not None:
level = count
else:
level = 100
tab = self._tabs.currentWidget()
tab.zoom_perc(level)
@cmdutils.register(instance='mainwindow.tabs.cur', split=False)
def spawn(self, cmd):
"""Spawn a command in a shell. {} gets replaced by the current URL.

View File

@ -595,6 +595,7 @@ DATA = OrderedDict([
('sk', 'set keybind'),
('-', 'zoomout'),
('+', 'zoomin'),
('=', 'zoom'),
('[[', 'prevpage'),
(']]', 'nextpage'),
('{{', 'tabprevpage'),

View File

@ -170,6 +170,18 @@ class WebView(QWebView):
self.urlChanged.emit(urlutils.qurl(u))
return self.load(u)
def zoom_perc(self, perc, fuzzyval=True):
"""Zoom to a given zoom percentage.
Args:
perc: The zoom percentage as int.
fuzzyval: Whether to set the NeighborLists fuzzyval.
"""
if fuzzyval:
self._zoom.fuzzyval = int(perc)
self.setZoomFactor(float(perc) / 100)
message.info("Zoom level: {}%".format(perc))
def zoom(self, offset):
"""Increase/Decrease the zoom level.
@ -177,8 +189,7 @@ class WebView(QWebView):
offset: The offset in the zoom level list.
"""
level = self._zoom.getitem(offset)
self.setZoomFactor(float(level) / 100)
message.info("Zoom level: {}%".format(level))
self.zoom_perc(level, fuzzyval=False)
def shutdown(self, callback=None):
"""Shut down the tab cleanly and remove it.