Tooltip delay at 0 for avatar in chat

This commit is contained in:
Julien Wadel 2021-08-11 12:34:09 +02:00
parent c883a1a024
commit 075aa6f948
3 changed files with 70 additions and 44 deletions

View file

@ -6,48 +6,72 @@ import Common.Styles 1.0
// =============================================================================
MouseArea {
id: tooltipArea
property alias text: tooltip.text
property int delay: TooltipStyle.delay
property bool force: false
property var tooltipParent: parent
property int maxWidth : tooltipParent.width
property bool _visible: false
property int hoveringCursor : Qt.PointingHandCursor
anchors.fill:parent
hoverEnabled: true
scrollGestureEnabled: true
onContainsMouseChanged: _visible = containsMouse
cursorShape: containsMouse ? hoveringCursor : Qt.ArrowCursor
onPressed: mouse.accepted = false
onWheel: {
_visible = false
wheel.accepted = false
}
Tooltip {
id: tooltip
delay: tooltipArea.delay
parent: tooltipParent
visible: _visible || force
width: Math.min(tooltip.implicitWidth, Math.max(tooltipArea.maxWidth, TooltipStyle.minWidth))
//tooltipParent.width>TooltipStyle.minWidth?tooltipParent.width:TooltipStyle.minWidth
timeout: -1
// Workaround to always display tooltip.
onVisibleChanged: {
if (!visible && force) {
tooltip.visible = true
}
}
}
id: tooltipArea
property alias text: tooltip.text
property int delay: TooltipStyle.delay
property bool force: false
property var tooltipParent: parent
property int maxWidth : tooltipParent.width
property bool _visible: false
property int hoveringCursor : Qt.PointingHandCursor
property bool isClickable : true
anchors.fill:parent
hoverEnabled: true
scrollGestureEnabled: true
onContainsMouseChanged: _visible = containsMouse
cursorShape: containsMouse ? hoveringCursor : Qt.ArrowCursor
onPressed: mouse.accepted = false
onWheel: {
_visible = false
wheel.accepted = false
}
onClicked:{
console.log("Clicked")
if(isClickable){
if(tooltip.delay>0) {
tooltip.oldDelay = tooltip.delay
tooltip.delay = 0
}
tooltip.show(text, -1);
}
mouse.accepted = false
}
Tooltip {
id: tooltip
property int oldDelay : 0
delay: tooltipArea.delay
parent: tooltipParent
visible: _visible || force
width: Math.min(tooltip.implicitWidth, Math.max(tooltipArea.maxWidth, TooltipStyle.minWidth))
//tooltipParent.width>TooltipStyle.minWidth?tooltipParent.width:TooltipStyle.minWidth
timeout: -1
// Workaround to always display tooltip.
onVisibleChanged: {
if (!visible && force) {
tooltip.visible = true
}
}
MouseArea{
anchors.fill:parent
visible: tooltipArea.isClickable
onClicked : {
tooltip.hide()
tooltip.delay = tooltip.oldDelay
mouse.accepted = false
}
}
}
}

View file

@ -154,6 +154,7 @@ Rectangle {
hoverEnabled: true
implicitHeight: layout.height
width: parent.width + parent.anchors.rightMargin
acceptedButtons: Qt.NoButton
RowLayout {
id: layout

View file

@ -46,6 +46,7 @@ RowLayout {
$chatEntry.timestamp.getTime() - previousEntry.timestamp.getTime() > 3600
}
TooltipArea{
delay:0
text:avatar.username+'\n'+$chatEntry.fromSipAddress
tooltipParent:mainRow
}