From 80067b5060e4370b9c12c6c232629240dde26cdf Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 28 Apr 2019 11:50:46 -0400 Subject: [PATCH] Add HScrollableTextArea and make SendBox use it --- .../components/base/HScrollableTextArea.qml | 24 +++++++ harmonyqml/components/chat/SendBox.qml | 69 ++++++++----------- 2 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 harmonyqml/components/base/HScrollableTextArea.qml diff --git a/harmonyqml/components/base/HScrollableTextArea.qml b/harmonyqml/components/base/HScrollableTextArea.qml new file mode 100644 index 00000000..aede4a77 --- /dev/null +++ b/harmonyqml/components/base/HScrollableTextArea.qml @@ -0,0 +1,24 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 + +ScrollView { + property alias placeholderText: textArea.placeholderText + property alias text: textArea.text + property alias area: textArea + + default property alias textAreaData: textArea.data + + clip: true + + TextArea { + id: textArea + readOnly: ! visible + selectByMouse: true + + wrapMode: TextEdit.Wrap + font.family: HStyle.fontFamily.sans + font.pixelSize: HStyle.fontSize.normal + color: HStyle.colors.foreground + } +} + diff --git a/harmonyqml/components/chat/SendBox.qml b/harmonyqml/components/chat/SendBox.qml index aed87627..dca25ff2 100644 --- a/harmonyqml/components/chat/SendBox.qml +++ b/harmonyqml/components/chat/SendBox.qml @@ -14,7 +14,7 @@ Base.HGlassRectangle { Layout.maximumHeight: pageStack.height / 2 color: Base.HStyle.chat.sendBox.background - RowLayout { + Base.HRowLayout { anchors.fill: parent spacing: 0 @@ -24,50 +24,39 @@ Base.HGlassRectangle { dimension: root.Layout.minimumHeight } - ScrollView { + Base.HScrollableTextArea { Layout.fillHeight: true Layout.fillWidth: true - id: sendBoxScrollView - clip: true - TextArea { - property string typedText: text + id: textArea + placeholderText: qsTr("Type a message...") + area.focus: true - id: textArea - placeholderText: qsTr("Type a message...") - wrapMode: TextEdit.Wrap - selectByMouse: true - readOnly: ! visible - font.family: "Roboto" - font.pixelSize: 16 - focus: true - - function setTyping(typing) { - Backend.clientManager.clients[chatPage.userId] - .setTypingState(chatPage.roomId, typing) - } - - onTypedTextChanged: setTyping(Boolean(text)) - onEditingFinished: setTyping(false) // when lost focus - - Keys.onReturnPressed: { - event.accepted = true - - if (event.modifiers & Qt.ShiftModifier || - event.modifiers & Qt.ControlModifier || - event.modifiers & Qt.AltModifier) { - textArea.insert(textArea.cursorPosition, "\n") - return - } - - if (textArea.text === "") { return } - Backend.clientManager.clients[chatPage.userId] - .sendMarkdown(chatPage.roomId, textArea.text) - textArea.clear() - } - - Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter + function setTyping(typing) { + Backend.clientManager.clients[chatPage.userId] + .setTypingState(chatPage.roomId, typing) } + + onTextChanged: setTyping(Boolean(text)) + area.onEditingFinished: setTyping(false) // when lost focus + + Keys.onReturnPressed: { + event.accepted = true + + if (event.modifiers & Qt.ShiftModifier || + event.modifiers & Qt.ControlModifier || + event.modifiers & Qt.AltModifier) { + textArea.insert(textArea.cursorPosition, "\n") + return + } + + if (textArea.text === "") { return } + Backend.clientManager.clients[chatPage.userId] + .sendMarkdown(chatPage.roomId, textArea.text) + textArea.clear() + } + + Keys.onEnterPressed: Keys.onReturnPressed(event) // numpad enter } } }