|
7 | 7 | fromOrange.widgets.visualize.utils.plotutilsimportPlotWidget |
8 | 8 |
|
9 | 9 |
|
| 10 | +classInteractiveInfiniteLine(InfiniteLine): |
| 11 | +""" |
| 12 | + A subclass of InfiniteLine that provides custom hover behavior. |
| 13 | + """ |
| 14 | + |
| 15 | +def__init__(self,angle=90,pos=None,movable=False,bounds=None,**kwargs): |
| 16 | +super().__init__(angle=angle,pos=pos,movable=movable,bounds=bounds,**kwargs) |
| 17 | +self._normal_pen=None |
| 18 | +self._highlight_pen=None |
| 19 | + |
| 20 | +defhoverEvent(self,ev): |
| 21 | +""" |
| 22 | + Override hoverEvent to provide custom hover behavior. |
| 23 | +
|
| 24 | + Parameters |
| 25 | + ---------- |
| 26 | + ev : HoverEvent |
| 27 | + The hover event from pyqtgraph |
| 28 | + """ |
| 29 | +ifnothasattr(ev,'isEnter'): |
| 30 | +return |
| 31 | + |
| 32 | +ifev.isEnter()andself._highlight_penisnotNone: |
| 33 | +self.setPen(self._highlight_pen) |
| 34 | +elifev.isExit()andself._normal_penisnotNone: |
| 35 | +self.setPen(self._normal_pen) |
| 36 | + |
| 37 | + |
10 | 38 | classSliderGraph(PlotWidget): |
11 | 39 | """ |
12 | 40 | An widget graph element that shows a line plot with more sequences. It |
@@ -137,58 +165,35 @@ def _plot_cutpoint(self, x): |
137 | 165 | return |
138 | 166 | ifself._lineisNone: |
139 | 167 | # plot interactive vertical line |
140 | | -self._line=InfiniteLine( |
| 168 | +self._line=InteractiveInfiniteLine( |
141 | 169 | angle=90,pos=x,movable=True, |
142 | 170 | bounds=self.selection_limitifself.selection_limitisnotNone |
143 | 171 | else (self.x.min(),self.x.max()) |
144 | 172 | ) |
145 | 173 | self._line.setCursor(Qt.SizeHorCursor) |
146 | 174 |
|
147 | | -# Set up hover state handling |
148 | | -self._line.hoverEvent=self._handle_hover# Changed from lambda to direct method reference |
149 | | - |
150 | | -# Initial pen style |
151 | | -self._line.setPen(mkPen(self.palette().text().color(),width=6,style=Qt.SolidLine,capStyle=Qt.RoundCap)) |
| 175 | +# Create normal and highlight pens |
| 176 | +normal_pen=mkPen(self.palette().text().color(),width=4,style=Qt.SolidLine,capStyle=Qt.RoundCap) |
| 177 | +highlight_color=self.palette().highlight().color() |
| 178 | +highlight_color.setHsv( |
| 179 | +highlight_color.hue(), |
| 180 | +min(highlight_color.saturation()+30,255), |
| 181 | +max(highlight_color.value()-20,0) |
| 182 | + ) |
| 183 | +highlight_pen=mkPen(highlight_color,width=10,style=Qt.SolidLine,capStyle=Qt.RoundCap) |
| 184 | + |
| 185 | +# Set pens directly |
| 186 | +self._line._normal_pen=normal_pen |
| 187 | +self._line._highlight_pen=highlight_pen |
| 188 | +self._line.setPen(normal_pen) |
152 | 189 | self._line.sigPositionChanged.connect(self._on_cut_changed) |
153 | 190 | self.addItem(self._line) |
154 | 191 | else: |
155 | 192 | self._line.setValue(x) |
156 | 193 |
|
157 | 194 | self._update_horizontal_lines() |
158 | 195 |
|
159 | | -def_handle_hover(self,ev): |
160 | | -""" |
161 | | - Handle hover events for the vertical line. |
162 | | -
|
163 | | - Parameters |
164 | | - ---------- |
165 | | - ev : HoverEvent |
166 | | - The hover event from pyqtgraph |
167 | | - """ |
168 | | -ifnothasattr(ev,'isEnter'):# Add check for event type |
169 | | -return |
170 | 196 |
|
171 | | -ifev.isEnter(): |
172 | | -highlight_color=self.palette().highlight().color() |
173 | | -highlight_color.setHsv( |
174 | | -highlight_color.hue(), |
175 | | -min(highlight_color.saturation()+30,255), |
176 | | -max(highlight_color.value()-20,0) |
177 | | - ) |
178 | | -self._line.setPen(mkPen( |
179 | | -highlight_color, |
180 | | -width=10, |
181 | | -style=Qt.SolidLine, |
182 | | -capStyle=Qt.RoundCap |
183 | | - )) |
184 | | -elifev.isExit(): |
185 | | -# On hover exit: return to normal state |
186 | | -self._line.setPen(mkPen( |
187 | | -self.palette().text().color(), |
188 | | -width=6, |
189 | | -style=Qt.SolidLine, |
190 | | -capStyle=Qt.RoundCap |
191 | | - )) |
192 | 197 |
|
193 | 198 | def_plot_horizontal_lines(self): |
194 | 199 | """ |
|