add scroll_pos to window title && fix signals
This commit is contained in:
parent
717298e423
commit
1b6860b748
@ -299,7 +299,7 @@ def data(readonly=False):
|
||||
|
||||
('window-title-format',
|
||||
SettingValue(typ.FormatString(fields=['perc', 'perc_raw', 'title',
|
||||
'title_sep', 'id']),
|
||||
'title_sep', 'id', 'scroll_pos']),
|
||||
'{perc}{title}{title_sep}qutebrowser'),
|
||||
"The format to use for the window title. The following "
|
||||
"placeholders are defined:\n\n"
|
||||
@ -308,7 +308,8 @@ def data(readonly=False):
|
||||
"* `{title}`: The title of the current web page\n"
|
||||
"* `{title_sep}`: The string ` - ` if a title is set, empty "
|
||||
"otherwise.\n"
|
||||
"* `{id}`: The internal window ID of this window."),
|
||||
"* `{id}`: The internal window ID of this window."
|
||||
"* `{scroll_pos}`: The page scroll position."),
|
||||
|
||||
('hide-mouse-cursor',
|
||||
SettingValue(typ.Bool(), 'false'),
|
||||
@ -543,7 +544,8 @@ def data(readonly=False):
|
||||
"* `{title_sep}`: The string ` - ` if a title is set, empty "
|
||||
"otherwise.\n"
|
||||
"* `{index}`: The index of this tab.\n"
|
||||
"* `{id}`: The internal tab ID of this tab."),
|
||||
"* `{id}`: The internal tab ID of this tab."
|
||||
"* `{scroll_pos}`: The page scroll position."),
|
||||
|
||||
('mousewheel-tab-switching',
|
||||
SettingValue(typ.Bool(), 'true'),
|
||||
|
@ -165,6 +165,15 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
fields['title'] = tabtitle
|
||||
fields['title_sep'] = ' - ' if tabtitle else ''
|
||||
fields['id'] = self._win_id
|
||||
y = widget.scroll_pos[1]
|
||||
if y <= 0:
|
||||
scroll_pos = 'top'
|
||||
elif y >= 100:
|
||||
scroll_pos = 'bot'
|
||||
else:
|
||||
scroll_pos = '{:2}%'.format(y)
|
||||
|
||||
fields['scroll_pos'] = str(scroll_pos)
|
||||
fmt = config.get('ui', 'window-title-format')
|
||||
self.window().setWindowTitle(fmt.format(**fields))
|
||||
|
||||
@ -185,6 +194,7 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
self._filter.create(self.cur_statusbar_message, tab))
|
||||
tab.scroll_pos_changed.connect(
|
||||
self._filter.create(self.cur_scroll_perc_changed, tab))
|
||||
tab.scroll_pos_changed.connect(self.on_scroll_pos_changed)
|
||||
tab.url_text_changed.connect(
|
||||
self._filter.create(self.cur_url_text_changed, tab))
|
||||
tab.load_status_changed.connect(
|
||||
@ -577,6 +587,12 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
if idx == self.currentIndex():
|
||||
self.update_window_title()
|
||||
|
||||
@pyqtSlot(int, int)
|
||||
def on_scroll_pos_changed(self, x, y):
|
||||
"""Update tab and window title when scroll position changed."""
|
||||
self.update_window_title()
|
||||
self.update_tab_titles()
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizeEvent of QWidget to emit a resized signal afterwards.
|
||||
|
||||
|
@ -120,7 +120,7 @@ class TabWidget(QTabWidget):
|
||||
else:
|
||||
scroll_pos = '{:2}%'.format(y)
|
||||
|
||||
fields['scroll_pos'] = '{}'.format(scroll_pos)
|
||||
fields['scroll_pos'] = str(scroll_pos)
|
||||
|
||||
fmt = config.get('tabs', 'title-format')
|
||||
self.tabBar().setTabText(idx, fmt.format(**fields))
|
||||
@ -167,7 +167,6 @@ class TabWidget(QTabWidget):
|
||||
text = text_or_empty
|
||||
new_idx = super().addTab(page, icon, '')
|
||||
self.set_page_title(new_idx, text)
|
||||
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
|
||||
return new_idx
|
||||
|
||||
def insertTab(self, idx, page, icon_or_text, text_or_empty=None):
|
||||
@ -198,7 +197,6 @@ class TabWidget(QTabWidget):
|
||||
text = text_or_empty
|
||||
new_idx = super().insertTab(idx, page, icon, '')
|
||||
self.set_page_title(new_idx, text)
|
||||
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
|
||||
return new_idx
|
||||
|
||||
@pyqtSlot(int)
|
||||
|
Loading…
Reference in New Issue
Block a user