Commit e442609e authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Chat): handle correctly hovered links in messages

parent 1da42133
......@@ -12,10 +12,28 @@ Item {
property alias backgroundColor: rectangle.color
property alias color: text.color
property alias fontSize: text.font.pointSize
default property alias _content: content.data
// -----------------------------------------------------------------
function _handleHoveredLink (hoveredLink) {
var root = Utils.getTopParent(container)
var children = root.children
// Can be the `invertedMouseArea` of other message.
// Or another? It's a problem in this case...
var mouseArea = children[children.length - 1]
if (Utils.qmlTypeof(mouseArea, 'QQuickMouseArea')) {
mouseArea.cursorShape = hoveredLink
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
}
// -----------------------------------------------------------------
implicitHeight: text.contentHeight + text.padding * 2
Rectangle {
......@@ -45,21 +63,15 @@ Item {
imagesHeight: ChatStyle.entry.message.images.height,
imagesWidth: ChatStyle.entry.message.images.width
})
wrapMode: Text.Wrap
// 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.
onLinkActivated: Qt.openUrlExternally(link)
wrapMode: Text.Wrap
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
onHoveredLinkChanged: _handleHoveredLink(hoveredLink)
onLinkActivated: Qt.openUrlExternally(link)
InvertedMouseArea {
anchors.fill: parent
......@@ -70,6 +82,17 @@ Item {
parent.focus = false
}
}
// Used if no InvertedMouseArea exists.
MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
}
Item {
......
......@@ -117,11 +117,14 @@ TestCase {
component: 'import QtQuick 2.7; ListModel {}',
result: true,
type: 'QQmlListModel'
},
{
}, {
component: 'import QtQuick 2.7; ListView {}',
result: true,
type: 'QQuickListView'
}, {
component: 'import QtQuick 2.7; MouseArea {}',
result: true,
type: 'QQuickMouseArea'
}
]
}
......
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