Warning, /network/neochat/src/qml/CompletionMenu.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Carl Schwan <carl@carlschwan.de>
0002 // SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 import QtQuick
0006 import QtQuick.Layouts
0007 import QtQuick.Controls as QQC2
0008 import Qt.labs.qmlmodels
0009 
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kirigamiaddons.delegates as Delegates
0012 import org.kde.kirigamiaddons.labs.components as KirigamiComponents
0013 
0014 import org.kde.neochat
0015 
0016 QQC2.Popup {
0017     id: root
0018 
0019     required property NeoChatConnection connection
0020     required property var chatDocumentHandler
0021 
0022     visible: completions.count > 0
0023 
0024     onVisibleChanged: if (visible) {
0025         root.open();
0026     }
0027 
0028     RoomListModel {
0029         id: roomListModel
0030         connection: root.connection
0031     }
0032 
0033     Component.onCompleted: {
0034         chatDocumentHandler.completionModel.roomListModel = roomListModel;
0035     }
0036 
0037     function incrementIndex() {
0038         completions.incrementCurrentIndex();
0039     }
0040 
0041     function decrementIndex() {
0042         completions.decrementCurrentIndex();
0043     }
0044 
0045     function complete() {
0046         root.chatDocumentHandler.complete(completions.currentIndex);
0047     }
0048 
0049     leftPadding: 0
0050     rightPadding: 0
0051     topPadding: 0
0052     bottomPadding: 0
0053 
0054     implicitHeight: Math.min(completions.contentHeight, Kirigami.Units.gridUnit * 10)
0055 
0056     contentItem: ColumnLayout {
0057         spacing: 0
0058         Kirigami.Separator {
0059             Layout.fillWidth: true
0060         }
0061         QQC2.ScrollView {
0062             Layout.fillWidth: true
0063             Layout.preferredHeight: contentHeight
0064             Layout.maximumHeight: Kirigami.Units.gridUnit * 10
0065 
0066             background: Rectangle {
0067                 color: Kirigami.Theme.backgroundColor
0068             }
0069 
0070             ListView {
0071                 id: completions
0072 
0073                 model: root.chatDocumentHandler.completionModel
0074                 currentIndex: 0
0075                 keyNavigationWraps: true
0076                 highlightMoveDuration: 100
0077                 onCountChanged: currentIndex = 0
0078                 delegate: Delegates.RoundedItemDelegate {
0079                     id: completionDelegate
0080 
0081                     required property int index
0082                     required property string displayName
0083                     required property string subtitle
0084                     required property string iconName
0085 
0086                     text: displayName
0087 
0088                     contentItem: RowLayout {
0089                         KirigamiComponents.Avatar {
0090                             visible: completionDelegate.iconName !== "invalid"
0091                             Layout.preferredWidth: Kirigami.Units.iconSizes.medium
0092                             Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0093                             source: completionDelegate.iconName === "invalid" ? "" : completionDelegate.iconName
0094                             name: completionDelegate.text
0095                         }
0096                         Delegates.SubtitleContentItem {
0097                             itemDelegate: completionDelegate
0098                             labelItem.textFormat: Text.PlainText
0099                             subtitle: completionDelegate.subtitle ?? ""
0100                             subtitleItem.textFormat: Text.PlainText
0101                         }
0102                     }
0103                     onClicked: root.chatDocumentHandler.complete(completionDelegate.index)
0104                 }
0105             }
0106         }
0107     }
0108 
0109     background: Rectangle {
0110         color: Kirigami.Theme.backgroundColor
0111     }
0112 }