Commit 1d286429 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/Chat/Message): use a `Logic` file

parent f4faaf9c
...@@ -271,6 +271,7 @@ ...@@ -271,6 +271,7 @@
<file>ui/modules/Linphone/Chat/Event.qml</file> <file>ui/modules/Linphone/Chat/Event.qml</file>
<file>ui/modules/Linphone/Chat/FileMessage.qml</file> <file>ui/modules/Linphone/Chat/FileMessage.qml</file>
<file>ui/modules/Linphone/Chat/IncomingMessage.qml</file> <file>ui/modules/Linphone/Chat/IncomingMessage.qml</file>
<file>ui/modules/Linphone/Chat/Message.js</file>
<file>ui/modules/Linphone/Chat/Message.qml</file> <file>ui/modules/Linphone/Chat/Message.qml</file>
<file>ui/modules/Linphone/Chat/OutgoingMessage.qml</file> <file>ui/modules/Linphone/Chat/OutgoingMessage.qml</file>
<file>ui/modules/Linphone/Contact/Avatar.qml</file> <file>ui/modules/Linphone/Contact/Avatar.qml</file>
......
// See: `ensureVisible` on http://doc.qt.io/qt-5/qml-qtquick-textedit.html
function ensureVisible (cursor) {
// Case 1: No focused.
if (!message.activeFocus) {
return
}
// Case 2: Scroll up.
var contentItem = chat.contentItem
var contentY = chat.contentY
var messageY = message.mapToItem(contentItem, 0, 0).y + cursor.y
if (contentY >= messageY) {
chat.contentY = messageY
return
}
// Case 3: Scroll down.
var chatHeight = chat.height
var cursorHeight = cursor.height
if (contentY + chatHeight <= messageY + cursorHeight) {
chat.contentY = messageY + cursorHeight - chatHeight
}
}
...@@ -4,6 +4,8 @@ import Common 1.0 ...@@ -4,6 +4,8 @@ import Common 1.0
import Linphone.Styles 1.0 import Linphone.Styles 1.0
import Utils 1.0 import Utils 1.0
import 'Message.js' as Logic
// ============================================================================= // =============================================================================
Item { Item {
...@@ -33,35 +35,13 @@ Item { ...@@ -33,35 +35,13 @@ Item {
) + message.padding * 2 ) + message.padding * 2
} }
// ---------------------------------------------------------------------------
// Message.
// ---------------------------------------------------------------------------
TextEdit { TextEdit {
id: message id: message
// See: `ensureVisible` on http://doc.qt.io/qt-5/qml-qtquick-textedit.html
function ensureVisible (cursor) {
// Case 1: No focused.
if (!message.activeFocus) {
return
}
// Case 2: Scroll up.
var contentItem = chat.contentItem
var contentY = chat.contentY
var messageY = message.mapToItem(contentItem, 0, 0).y + cursor.y
if (contentY >= messageY) {
chat.contentY = messageY
return
}
// Case 3: Scroll down.
var chatHeight = chat.height
var cursorHeight = cursor.height
if (contentY + chatHeight <= messageY + cursorHeight) {
chat.contentY = messageY + cursorHeight - chatHeight
}
}
anchors { anchors {
left: container.left left: container.left
right: container.right right: container.right
...@@ -78,9 +58,9 @@ Item { ...@@ -78,9 +58,9 @@ Item {
// See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop // See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop
// and http://doc.qt.io/qt-5/richtext-html-subset.html // and http://doc.qt.io/qt-5/richtext-html-subset.html
textFormat: Text.RichText // To supports links and imgs. textFormat: Text.RichText // To supports links and imgs.
wrapMode: TextEdit.Wrap wrapMode: TextEdit.WordWrap
onCursorRectangleChanged: ensureVisible(cursorRectangle) onCursorRectangleChanged: Logic.ensureVisible(cursorRectangle)
onLinkActivated: Qt.openUrlExternally(link) onLinkActivated: Qt.openUrlExternally(link)
onActiveFocusChanged: deselect() onActiveFocusChanged: deselect()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment