Skip to content

Commit

Permalink
[WIP] Elide source designation at lower window widths
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence committed Sep 4, 2020
1 parent b8c6c31 commit 7807daf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions securedrop_client/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def get_elided_text(self, full_text: str) -> str:
full_text = full_text.split("\n", 1)[0]

fm = self.fontMetrics()
filename_width = fm.horizontalAdvance(full_text)
if filename_width > self.max_length:
px_width = fm.horizontalAdvance(full_text)
if px_width > self.max_length:
elided_text = ""
for c in full_text:
if fm.horizontalAdvance(elided_text) > self.max_length:
Expand Down
19 changes: 16 additions & 3 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,11 @@ def setText(self, text):
self.placeholder.hide()
super(ReplyTextEdit, self).setPlainText(text)

def resizeEvent(self, event):
# Adjust available source label width to elide text when necessary
new_width = event.size().width()
self.placeholder.update_label_width(new_width)


class ReplyTextEditPlaceholder(QWidget):
def __init__(self, source_name):
Expand All @@ -3147,14 +3152,15 @@ def __init__(self, source_name):
# Signed in
compose_a_reply_to = QLabel(_("Compose a reply to "))
compose_a_reply_to.setObjectName("ReplyTextEditPlaceholder_text")
source_name = SecureQLabel(source_name, wordwrap=False)
source_name.setObjectName("ReplyTextEditPlaceholder_bold_blue")
self.source_name = source_name
self.source_name_label = SecureQLabel(source_name, wordwrap=False, max_length=140)
self.source_name_label.setObjectName("ReplyTextEditPlaceholder_bold_blue")
self.signed_in = QWidget()
signed_in_layout = QHBoxLayout()
signed_in_layout.setSpacing(0)
self.signed_in.setLayout(signed_in_layout)
signed_in_layout.addWidget(compose_a_reply_to)
signed_in_layout.addWidget(source_name)
signed_in_layout.addWidget(self.source_name_label)
self.signed_in.hide()

# Awaiting key
Expand Down Expand Up @@ -3203,6 +3209,13 @@ def show_signed_out(self):
self.signed_in.hide()
self.signed_out.show()

def update_label_width(self, width):
if width > 300:
# Ensure source designations are elided with "..." if needed per
# current container size
self.source_name_label.max_length = width - 300
self.source_name_label.setText(self.source_name)


class DeleteSourceAction(QAction):
"""Use this action to delete the source record."""
Expand Down

0 comments on commit 7807daf

Please sign in to comment.