Commit 12d64188 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/modules/Linphone/Chat/Message): message text supports scrolled...

feat(ui/modules/Linphone/Chat/Message): message text supports scrolled selection & remove useless code
parent b23b651f
...@@ -12,33 +12,14 @@ Item { ...@@ -12,33 +12,14 @@ Item {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
property alias backgroundColor: rectangle.color property alias backgroundColor: rectangle.color
property alias color: text.color property alias color: message.color
property alias fontSize: text.font.pointSize property alias fontSize: message.font.pointSize
default property alias _content: content.data default property alias _content: content.data
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function _handleHoveredLink (hoveredLink) { implicitHeight: message.contentHeight + message.padding * 2
// Can be the `invertedMouseArea` of other message.
// Or another mouse area. Dangerous?
var mouseArea = Utils.find(
Utils.getTopParent(container).children,
function (element) {
return Utils.qmlTypeof(element, 'QQuickMouseArea')
}
)
if (mouseArea != null) {
mouseArea.cursorShape = hoveredLink
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
}
// ---------------------------------------------------------------------------
implicitHeight: text.contentHeight + text.padding * 2
Rectangle { Rectangle {
id: rectangle id: rectangle
...@@ -46,14 +27,40 @@ Item { ...@@ -46,14 +27,40 @@ Item {
height: parent.height height: parent.height
radius: ChatStyle.entry.message.radius radius: ChatStyle.entry.message.radius
width: ( width: (
text.contentWidth < parent.width message.contentWidth < parent.width
? text.contentWidth ? message.contentWidth
: parent.width : parent.width
) + text.padding * 2 ) + message.padding * 2
} }
TextEdit { TextEdit {
id: text 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
...@@ -73,20 +80,12 @@ Item { ...@@ -73,20 +80,12 @@ Item {
textFormat: Text.RichText // To supports links and imgs. textFormat: Text.RichText // To supports links and imgs.
wrapMode: TextEdit.Wrap wrapMode: TextEdit.Wrap
onHoveredLinkChanged: _handleHoveredLink(hoveredLink) onCursorRectangleChanged: ensureVisible(cursorRectangle)
onLinkActivated: Qt.openUrlExternally(link) onLinkActivated: Qt.openUrlExternally(link)
InvertedMouseArea { onActiveFocusChanged: deselect()
anchors.fill: parent
enabled: parent.activeFocus
onPressed: {
parent.deselect()
parent.focus = false
}
}
// Used if no InvertedMouseArea exists. // Handle hovered link.
MouseArea { MouseArea {
id: mouseArea id: mouseArea
...@@ -94,7 +93,7 @@ Item { ...@@ -94,7 +93,7 @@ Item {
acceptedButtons: Qt.NoButton acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink cursorShape: parent.hoveredLink
? Qt.PointingHandCursor ? Qt.PointingHandCursor
: Qt.ArrowCursor : Qt.IBeamCursor
} }
} }
......
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