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 { ...@@ -12,10 +12,28 @@ Item {
property alias backgroundColor: rectangle.color property alias backgroundColor: rectangle.color
property alias color: text.color property alias color: text.color
property alias fontSize: text.font.pointSize property alias fontSize: text.font.pointSize
default property alias _content: content.data 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 implicitHeight: text.contentHeight + text.padding * 2
Rectangle { Rectangle {
...@@ -45,21 +63,15 @@ Item { ...@@ -45,21 +63,15 @@ Item {
imagesHeight: ChatStyle.entry.message.images.height, imagesHeight: ChatStyle.entry.message.images.height,
imagesWidth: ChatStyle.entry.message.images.width imagesWidth: ChatStyle.entry.message.images.width
}) })
wrapMode: Text.Wrap
// 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.
onLinkActivated: Qt.openUrlExternally(link) wrapMode: Text.Wrap
MouseArea { onHoveredLinkChanged: _handleHoveredLink(hoveredLink)
anchors.fill: parent onLinkActivated: Qt.openUrlExternally(link)
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink
? Qt.PointingHandCursor
: Qt.ArrowCursor
}
InvertedMouseArea { InvertedMouseArea {
anchors.fill: parent anchors.fill: parent
...@@ -70,6 +82,17 @@ Item { ...@@ -70,6 +82,17 @@ Item {
parent.focus = false 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 { Item {
......
...@@ -117,11 +117,14 @@ TestCase { ...@@ -117,11 +117,14 @@ TestCase {
component: 'import QtQuick 2.7; ListModel {}', component: 'import QtQuick 2.7; ListModel {}',
result: true, result: true,
type: 'QQmlListModel' type: 'QQmlListModel'
}, }, {
{
component: 'import QtQuick 2.7; ListView {}', component: 'import QtQuick 2.7; ListView {}',
result: true, result: true,
type: 'QQuickListView' 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