Warning, /network/neochat/src/qml/UserInfo.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls as QQC2 0006 import QtQuick.Layouts 0007 import org.kde.kirigami as Kirigami 0008 import org.kde.kirigamiaddons.labs.components as KirigamiComponents 0009 import org.kde.kirigamiaddons.delegates as Delegates 0010 0011 import org.kde.neochat 0012 import org.kde.neochat.config 0013 import org.kde.neochat.accounts 0014 0015 RowLayout { 0016 id: root 0017 0018 required property NeoChatConnection connection 0019 0020 property bool bottomEdge: true 0021 0022 property var addAccount 0023 0024 spacing: Kirigami.Units.largeSpacing 0025 0026 Layout.topMargin: Kirigami.Units.smallSpacing 0027 Layout.bottomMargin: Kirigami.Units.smallSpacing 0028 Layout.minimumHeight: bottomEdge ? Kirigami.Units.gridUnit * 2 : -1 0029 0030 onVisibleChanged: { 0031 if (!visible) { 0032 accountsPopup.close(); 0033 switchUserButton.checked = false; 0034 } 0035 } 0036 0037 QQC2.AbstractButton { 0038 id: accountButton 0039 0040 Layout.preferredWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0041 Layout.preferredHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0042 Layout.leftMargin: Kirigami.Units.largeSpacing 0043 0044 TapHandler { 0045 acceptedButtons: Qt.RightButton | Qt.LeftButton 0046 onTapped: (eventPoint, button) => { 0047 // TODO Qt6 remove 0048 if (!button) { 0049 button = eventPoint.event.button; 0050 } 0051 if (button == Qt.RightButton) { 0052 accountMenu.open(); 0053 } else { 0054 pageStack.pushDialogLayer(Qt.resolvedUrl('qrc:/org/kde/neochat/qml/AccountEditorPage.qml'), { 0055 connection: root.connection 0056 }, { 0057 title: i18n("Account editor") 0058 }); 0059 } 0060 } 0061 } 0062 0063 text: i18n("Edit this account") 0064 0065 contentItem: KirigamiComponents.Avatar { 0066 readonly property string mediaId: root.connection.localUser.avatarMediaId 0067 0068 source: mediaId ? ("image://mxc/" + mediaId) : "" 0069 name: root.connection.localUser.displayName ?? root.connection.localUser.id 0070 } 0071 } 0072 0073 ColumnLayout { 0074 Layout.fillWidth: true 0075 spacing: 0 0076 QQC2.Label { 0077 id: displayNameLabel 0078 text: root.connection.localUser.displayName 0079 textFormat: Text.PlainText 0080 elide: Text.ElideRight 0081 Layout.fillWidth: true 0082 } 0083 QQC2.Label { 0084 text: (root.connection.label.length > 0 ? (root.connection.label + " ") : "") + root.connection.localUser.id 0085 font.pointSize: displayNameLabel.font.pointSize * 0.8 0086 opacity: 0.7 0087 textFormat: Text.PlainText 0088 elide: Text.ElideRight 0089 Layout.fillWidth: true 0090 } 0091 } 0092 QQC2.ToolButton { 0093 id: switchUserButton 0094 icon.name: "system-switch-user" 0095 checkable: true 0096 text: i18n("Switch User") 0097 display: QQC2.AbstractButton.IconOnly 0098 Accessible.name: text 0099 QQC2.ToolTip.text: text 0100 QQC2.ToolTip.visible: hovered 0101 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0102 Layout.minimumWidth: Layout.preferredWidth 0103 Layout.alignment: Qt.AlignRight 0104 Shortcut { 0105 sequence: "Ctrl+U" 0106 onActivated: switchUserButton.toggle() 0107 } 0108 } 0109 QQC2.ToolButton { 0110 icon.name: "list-add" 0111 onClicked: ; //TODO 0112 text: i18n("Add") //TODO find better message 0113 display: QQC2.AbstractButton.IconOnly 0114 QQC2.ToolTip.text: text 0115 QQC2.ToolTip.visible: hovered 0116 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0117 Layout.minimumWidth: Layout.preferredWidth 0118 Layout.alignment: Qt.AlignRight 0119 visible: false 0120 } 0121 QQC2.ToolButton { 0122 icon.name: "settings-configure" 0123 onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/SettingsPage.qml", {connection: root.connection}, { title: i18n("Configure") }) 0124 text: i18n("Open Settings") 0125 display: QQC2.AbstractButton.IconOnly 0126 Layout.minimumWidth: Layout.preferredWidth 0127 Layout.alignment: Qt.AlignRight 0128 QQC2.ToolTip.text: text 0129 QQC2.ToolTip.visible: hovered 0130 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0131 } 0132 Item { 0133 width: 1 0134 } 0135 0136 AccountMenu { 0137 id: accountMenu 0138 y: root.bottomEdge ? -height : accountButton.height 0139 connection: root.connection 0140 } 0141 QQC2.Popup { 0142 id: accountsPopup 0143 parent: root 0144 0145 visible: switchUserButton.checked 0146 onVisibleChanged: if (visible) accounts.forceActiveFocus() 0147 0148 x: -Kirigami.Units.smallSpacing 0149 y: root.bottomEdge ? -height - Kirigami.Units.smallSpacing - 1 : root.height + Kirigami.Units.smallSpacing - 1 0150 width: root.width + (root.bottomEdge ? 0 : Kirigami.Units.smallSpacing * 2) 0151 leftPadding: 0 0152 rightPadding: 0 0153 bottomPadding: Kirigami.Units.smallSpacing 0154 topPadding: Kirigami.Units.smallSpacing 0155 0156 closePolicy: QQC2.Popup.CloseOnEscape 0157 0158 contentItem: ListView { 0159 id: accounts 0160 implicitHeight: contentHeight 0161 0162 header: Kirigami.Separator {} 0163 0164 footer: Delegates.RoundedItemDelegate { 0165 id: addButton 0166 width: parent.width 0167 highlighted: focus || (addAccount.highlighted || addAccount.ListView.isCurrentItem) && !addAccount.pressed 0168 Component.onCompleted: root.addAccount = this 0169 icon { 0170 name: "list-add" 0171 width: Kirigami.Units.iconSizes.smallMedium 0172 height: Kirigami.Units.iconSizes.smallMedium 0173 } 0174 text: i18n("Add Account") 0175 contentItem: Delegates.SubtitleContentItem { 0176 itemDelegate: parent 0177 subtitle: i18n("Log in to an existing account") 0178 labelItem.textFormat: Text.PlainText 0179 subtitleItem.textFormat: Text.PlainText 0180 } 0181 0182 onClicked: { 0183 pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/WelcomePage.qml", {}, { 0184 title: i18nc("@title:window", "Login"), 0185 }); 0186 if (switchUserButton.checked) { 0187 switchUserButton.checked = false 0188 } 0189 accounts.currentIndex = Controller.activeConnectionIndex 0190 } 0191 Keys.onUpPressed: { 0192 accounts.currentIndex = accounts.count - 1 0193 accounts.forceActiveFocus() 0194 } 0195 Keys.onDownPressed: { 0196 accounts.currentIndex = 0 0197 accounts.forceActiveFocus() 0198 } 0199 } 0200 clip: true 0201 model: AccountRegistry 0202 0203 keyNavigationEnabled: false 0204 Keys.onDownPressed: { 0205 if (accounts.currentIndex === accounts.count - 1) { 0206 addAccount.forceActiveFocus() 0207 accounts.currentIndex = -1 0208 } else { 0209 accounts.incrementCurrentIndex() 0210 } 0211 } 0212 Keys.onUpPressed: { 0213 if (accounts.currentIndex === 0) { 0214 addAccount.forceActiveFocus() 0215 accounts.currentIndex = -1 0216 } else { 0217 accounts.decrementCurrentIndex() 0218 } 0219 } 0220 0221 Keys.onReleased: if (event.key == Qt.Key_Escape) { 0222 if (switchUserButton.checked) { 0223 switchUserButton.checked = false 0224 } 0225 } 0226 0227 onVisibleChanged: { 0228 for (let i = 0; i < accounts.count; i++) { 0229 if (model.data(model.index(i, 0), Qt.DisplayRole) === root.connection.localUser.id) { 0230 accounts.currentIndex = i; 0231 break; 0232 } 0233 } 0234 } 0235 0236 delegate: Delegates.RoundedItemDelegate { 0237 id: userDelegate 0238 0239 required property NeoChatConnection connection 0240 0241 width: parent.width 0242 text: connection.localUser.displayName 0243 0244 contentItem: RowLayout { 0245 KirigamiComponents.Avatar { 0246 implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0247 implicitHeight: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0248 sourceSize { 0249 width: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0250 height: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing 0251 } 0252 source: userDelegate.connection.localUser.avatarMediaId ? ("image://mxc/" + userDelegate.connection.localUser.avatarMediaId) : "" 0253 name: userDelegate.connection.localUser.displayName ?? userDelegate.connection.localUser.id 0254 } 0255 0256 Delegates.SubtitleContentItem { 0257 itemDelegate: userDelegate 0258 subtitle: userDelegate.connection.localUser.id 0259 labelItem.textFormat: Text.PlainText 0260 subtitleItem.textFormat: Text.PlainText 0261 } 0262 } 0263 0264 onClicked: { 0265 Controller.activeConnection = userDelegate.connection 0266 if (switchUserButton.checked) { 0267 switchUserButton.checked = false 0268 } 0269 } 0270 } 0271 } 0272 0273 background: ColumnLayout { 0274 spacing: 0 0275 Kirigami.Separator { 0276 Layout.fillWidth: true 0277 visible: root.bottomEdge 0278 } 0279 Rectangle { 0280 Layout.fillWidth: true 0281 Layout.fillHeight: true 0282 color: Kirigami.Theme.backgroundColor 0283 } 0284 Kirigami.Separator { 0285 Layout.fillWidth: true 0286 visible: !root.bottomEdge 0287 } 0288 } 0289 } 0290 }