Skip to content

Commit

Permalink
Prevent tooltips on source preview labels
Browse files Browse the repository at this point in the history
Allow SecureQLabel to disable tooltips via the "with_tooltip"
constructor argument, which if False will prevent tooltips being
automatically set for the SecureQLabel when its setText method is
called.

Set "with_tooltip" False on SourceWidget's preview SecureQLabel so
that no tooltip appears when hovering over it.
  • Loading branch information
rmol committed Mar 25, 2020
1 parent bd94b7c commit 61f335d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,21 @@ def __init__(
flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags(),
wordwrap: bool = True,
max_length: int = 0,
with_tooltip: bool = True,
):
super().__init__(parent, flags)
self.wordwrap = wordwrap
self.max_length = max_length
self.setWordWrap(wordwrap) # If True, wraps text at default of 70 characters
self.with_tooltip = with_tooltip
self.setText(text)
self.elided = True if self.text() != text else False

def setText(self, text: str) -> None:
self.setTextFormat(Qt.PlainText)
if self.with_tooltip:
tooltip_label = SecureQLabel(text, with_tooltip=False)
self.setToolTip(tooltip_label.text())
elided_text = self.get_elided_text(text)
self.elided = True if elided_text != text else False
super().setText(elided_text)
Expand All @@ -179,8 +184,6 @@ def get_elided_text(self, full_text: str) -> str:
fm = self.fontMetrics()
filename_width = fm.horizontalAdvance(full_text)
if filename_width > self.max_length:
wrapped_tool_tip = SecureQLabel(full_text)
self.setToolTip(wrapped_tool_tip.text())
elided_text = ''
for c in full_text:
if fm.horizontalAdvance(elided_text) > self.max_length:
Expand Down
2 changes: 1 addition & 1 deletion securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ def __init__(self, controller: Controller, source: Source):
summary_layout.setSpacing(0)
self.name = QLabel()
self.name.setObjectName('source_name')
self.preview = SecureQLabel(max_length=self.PREVIEW_WIDTH)
self.preview = SecureQLabel(max_length=self.PREVIEW_WIDTH, with_tooltip=False)
self.preview.setObjectName('preview')
self.preview.setFixedSize(QSize(self.PREVIEW_WIDTH, self.PREVIEW_HEIGHT))
self.waiting_delete_confirmation = QLabel('Deletion in progress')
Expand Down

0 comments on commit 61f335d

Please sign in to comment.