Round correct edge for keyhint with top statusbar

This commit is contained in:
Florian Bruhin 2016-09-22 17:29:25 +02:00
parent e04e6c51d1
commit 17ceba5ce4

View File

@ -45,28 +45,19 @@ class KeyHintView(QLabel):
update_geometry: Emitted when this widget should be resized/positioned. update_geometry: Emitted when this widget should be resized/positioned.
""" """
STYLESHEET = """
QLabel {
font: {{ font['keyhint'] }};
color: {{ color['keyhint.fg'] }};
background-color: {{ color['keyhint.bg'] }};
padding: 6px;
border-top-right-radius: 6px;
}
"""
update_geometry = pyqtSignal() update_geometry = pyqtSignal()
def __init__(self, win_id, parent=None): def __init__(self, win_id, parent=None):
super().__init__(parent) super().__init__(parent)
self.setTextFormat(Qt.RichText) self.setTextFormat(Qt.RichText)
self._win_id = win_id self._win_id = win_id
style.set_register_stylesheet(self)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum) self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Minimum)
self.hide() self.hide()
self._show_timer = usertypes.Timer(self, 'keyhint_show') self._show_timer = usertypes.Timer(self, 'keyhint_show')
self._show_timer.setInterval(500) self._show_timer.setInterval(500)
self._show_timer.timeout.connect(self.show) self._show_timer.timeout.connect(self.show)
style.set_register_stylesheet(self,
generator=self._generate_stylesheet)
def __repr__(self): def __repr__(self):
return utils.get_repr(self, win_id=self._win_id) return utils.get_repr(self, win_id=self._win_id)
@ -76,6 +67,22 @@ class KeyHintView(QLabel):
self.update_geometry.emit() self.update_geometry.emit()
super().showEvent(e) super().showEvent(e)
def _generate_stylesheet(self):
"""Generate a stylesheet with the right edge rounded."""
stylesheet = """
QLabel {
font: {{ font['keyhint'] }};
color: {{ color['keyhint.fg'] }};
background-color: {{ color['keyhint.bg'] }};
padding: 6px;
border-EDGE-radius: 6px;
}
"""
if config.get('ui', 'status-position') == 'top':
return stylesheet.replace('EDGE', 'bottom-right')
else:
return stylesheet.replace('EDGE', 'top-right')
@pyqtSlot(str) @pyqtSlot(str)
def update_keyhint(self, modename, prefix): def update_keyhint(self, modename, prefix):
"""Show hints for the given prefix (or hide if prefix is empty). """Show hints for the given prefix (or hide if prefix is empty).