-
Notifications
You must be signed in to change notification settings - Fork 45
Adds wordwrap and text selectability for messages and replies #1050
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
Changes from 10 commits
1f918e1
6aff05f
8b6d1bb
5392c46
e28cca5
c1bb6f7
974189d
d9702a3
e2a4e26
f837b3a
c91433c
52248e7
f4202b3
1b56034
3f8db24
f93944a
5bf3f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,9 @@ | |
| along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| """ | ||
| from typing import Union | ||
| import math | ||
|
|
||
| from PyQt5.QtWidgets import QLabel, QHBoxLayout, QPushButton, QWidget | ||
| from PyQt5.QtWidgets import QLabel, QHBoxLayout, QPlainTextEdit, QPushButton, QWidget | ||
| from PyQt5.QtCore import QSize, Qt | ||
|
|
||
| from securedrop_client.resources import load_svg, load_icon | ||
|
|
@@ -195,3 +196,43 @@ def get_elided_text(self, full_text: str) -> str: | |
|
|
||
| def is_elided(self) -> bool: | ||
| return self.elided | ||
|
|
||
|
|
||
| class SecureQPlainTextEdit(QPlainTextEdit): | ||
| MAX_TEXT_WIDTH = 75 | ||
| MAX_NATURAL_TEXT_WIDTH = 650 | ||
| HEIGHT_BASE = 60 | ||
| LINE_HEIGHT = 20 | ||
|
|
||
| def __init__(self, text: str = '') -> None: | ||
| super().__init__() | ||
| self.setReadOnly(True) | ||
| self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) | ||
| self.document().setTextWidth(self.MAX_TEXT_WIDTH) | ||
| self.height = self.HEIGHT_BASE | ||
| self.setPlainText(text) | ||
|
|
||
| # Disable copy/paste context menu | ||
| self.setContextMenuPolicy(Qt.NoContextMenu) | ||
|
|
||
| def setPlainText(self, text: str) -> None: | ||
| super().setPlainText(text) | ||
|
|
||
| total_line_count = 0 | ||
| for block_num in range(0, self.blockCount()): | ||
| block = self.document().findBlockByNumber(block_num) | ||
| line_count = math.ceil(block.length() / self.document().idealWidth()) | ||
|
||
| total_line_count = total_line_count + line_count | ||
|
|
||
| self.height = self.HEIGHT_BASE + (total_line_count * self.LINE_HEIGHT) | ||
| self.setFixedHeight(self.height) | ||
|
|
||
| def mouseReleaseEvent(self, event): | ||
| self.setFocus() | ||
| super().mouseReleaseEvent(event) | ||
|
|
||
| def focusOutEvent(self, event): | ||
| clear_text_cursor = self.textCursor() | ||
| clear_text_cursor.clearSelection() | ||
| self.setTextCursor(clear_text_cursor) | ||
| super().focusOutEvent(event) | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I'm currently investigating this height setting - how was this
LINE_HEIGHTconstant determined? (asking because I was wondering if we can get this on the fly, looks like it's not exposed onQFont)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though we do have
QFontMetrics::lineSpacingandQFontMetrics::heightwhich both report 16:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@creviera ^^