Allow completion widget height to be configured in %
This commit is contained in:
parent
9318558eb6
commit
6d709d9fd8
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
[general]
|
[general]
|
||||||
# show_completion: bool, whether to show the autocompletion window or not.
|
# show_completion: bool, whether to show the autocompletion window or not.
|
||||||
# completion_height: the height of the completion, in pixels
|
# completion_height: the height of the completion, in pixels or as percentage
|
||||||
|
# of the browser size.
|
||||||
# ignorecase: bool, whether to do case-insensitive searching.
|
# ignorecase: bool, whether to do case-insensitive searching.
|
||||||
# wrapsearch: bool, whether to wrap search to the top when arriving at the end.
|
# wrapsearch: bool, whether to wrap search to the top when arriving at the end.
|
||||||
# startpage: The default pages to open at the start, multiple pages can be
|
# startpage: The default pages to open at the start, multiple pages can be
|
||||||
@ -27,7 +28,7 @@
|
|||||||
# dns: Use DNS matching (might be slow)
|
# dns: Use DNS matching (might be slow)
|
||||||
# false: Never search automatically
|
# false: Never search automatically
|
||||||
show_completion = true
|
show_completion = true
|
||||||
completion_height = 400
|
completion_height = 50%
|
||||||
ignorecase = true
|
ignorecase = true
|
||||||
wrapsearch = true
|
wrapsearch = true
|
||||||
startpage = http://www.duckduckgo.com/
|
startpage = http://www.duckduckgo.com/
|
||||||
|
@ -76,6 +76,9 @@ class TabbedBrowser(TabWidget):
|
|||||||
arg: The QKeyEvent leading to the keypress.
|
arg: The QKeyEvent leading to the keypress.
|
||||||
shutdown_complete: The shuttdown is completed.
|
shutdown_complete: The shuttdown is completed.
|
||||||
quit: The last tab was closed, quit application.
|
quit: The last tab was closed, quit application.
|
||||||
|
resized: Emitted when the browser window has resized, so the completion
|
||||||
|
widget can adjust its size to it.
|
||||||
|
arg: The new size.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -90,6 +93,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
keypress = pyqtSignal('QKeyEvent')
|
keypress = pyqtSignal('QKeyEvent')
|
||||||
shutdown_complete = pyqtSignal()
|
shutdown_complete = pyqtSignal()
|
||||||
quit = pyqtSignal()
|
quit = pyqtSignal()
|
||||||
|
resized = pyqtSignal('QRect')
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -479,6 +483,15 @@ class TabbedBrowser(TabWidget):
|
|||||||
self.keypress.emit(e)
|
self.keypress.emit(e)
|
||||||
super().keyPressEvent(e)
|
super().keyPressEvent(e)
|
||||||
|
|
||||||
|
def resizeEvent(self, e):
|
||||||
|
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
||||||
|
|
||||||
|
e -- The QResizeEvent.
|
||||||
|
|
||||||
|
"""
|
||||||
|
super().resizeEvent(e)
|
||||||
|
self.resized.emit(self.geometry())
|
||||||
|
|
||||||
|
|
||||||
class BrowserTab(QWebView):
|
class BrowserTab(QWebView):
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ class CompletionView(QTreeView):
|
|||||||
_enabled: Whether showing the CompletionView is enabled.
|
_enabled: Whether showing the CompletionView is enabled.
|
||||||
_completing: Whether we're currently completing something.
|
_completing: Whether we're currently completing something.
|
||||||
_height: The height to use for the CompletionView.
|
_height: The height to use for the CompletionView.
|
||||||
|
_height_perc: Either None or a percentage if height should be relative.
|
||||||
_delegate: The item delegate used.
|
_delegate: The item delegate used.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
@ -94,8 +95,13 @@ class CompletionView(QTreeView):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
height = int(config.config.get('general', 'completion_height'))
|
height = config.config.get('general', 'completion_height')
|
||||||
self._height = QPoint(0, height)
|
if height.endswith('%'):
|
||||||
|
self._height = QPoint(0, 200) # just a temporary sane value
|
||||||
|
self._height_perc = int(height.rstrip('%'))
|
||||||
|
else:
|
||||||
|
self._height = QPoint(0, int(height))
|
||||||
|
self._height_perc = None
|
||||||
self._enabled = config.config.getboolean('general', 'show_completion')
|
self._enabled = config.config.getboolean('general', 'show_completion')
|
||||||
self._completion_models = {}
|
self._completion_models = {}
|
||||||
self._completion_models[''] = None
|
self._completion_models[''] = None
|
||||||
@ -172,6 +178,20 @@ class CompletionView(QTreeView):
|
|||||||
assert topleft.y() < bottomright.y()
|
assert topleft.y() < bottomright.y()
|
||||||
self.setGeometry(QRect(topleft, bottomright))
|
self.setGeometry(QRect(topleft, bottomright))
|
||||||
|
|
||||||
|
@pyqtSlot('QRect')
|
||||||
|
def on_browser_resized(self, geom):
|
||||||
|
"""Slot for the resized signal of the browser window.
|
||||||
|
|
||||||
|
Adjust the height of the completion if it was configured as a
|
||||||
|
percentage.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if self._height_perc is None:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
height = int(geom.height() * self._height_perc / 100)
|
||||||
|
self._height = QPoint(0, height)
|
||||||
|
|
||||||
@pyqtSlot('QPoint')
|
@pyqtSlot('QPoint')
|
||||||
def move_to_bar(self, pos):
|
def move_to_bar(self, pos):
|
||||||
"""Move the completion area to the statusbar geometry.
|
"""Move the completion area to the statusbar geometry.
|
||||||
|
@ -74,6 +74,7 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
self.status.resized.connect(self.completion.resize_to_bar)
|
self.status.resized.connect(self.completion.resize_to_bar)
|
||||||
self.status.moved.connect(self.completion.move_to_bar)
|
self.status.moved.connect(self.completion.move_to_bar)
|
||||||
|
self.tabs.resized.connect(self.completion.on_browser_resized)
|
||||||
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
self.tabs.cur_progress.connect(self.status.prog.setValue)
|
||||||
self.tabs.cur_load_finished.connect(lambda *args:
|
self.tabs.cur_load_finished.connect(lambda *args:
|
||||||
self.status.prog.hide())
|
self.status.prog.hide())
|
||||||
|
Loading…
Reference in New Issue
Block a user