mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 05:23:06 +00:00
feat(ui/modules/Linphone/Chat/Message): use a Logic file
This commit is contained in:
parent
f4faaf9cce
commit
1d28642913
3 changed files with 34 additions and 28 deletions
|
|
@ -271,6 +271,7 @@
|
|||
<file>ui/modules/Linphone/Chat/Event.qml</file>
|
||||
<file>ui/modules/Linphone/Chat/FileMessage.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/OutgoingMessage.qml</file>
|
||||
<file>ui/modules/Linphone/Contact/Avatar.qml</file>
|
||||
|
|
|
|||
25
linphone-desktop/ui/modules/Linphone/Chat/Message.js
Normal file
25
linphone-desktop/ui/modules/Linphone/Chat/Message.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// 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
|
|||
import Linphone.Styles 1.0
|
||||
import Utils 1.0
|
||||
|
||||
import 'Message.js' as Logic
|
||||
|
||||
// =============================================================================
|
||||
|
||||
Item {
|
||||
|
|
@ -33,35 +35,13 @@ Item {
|
|||
) + message.padding * 2
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Message.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
TextEdit {
|
||||
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 {
|
||||
left: container.left
|
||||
right: container.right
|
||||
|
|
@ -78,9 +58,9 @@ Item {
|
|||
// See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop
|
||||
// and http://doc.qt.io/qt-5/richtext-html-subset.html
|
||||
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)
|
||||
|
||||
onActiveFocusChanged: deselect()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue