feat(Chat): handle correctly hovered links in messages

This commit is contained in:
Ronan Abhamon 2016-11-09 17:25:15 +01:00
parent 1da42133d5
commit e442609e8c
2 changed files with 37 additions and 11 deletions

View file

@ -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 {

View file

@ -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'
}
]
}