Skip to content

Commit

Permalink
Fix #415 with various cursor related changes and other UI/CSS updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntoll committed Dec 19, 2019
1 parent f391abe commit ef228d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
39 changes: 37 additions & 2 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from uuid import uuid4
from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QEvent, QTimer, QSize, pyqtBoundSignal, \
QObject, QPoint
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient
from PyQt5.QtGui import QIcon, QPalette, QBrush, QColor, QFont, QLinearGradient, QCursor
from PyQt5.QtWidgets import QListWidget, QLabel, QWidget, QListWidgetItem, QHBoxLayout, \
QPushButton, QVBoxLayout, QLineEdit, QScrollArea, QDialog, QAction, QMenu, QMessageBox, \
QToolButton, QSizePolicy, QPlainTextEdit, QStatusBar, QGraphicsDropShadowEffect
Expand Down Expand Up @@ -114,10 +114,12 @@ def setup(self, controller):

def set_logged_in(self):
self.refresh.enable()
self.refresh.setCursor(QCursor(Qt.PointingHandCursor))
self.setPalette(self.online_palette)

def set_logged_out(self):
self.refresh.disable()
self.refresh.setCursor(QCursor(Qt.ArrowCursor))
self.setPalette(self.offline_palette)

def update_activity_status(self, message: str, duration: int):
Expand Down Expand Up @@ -239,6 +241,7 @@ def _on_clicked(self):
self.setIcon(load_icon(
normal='refresh_active.svg',
disabled='refresh_offline.svg'))
self.setCursor(QCursor(Qt.WaitCursor))

def _on_refresh_complete(self, data):
if (data == 'synced'):
Expand All @@ -247,6 +250,7 @@ def _on_refresh_complete(self, data):
disabled='refresh_offline.svg',
active='refresh_active.svg',
selected='refresh.svg'))
self.setCursor(QCursor(Qt.PointingHandCursor))

def enable(self):
self.setEnabled(True)
Expand Down Expand Up @@ -562,11 +566,19 @@ def __init__(self):
self.menu = UserMenu()
self.setMenu(self.menu)

# Set cursor.
self.setCursor(QCursor(Qt.PointingHandCursor))

def setup(self, controller):
self.menu.setup(controller)

def set_username(self, username):
self.setText(_('{}').format(html.escape(username)))
formatted_name = _('{}').format(html.escape(username))
self.setText(formatted_name)
if len(formatted_name) > 21:
# The name will be truncated, so create a tooltip to display full
# name if the mouse hovers over the widget.
self.setToolTip(_('{}').format(html.escape(username)))


class UserMenu(QMenu):
Expand Down Expand Up @@ -845,6 +857,9 @@ class SourceList(QListWidget):
QListView::item:selected {
border: 500px solid #f3f5f9;
}
QListView::item:hover{
border: 500px solid #f9f9f9;
}
'''

def __init__(self):
Expand Down Expand Up @@ -967,6 +982,9 @@ def __init__(self, source: Source):
layout = QHBoxLayout(self)
self.setLayout(layout)

# Set cursor.
self.setCursor(QCursor(Qt.PointingHandCursor))

# Remove margins and spacing
layout.setContentsMargins(self.SIDE_MARGIN, 0, self.SIDE_MARGIN, 0)
layout.setSpacing(0)
Expand Down Expand Up @@ -1061,6 +1079,10 @@ class StarToggleButton(SvgToggleButton):
#star_button {
border: none;
}
#star_button:hover {
border: 4px solid #D3D8EA;
border-radius: 8px;
}
'''

def __init__(self, source: Source):
Expand Down Expand Up @@ -1220,6 +1242,9 @@ def __init__(self):
self.setFixedHeight(40)
self.setFixedWidth(140)

# Set cursor.
self.setCursor(QCursor(Qt.PointingHandCursor))

# Set drop shadow effect
effect = QGraphicsDropShadowEffect(self)
effect.setOffset(0, 1)
Expand Down Expand Up @@ -2512,6 +2537,10 @@ class ReplyBoxWidget(QWidget):
QPushButton {
border: none;
}
QPushButton:hover {
background: #D3D8EA;
border-radius: 8px;
}
QWidget#horizontal_line {
min-height: 2px;
max-height: 2px;
Expand Down Expand Up @@ -2564,6 +2593,8 @@ def __init__(self, source: Source, controller: Controller) -> None:
button_icon = QIcon(button_pixmap)
self.send_button.setIcon(button_icon)
self.send_button.setIconSize(QSize(56.5, 47))
# Set cursor.
self.send_button.setCursor(QCursor(Qt.PointingHandCursor))

# Add widgets to replybox
replybox_layout.addWidget(self.text_edit)
Expand Down Expand Up @@ -2649,6 +2680,8 @@ def __init__(self, source, controller):
self.placeholder.setParent(self)
self.placeholder.move(QPoint(3, 4)) # make label match text below
self.set_logged_in()
# Set cursor.
self.setCursor(QCursor(Qt.IBeamCursor))

def focusInEvent(self, e):
# override default behavior: when reply text box is focused, the placeholder
Expand Down Expand Up @@ -2755,6 +2788,8 @@ def __init__(self, source, controller):
self.setMenu(self.menu)

self.setPopupMode(QToolButton.InstantPopup)
# Set cursor.
self.setCursor(QCursor(Qt.PointingHandCursor))


class TitleLabel(QLabel):
Expand Down
9 changes: 9 additions & 0 deletions tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ def test_UserButton_set_username():
ub.text() == 'test_username'


def test_UserButton_set_long_username(mocker):
ub = UserButton()
ub.setToolTip = mocker.MagicMock()
ub.set_username('test_username_that_is_very_very_long')
ub.setToolTip.assert_called_once_with(
'test_username_that_is_very_very_long'
)


def test_UserMenu_setup(mocker):
um = UserMenu()
controller = mocker.MagicMock()
Expand Down

0 comments on commit ef228d9

Please sign in to comment.