Skip to content

Commit

Permalink
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 df72972
Show file tree
Hide file tree
Showing 2 changed files with 33 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
34 changes: 31 additions & 3 deletions securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3133,8 +3133,25 @@ 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
self.placeholder.update_label_width(event.size().width())
super().resizeEvent(event)


class ReplyTextEditPlaceholder(QWidget):

# These values are used to determine the width that can be taken up by
# the source designation as the widget is initialized or the window is
# resized.
INITIAL_MAX_WIDTH = 150
RESERVED_WIDTH = 250

# We allocate a fixed with to the source designation because its text is
# dynamically resized, which otherwise causes Qt's layout engine to
# incorrectly reposition it
FIXED_LABEL_WIDTH = 800

def __init__(self, source_name):
super().__init__()

Expand All @@ -3147,14 +3164,18 @@ 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=self.INITIAL_MAX_WIDTH
)
self.source_name_label.setObjectName("ReplyTextEditPlaceholder_bold_blue")
self.source_name_label.setFixedWidth(self.FIXED_LABEL_WIDTH)
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 +3224,13 @@ def show_signed_out(self):
self.signed_in.hide()
self.signed_out.show()

def update_label_width(self, width):
if width > self.RESERVED_WIDTH:
# Ensure source designations are elided with "..." if needed per
# current container size
self.source_name_label.max_length = width - self.RESERVED_WIDTH
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 df72972

Please sign in to comment.