Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent tooltips on source preview labels #1006

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1175,7 +1175,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