Warning, /network/neochat/src/qml/StateDelegate.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2018-2020 Black Hat <bhat@encom.eu.org> 0002 // SPDX-License-Identifier: GPL-3.0-only 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import QtQuick.Layouts 0007 0008 import org.kde.kirigami as Kirigami 0009 import org.kde.kirigamiaddons.labs.components as KirigamiComponents 0010 0011 import org.kde.neochat 0012 import org.kde.neochat.config 0013 0014 /** 0015 * @brief A timeline delegate for visualising an aggregated list of consecutive state events. 0016 * 0017 * @inherit TimelineDelegate 0018 */ 0019 TimelineDelegate { 0020 id: root 0021 0022 /** 0023 * @brief List of the first 5 unique authors of the aggregated state event. 0024 */ 0025 required property var authorList 0026 0027 /** 0028 * @brief The number of unique authors beyond the first 5. 0029 */ 0030 required property string excessAuthors 0031 0032 /** 0033 * @brief Single line aggregation of all the state events. 0034 */ 0035 required property string aggregateDisplay 0036 0037 /** 0038 * @brief List of state events in the aggregated state. 0039 */ 0040 required property var stateEvents 0041 0042 /** 0043 * @brief Whether the section header should be shown. 0044 */ 0045 required property bool showSection 0046 0047 /** 0048 * @brief The date of the event as a string. 0049 */ 0050 required property string section 0051 0052 /** 0053 * @brief A model with the first 5 other user read markers for this message. 0054 */ 0055 required property var readMarkers 0056 0057 /** 0058 * @brief String with the display name and matrix ID of the other user read markers. 0059 */ 0060 required property string readMarkersString 0061 0062 /** 0063 * @brief The number of other users at the event after the first 5. 0064 */ 0065 required property var excessReadMarkers 0066 0067 /** 0068 * @brief Whether the other user read marker component should be shown. 0069 */ 0070 required property bool showReadMarkers 0071 0072 /** 0073 * @brief Whether the state event is folded to a single line. 0074 */ 0075 property bool folded: true 0076 0077 contentItem: ColumnLayout { 0078 SectionDelegate { 0079 Layout.fillWidth: true 0080 visible: root.showSection 0081 labelText: root.section 0082 colorSet: Config.compactLayout ? Kirigami.Theme.View : Kirigami.Theme.Window 0083 } 0084 RowLayout { 0085 Layout.fillWidth: true 0086 Layout.leftMargin: Kirigami.Units.largeSpacing * 1.5 0087 Layout.rightMargin: Kirigami.Units.largeSpacing * 1.5 0088 Layout.topMargin: Kirigami.Units.largeSpacing 0089 visible: stateEventRepeater.count !== 1 0090 0091 Flow { 0092 visible: root.folded 0093 spacing: -Kirigami.Units.iconSizes.small / 2 0094 0095 Repeater { 0096 model: root.authorList 0097 delegate: Item { 0098 id: avatarDelegate 0099 0100 required property var modelData 0101 0102 implicitWidth: Kirigami.Units.iconSizes.small 0103 implicitHeight: Kirigami.Units.iconSizes.small + Kirigami.Units.smallSpacing / 2 0104 0105 KirigamiComponents.Avatar { 0106 y: Kirigami.Units.smallSpacing / 2 0107 0108 implicitWidth: Kirigami.Units.iconSizes.small 0109 implicitHeight: Kirigami.Units.iconSizes.small 0110 0111 name: parent.modelData.displayName 0112 source: parent.modelData.avatarSource 0113 color: parent.modelData.color 0114 } 0115 } 0116 } 0117 0118 QQC2.Label { 0119 id: excessAuthorsLabel 0120 0121 text: root.excessAuthors 0122 visible: root.excessAuthors !== "" 0123 color: Kirigami.Theme.textColor 0124 horizontalAlignment: Text.AlignHCenter 0125 background: Kirigami.ShadowedRectangle { 0126 Kirigami.Theme.inherit: false 0127 Kirigami.Theme.colorSet: Kirigami.Theme.View 0128 0129 color: Kirigami.Theme.backgroundColor 0130 radius: height / 2 0131 0132 shadow { 0133 size: Kirigami.Units.smallSpacing 0134 color: Qt.rgba(Kirigami.Theme.textColor.r, Kirigami.Theme.textColor.g, Kirigami.Theme.textColor.b, 0.10) 0135 } 0136 0137 border { 0138 color: Kirigami.ColorUtils.tintWithAlpha(color, Kirigami.Theme.textColor, 0.15) 0139 width: 1 0140 } 0141 } 0142 0143 height: Kirigami.Units.iconSizes.small + Kirigami.Units.smallSpacing 0144 width: Math.max(excessAuthorsTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height) 0145 0146 TextMetrics { 0147 id: excessAuthorsTextMetrics 0148 text: excessAuthorsLabel.text 0149 } 0150 } 0151 } 0152 QQC2.Label { 0153 Layout.fillWidth: true 0154 visible: root.folded 0155 0156 text: `<style>a {color: ${Kirigami.Theme.textColor}}</style>` + root.aggregateDisplay 0157 elide: Qt.ElideRight 0158 textFormat: Text.RichText 0159 wrapMode: Text.WordWrap 0160 onLinkActivated: RoomManager.resolveResource(link) 0161 HoverHandler { 0162 cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.IBeamCursor 0163 } 0164 } 0165 Item { 0166 Layout.fillWidth: true 0167 implicitHeight: foldButton.implicitHeight 0168 visible: !root.folded 0169 } 0170 QQC2.ToolButton { 0171 id: foldButton 0172 icon { 0173 name: (!root.folded ? "go-up" : "go-down") 0174 width: Kirigami.Units.iconSizes.small 0175 height: Kirigami.Units.iconSizes.small 0176 } 0177 0178 onClicked: root.toggleFolded() 0179 } 0180 } 0181 Repeater { 0182 id: stateEventRepeater 0183 model: root.stateEvents 0184 delegate: StateComponent { 0185 Layout.fillWidth: true 0186 Layout.leftMargin: Kirigami.Units.largeSpacing * 1.5 0187 Layout.rightMargin: Kirigami.Units.largeSpacing * 1.5 0188 Layout.topMargin: Kirigami.Units.largeSpacing 0189 visible: !root.folded || stateEventRepeater.count === 1 0190 } 0191 } 0192 AvatarFlow { 0193 Layout.alignment: Qt.AlignRight 0194 visible: root.showReadMarkers 0195 model: root.readMarkers 0196 toolTipText: root.readMarkersString 0197 excessAvatars: root.excessReadMarkers 0198 } 0199 } 0200 0201 function toggleFolded() { 0202 folded = !folded; 0203 foldedChanged(); 0204 } 0205 }