add scroll_pos to window title && fix signals

This commit is contained in:
Alexey Nabrodov 2015-09-28 19:43:50 +03:00
parent 717298e423
commit 1b6860b748
3 changed files with 22 additions and 6 deletions

View File

@ -299,7 +299,7 @@ def data(readonly=False):
('window-title-format', ('window-title-format',
SettingValue(typ.FormatString(fields=['perc', 'perc_raw', 'title', SettingValue(typ.FormatString(fields=['perc', 'perc_raw', 'title',
'title_sep', 'id']), 'title_sep', 'id', 'scroll_pos']),
'{perc}{title}{title_sep}qutebrowser'), '{perc}{title}{title_sep}qutebrowser'),
"The format to use for the window title. The following " "The format to use for the window title. The following "
"placeholders are defined:\n\n" "placeholders are defined:\n\n"
@ -308,7 +308,8 @@ def data(readonly=False):
"* `{title}`: The title of the current web page\n" "* `{title}`: The title of the current web page\n"
"* `{title_sep}`: The string ` - ` if a title is set, empty " "* `{title_sep}`: The string ` - ` if a title is set, empty "
"otherwise.\n" "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', ('hide-mouse-cursor',
SettingValue(typ.Bool(), 'false'), SettingValue(typ.Bool(), 'false'),
@ -543,7 +544,8 @@ def data(readonly=False):
"* `{title_sep}`: The string ` - ` if a title is set, empty " "* `{title_sep}`: The string ` - ` if a title is set, empty "
"otherwise.\n" "otherwise.\n"
"* `{index}`: The index of this tab.\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', ('mousewheel-tab-switching',
SettingValue(typ.Bool(), 'true'), SettingValue(typ.Bool(), 'true'),

View File

@ -165,6 +165,15 @@ class TabbedBrowser(tabwidget.TabWidget):
fields['title'] = tabtitle fields['title'] = tabtitle
fields['title_sep'] = ' - ' if tabtitle else '' fields['title_sep'] = ' - ' if tabtitle else ''
fields['id'] = self._win_id 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') fmt = config.get('ui', 'window-title-format')
self.window().setWindowTitle(fmt.format(**fields)) self.window().setWindowTitle(fmt.format(**fields))
@ -185,6 +194,7 @@ class TabbedBrowser(tabwidget.TabWidget):
self._filter.create(self.cur_statusbar_message, tab)) self._filter.create(self.cur_statusbar_message, tab))
tab.scroll_pos_changed.connect( tab.scroll_pos_changed.connect(
self._filter.create(self.cur_scroll_perc_changed, tab)) self._filter.create(self.cur_scroll_perc_changed, tab))
tab.scroll_pos_changed.connect(self.on_scroll_pos_changed)
tab.url_text_changed.connect( tab.url_text_changed.connect(
self._filter.create(self.cur_url_text_changed, tab)) self._filter.create(self.cur_url_text_changed, tab))
tab.load_status_changed.connect( tab.load_status_changed.connect(
@ -577,6 +587,12 @@ class TabbedBrowser(tabwidget.TabWidget):
if idx == self.currentIndex(): if idx == self.currentIndex():
self.update_window_title() 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): def resizeEvent(self, e):
"""Extend resizeEvent of QWidget to emit a resized signal afterwards. """Extend resizeEvent of QWidget to emit a resized signal afterwards.

View File

@ -120,7 +120,7 @@ class TabWidget(QTabWidget):
else: else:
scroll_pos = '{:2}%'.format(y) scroll_pos = '{:2}%'.format(y)
fields['scroll_pos'] = '{}'.format(scroll_pos) fields['scroll_pos'] = str(scroll_pos)
fmt = config.get('tabs', 'title-format') fmt = config.get('tabs', 'title-format')
self.tabBar().setTabText(idx, fmt.format(**fields)) self.tabBar().setTabText(idx, fmt.format(**fields))
@ -167,7 +167,6 @@ class TabWidget(QTabWidget):
text = text_or_empty text = text_or_empty
new_idx = super().addTab(page, icon, '') new_idx = super().addTab(page, icon, '')
self.set_page_title(new_idx, text) self.set_page_title(new_idx, text)
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
return new_idx return new_idx
def insertTab(self, idx, page, icon_or_text, text_or_empty=None): def insertTab(self, idx, page, icon_or_text, text_or_empty=None):
@ -198,7 +197,6 @@ class TabWidget(QTabWidget):
text = text_or_empty text = text_or_empty
new_idx = super().insertTab(idx, page, icon, '') new_idx = super().insertTab(idx, page, icon, '')
self.set_page_title(new_idx, text) self.set_page_title(new_idx, text)
page.scroll_pos_changed.connect(lambda: self.update_tab_title(new_idx))
return new_idx return new_idx
@pyqtSlot(int) @pyqtSlot(int)