[SMS App] Make SMS message field scrollable

## Summary

This patch makes SMS message field scrollable and limits its height to ⅓
of window height (or ⅔ for smaller windows) so messages in conversation
are shown even when writing very long messages.

## Test Plan (and screenshots)

<small>These screenshots are in APNG and WEBP formats. Download them if
your browser does not support this format.</small>

### Before:

Message field height was not limited. Message field could be even higher
than window. That makes first lines of this field and messages in
conversation inaccessible.

![grab-noscroll.apng](/uploads/70a44ec3abd0e0707cf69f53ee832542/grab-noscroll.apng)

### After:

Message field height is limited to ⅓ or ⅔ of window height. When text
content reaches this threshold, scroll bars will show up.

![grab-scroll.webp](/uploads/489b9bb197a092f715bc2160acc7fd42/grab-scroll.webp)
This commit is contained in:
Jiří Wolker 2020-04-23 17:22:36 -07:00 committed by Simon Redman
parent 6abe790aa4
commit 2ef5cd4551

View file

@ -199,28 +199,38 @@ Kirigami.ScrollablePage
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
TextArea { ScrollView {
id: messageField
Layout.fillWidth: true Layout.fillWidth: true
placeholderText: page.isMultitarget ? i18nd("kdeconnect-sms", "Replying to multitarget messages is not supported") : i18nd("kdeconnect-sms", "Compose message") Layout.maximumHeight: page.height > 300 ? page.height / 3 : 2 * page.height / 3
wrapMode: TextArea.Wrap contentWidth: page.width - sendButtonArea.width
topPadding: Kirigami.Units.gridUnit * 0.5 clip: true
bottomPadding: topPadding ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
selectByMouse: true
background: Item {} TextArea {
Keys.onReturnPressed: { anchors.fill: parent
if (event.key === Qt.Key_Return) { id: messageField
if (event.modifiers & Qt.ShiftModifier) { placeholderText: page.isMultitarget ? i18nd("kdeconnect-sms", "Replying to multitarget messages is not supported") : i18nd("kdeconnect-sms", "Compose message")
messageField.append("") wrapMode: TextArea.Wrap
} else { topPadding: Kirigami.Units.gridUnit * 0.5
sendButton.onClicked() bottomPadding: topPadding
event.accepted = true selectByMouse: true
topInset: height * 2 // This removes background (frame) of the TextArea. Setting `background: Item {}` would cause segfault.
Keys.onReturnPressed: {
if (event.key === Qt.Key_Return) {
if (event.modifiers & Qt.ShiftModifier) {
messageField.append("")
} else {
sendButton.onClicked()
event.accepted = true
}
} }
} }
} }
} }
ColumnLayout { ColumnLayout {
id: sendButtonArea
ToolButton { ToolButton {
id: sendButton id: sendButton
Layout.preferredWidth: Kirigami.Units.gridUnit * 2 Layout.preferredWidth: Kirigami.Units.gridUnit * 2