diff --git a/securedrop_client/gui/widgets.py b/securedrop_client/gui/widgets.py index c5f6d324c..8a591def0 100644 --- a/securedrop_client/gui/widgets.py +++ b/securedrop_client/gui/widgets.py @@ -1178,10 +1178,6 @@ class StarToggleButton(SvgToggleButton): #star_button { border: none; } - #star_button:hover { - border: 4px solid #D3D8EA; - border-radius: 8px; - } ''' def __init__(self, source: Source): @@ -1190,6 +1186,7 @@ def __init__(self, source: Source): off='star_off.svg', svg_size=QSize(16, 16)) + self.installEventFilter(self) self.source = source if self.source.is_starred: self.setChecked(True) @@ -1203,6 +1200,14 @@ def setup(self, controller): self.controller.authentication_state.connect(self.on_authentication_changed) self.on_authentication_changed(self.controller.is_authenticated) + def eventFilter(self, obj, event): + t = event.type() + if t == QEvent.HoverEnter: + self.setIcon(load_icon('star_hover.svg')) + elif t == QEvent.HoverLeave: + self.set_icon(on='star_on.svg', off='star_off.svg') + return QObject.event(obj, event) + def on_authentication_changed(self, authenticated: bool): """ Set up handlers based on whether or not the user is authenticated. Connect to 'pressed' diff --git a/securedrop_client/resources/images/star_hover.svg b/securedrop_client/resources/images/star_hover.svg new file mode 100644 index 000000000..59fef007d --- /dev/null +++ b/securedrop_client/resources/images/star_hover.svg @@ -0,0 +1,11 @@ + + + + Starre + Created with Sketch. + + + + + + diff --git a/tests/gui/test_widgets.py b/tests/gui/test_widgets.py index a588ed402..8f418c232 100644 --- a/tests/gui/test_widgets.py +++ b/tests/gui/test_widgets.py @@ -1072,6 +1072,23 @@ def test_StarToggleButton_setup(mocker): on_authentication_changed_fn.assert_called_with('mock') +def test_StarToggleButton_eventFilter(mocker): + """ + Ensure the hover events are handled properly. + """ + stb = StarToggleButton(source=mocker.MagicMock()) + stb.setIcon = mocker.MagicMock() + stb.set_icon = mocker.MagicMock() + # Hover enter + test_event = QEvent(QEvent.HoverEnter) + stb.eventFilter(stb, test_event) + assert stb.setIcon.call_count == 1 + # Hover leave + test_event = QEvent(QEvent.HoverLeave) + stb.eventFilter(stb, test_event) + stb.set_icon.assert_called_once_with(on='star_on.svg', off='star_off.svg') + + def test_StarToggleButton_on_authentication_changed_while_authenticated_and_checked(mocker): """ If on_authentication_changed is set up correctly, then calling toggle on a checked button should