diff --git a/piker/ui/_graphics/_lines.py b/piker/ui/_graphics/_lines.py index bd5b9de6..61d2fd41 100644 --- a/piker/ui/_graphics/_lines.py +++ b/piker/ui/_graphics/_lines.py @@ -49,6 +49,8 @@ class LevelLabel(YSticky): ) -> None: super().__init__(chart, *args, **kwargs) + self._pen = self.line_pen + # orientation around axis options self._orient_v = orient_v self._orient_h = orient_h @@ -101,7 +103,7 @@ class LevelLabel(YSticky): p: QtGui.QPainter, rect: QtCore.QRectF ) -> None: - p.setPen(self.line_pen) + p.setPen(self._pen) if self._orient_v == 'bottom': lp, rp = rect.topLeft(), rect.topRight() @@ -111,6 +113,15 @@ class LevelLabel(YSticky): p.drawLine(lp.x(), lp.y(), rp.x(), rp.y()) + def highlight(self, pen) -> None: + self._pen = pen + self.update() + + def unhighlight(self): + self._pen = self.line_pen + self.update() + + class L1Label(LevelLabel): @@ -190,9 +201,38 @@ class LevelLine(pg.InfiniteLine): super().__init__(**kwargs) self.sigPositionChanged.connect(self.set_level) + # use slightly thicker highlight + self.setHoverPen( + color=(255, 0, 0), + width=self.pen.width() + 1 + ) + def set_level(self, value: float) -> None: self.label.update_from_data(0, self.value()) + def setMouseHover(self, hover: bool) -> None: + """Mouse hover callback. + + """ + if self.mouseHovering == hover: + return + self.mouseHovering = hover + + if hover: + + self.currentPen = self.hoverPen + self.label.highlight(self.hoverPen) + + else: + self.currentPen = self.pen + self.label.unhighlight() + + # highlight any attached label + + # self.setCursor(QtCore.Qt.OpenHandCursor) + # self.setCursor(QtCore.Qt.DragMoveCursor) + self.update() + def level_line( chart: 'ChartPlogWidget', # noqa