nheko/resources/qml/Reactions.qml

94 lines
2.6 KiB
QML
Raw Normal View History

2020-05-04 00:59:05 +02:00
import QtQuick 2.6
import QtQuick.Controls 2.2
// This class is for showing Reactions in the timeline row, not for
// adding new reactions via the emoji picker
2020-05-04 00:59:05 +02:00
Flow {
id: reactionFlow
// highlight colors for selfReactedEvent background
property real highlightHue: colors.highlight.hslHue
property real highlightSat: colors.highlight.hslSaturation
property real highlightLight: colors.highlight.hslLightness
property string eventId
property string roomId
2020-05-04 00:59:05 +02:00
anchors.left: parent.left
anchors.right: parent.right
spacing: 4
2020-05-04 13:14:54 +02:00
property alias reactions: repeater.model
2020-05-04 00:59:05 +02:00
Repeater {
2020-05-04 13:14:54 +02:00
id: repeater
delegate: AbstractButton {
2020-05-04 00:59:05 +02:00
id: reaction
hoverEnabled: true
2020-05-06 03:40:24 +02:00
implicitWidth: contentItem.childrenRect.width + contentItem.leftPadding*2
implicitHeight: contentItem.childrenRect.height
2020-05-04 00:59:05 +02:00
ToolTip.visible: hovered
ToolTip.text: model.users
onClicked: {
console.debug("Picked " + model.key + "in response to " + reactionFlow.eventId + " in room " + reactionFlow.roomId + ". selfReactedEvent: " + model.selfReactedEvent)
timelineManager.reactToMessage(reactionFlow.roomId, reactionFlow.eventId, model.key, model.selfReactedEvent)
}
2020-05-06 03:40:24 +02:00
2020-05-04 00:59:05 +02:00
contentItem: Row {
anchors.centerIn: parent
2020-05-06 03:40:24 +02:00
spacing: reactionText.implicitHeight/4
leftPadding: reactionText.implicitHeight / 2
rightPadding: reactionText.implicitHeight / 2
TextMetrics {
id: textMetrics
2020-06-10 03:05:27 +02:00
font.family: settings.emojiFont
2020-05-06 03:40:24 +02:00
elide: Text.ElideRight
elideWidth: 150
2020-05-16 22:19:23 +02:00
text: model.key
2020-05-06 03:40:24 +02:00
}
2020-05-04 00:59:05 +02:00
Text {
anchors.baseline: reactionCounter.baseline
2020-05-04 00:59:05 +02:00
id: reactionText
text: textMetrics.elidedText + (textMetrics.elidedText == model.key ? "" : "…")
2020-06-10 03:05:27 +02:00
font.family: settings.emojiFont
2020-05-05 23:43:43 +02:00
color: reaction.hovered ? colors.highlight : colors.text
2020-05-06 03:40:24 +02:00
maximumLineCount: 1
2020-05-04 00:59:05 +02:00
}
Rectangle {
2020-05-06 03:40:24 +02:00
id: divider
height: Math.floor(reactionCounter.implicitHeight * 1.4)
2020-05-04 00:59:05 +02:00
width: 1
color: (reaction.hovered || model.selfReactedEvent !== '') ? colors.highlight : colors.text
2020-05-04 00:59:05 +02:00
}
Text {
2020-05-06 03:40:24 +02:00
anchors.verticalCenter: divider.verticalCenter
id: reactionCounter
2020-05-04 13:14:54 +02:00
text: model.counter
2020-05-04 00:59:05 +02:00
font: reaction.font
2020-05-05 23:43:43 +02:00
color: reaction.hovered ? colors.highlight : colors.text
2020-05-04 00:59:05 +02:00
}
}
background: Rectangle {
anchors.centerIn: parent
2020-05-04 00:59:05 +02:00
implicitWidth: reaction.implicitWidth
implicitHeight: reaction.implicitHeight
border.color: (reaction.hovered || model.selfReactedEvent !== '') ? colors.highlight : colors.text
color: model.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.20) : colors.base
2020-05-04 00:59:05 +02:00
border.width: 1
radius: reaction.height / 2.0
}
}
}
}