Reposition hints if contents size changed

This commit is contained in:
Florian Bruhin 2014-04-22 09:35:59 +02:00
parent 8d891bf168
commit 233289228b

View File

@ -21,7 +21,7 @@ import logging
import math import math
from collections import namedtuple from collections import namedtuple
from PyQt5.QtCore import pyqtSignal, QObject, QEvent, Qt from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QEvent, Qt
from PyQt5.QtGui import QMouseEvent, QClipboard from PyQt5.QtGui import QMouseEvent, QClipboard
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
@ -367,6 +367,7 @@ class HintManager(QObject):
for e, string in zip(visible_elems, strings): for e, string in zip(visible_elems, strings):
label = self._draw_label(e, string) label = self._draw_label(e, string)
self._elems[string] = ElemTuple(e, label) self._elems[string] = ElemTuple(e, label)
self._frame.contentsSizeChanged.connect(self.on_contents_size_changed)
self.hint_strings_updated.emit(strings) self.hint_strings_updated.emit(strings)
self.set_mode.emit("hint") self.set_mode.emit("hint")
@ -378,6 +379,8 @@ class HintManager(QObject):
""" """
for elem in self._elems.values(): for elem in self._elems.values():
elem.label.removeFromDocument() elem.label.removeFromDocument()
self._frame.contentsSizeChanged.disconnect(
self.on_contents_size_changed)
self._elems = {} self._elems = {}
self._target = None self._target = None
self.set_mode.emit("normal") self.set_mode.emit("normal")
@ -425,3 +428,13 @@ class HintManager(QObject):
'cmd_bgtab': 'backtabopen', 'cmd_bgtab': 'backtabopen',
} }
self._set_cmd_text(link, commands[target]) self._set_cmd_text(link, commands[target])
# pylint: disable=unused-argument
@pyqtSlot('QSize')
def on_contents_size_changed(self, size):
"""Reposition hints if contents size changed."""
for elems in self._elems.values():
rect = elems.elem.geometry()
css = self.HINT_CSS.format(left=rect.x(), top=rect.y(),
config=config.instance)
elems.label.setAttribute("style", css)