Skip to content

Commit

Permalink
Ensure StarToggleButton hover states honor offline status
Browse files Browse the repository at this point in the history
  • Loading branch information
rmol authored and sssoleileraaa committed Mar 13, 2020
1 parent 7066e9b commit 4f86a61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,11 +1263,15 @@ def enable(self):
self.toggled.connect(self.on_toggle)

def eventFilter(self, obj, event):
checkable = self.isCheckable()
t = event.type()
if t == QEvent.HoverEnter:
if t == QEvent.HoverEnter and checkable:
self.setIcon(load_icon('star_hover.svg'))
elif t == QEvent.HoverLeave:
self.set_icon(on='star_on.svg', off='star_off.svg')
if checkable:
self.set_icon(on='star_on.svg', off='star_off.svg')
else:
self.set_icon(on='star_on.svg', off='star_on.svg')
return QObject.event(obj, event)

def on_authentication_changed(self, authenticated: bool):
Expand Down
6 changes: 6 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,12 @@ def test_StarToggleButton_eventFilter(mocker):
stb.eventFilter(stb, test_event)
stb.set_icon.assert_called_once_with(on='star_on.svg', off='star_off.svg')

# Hover leave when disabled
stb.disable()
test_event = QEvent(QEvent.HoverLeave)
stb.eventFilter(stb, test_event)
stb.set_icon.assert_called_with(on='star_on.svg', off='star_on.svg')


def test_StarToggleButton_on_authentication_changed_while_authenticated_and_checked(mocker):
"""
Expand Down

0 comments on commit 4f86a61

Please sign in to comment.