summary refs log tree commit diff
path: root/resources/qml/Reactions.qml
blob: c10917560243669ad1178203dc311a1def517553 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
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

	anchors.left: parent.left
	anchors.right: parent.right
	spacing: 4

	property alias reactions: repeater.model

	Repeater {
		id: repeater

		delegate: AbstractButton {
			id: reaction
			hoverEnabled: true
			implicitWidth: contentItem.childrenRect.width + contentItem.leftPadding*2
			implicitHeight: contentItem.childrenRect.height

			ToolTip.visible: hovered
			ToolTip.text: modelData.users

			onClicked: {
				console.debug("Picked " + modelData.key + "in response to " + reactionFlow.eventId + " in room " + reactionFlow.roomId + ". selfReactedEvent: " + modelData.selfReactedEvent)
				timelineManager.queueReactionMessage(reactionFlow.eventId, modelData.key)
			}


			contentItem: Row {
				anchors.centerIn: parent
				spacing: reactionText.implicitHeight/4
				leftPadding: reactionText.implicitHeight / 2
				rightPadding: reactionText.implicitHeight / 2

				TextMetrics {
					id: textMetrics
					font.family: settings.emojiFont
					elide: Text.ElideRight
					elideWidth: 150
					text: modelData.key
				}

				Text {
					anchors.baseline: reactionCounter.baseline
					id: reactionText
					text: textMetrics.elidedText + (textMetrics.elidedText == modelData.key ? "" : "…")
					font.family: settings.emojiFont
					color: reaction.hovered ? colors.highlight : colors.text
					maximumLineCount: 1
				}

				Rectangle {
					id: divider
					height: Math.floor(reactionCounter.implicitHeight * 1.4)
					width: 1
					color: (reaction.hovered || modelData.selfReactedEvent !== '') ? colors.highlight : colors.text
				}

				Text {
					anchors.verticalCenter: divider.verticalCenter
					id: reactionCounter
					text: modelData.count
					font: reaction.font
					color: reaction.hovered ? colors.highlight : colors.text
				}
			}

			background: Rectangle {
				anchors.centerIn: parent

				implicitWidth: reaction.implicitWidth
				implicitHeight: reaction.implicitHeight
				border.color: (reaction.hovered  || modelData.selfReactedEvent !== '') ? colors.highlight : colors.text
				color: modelData.selfReactedEvent !== '' ? Qt.hsla(highlightHue, highlightSat, highlightLight, 0.20) : colors.base
				border.width: 1
				radius: reaction.height / 2.0
			}
		}
	}
}