Skip to content

Commit

Permalink
Fix mouse hover issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoll authored and sssoleileraaa committed Mar 13, 2020
1 parent c784f7e commit b231971
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
13 changes: 9 additions & 4 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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'
Expand Down
11 changes: 11 additions & 0 deletions securedrop_client/resources/images/star_hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b231971

Please sign in to comment.