Warning, /network/tokodon/src/content/ui/SearchView.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Controls 2 as QQC2 0006 import QtQuick.Layouts 0007 import Qt.labs.qmlmodels 1.0 0008 import org.kde.kirigami 2 as Kirigami 0009 import org.kde.kirigamiaddons.delegates 1 as Delegates 0010 import org.kde.kirigamiaddons.components 1 as KirigamiComponents 0011 import org.kde.tokodon 0012 import './StatusDelegate' 0013 0014 ListView { 0015 id: root 0016 0017 required property string text 0018 0019 signal itemSelected 0020 0021 onTextChanged: if (text.length === 0) { 0022 searchModel.clear(); 0023 } 0024 0025 model: SearchModel { 0026 id: searchModel 0027 } 0028 0029 section { 0030 property: "type" 0031 delegate: Kirigami.ListSectionHeader { 0032 text: searchModel.labelForType(section) 0033 width: parent.width 0034 } 0035 } 0036 0037 Kirigami.PlaceholderMessage { 0038 text: i18n("Loading...") 0039 visible: searchModel.loading 0040 icon.name: "system-search" 0041 anchors.centerIn: parent 0042 width: parent.width - Kirigami.Units.gridUnit * 4 0043 } 0044 0045 Kirigami.PlaceholderMessage { 0046 text: i18n("No search results") 0047 visible: root.count === 0 && root.text.length > 2 && !searchModel.loading && searchModel.loaded 0048 icon.name: "system-search" 0049 anchors.centerIn: parent 0050 width: parent.width - Kirigami.Units.gridUnit * 4 0051 } 0052 0053 Kirigami.PlaceholderMessage { 0054 text: i18n("Search for users, tags and posts") 0055 visible: root.count === 0 && !searchModel.loading && !searchModel.loaded 0056 icon.name: "system-search" 0057 anchors.centerIn: parent 0058 width: parent.width - Kirigami.Units.gridUnit * 4 0059 } 0060 0061 delegate: DelegateChooser { 0062 role: "type" 0063 DelegateChoice { 0064 roleValue: SearchModel.Account 0065 0066 Delegates.RoundedItemDelegate { 0067 id: accountDelegate 0068 0069 required property var authorIdentity 0070 0071 width: ListView.view.width 0072 text: accountDelegate.authorIdentity.displayName 0073 0074 onClicked: { 0075 Navigation.openAccount(accountDelegate.authorIdentity.id); 0076 root.itemSelected(); 0077 } 0078 0079 contentItem: RowLayout { 0080 KirigamiComponents.Avatar { 0081 Layout.alignment: Qt.AlignTop 0082 Layout.rowSpan: 5 0083 source: accountDelegate.authorIdentity.avatarUrl 0084 cache: true 0085 name: accountDelegate.authorIdentity.displayName 0086 } 0087 0088 ColumnLayout { 0089 spacing: 0 0090 0091 Layout.fillWidth: true 0092 Layout.bottomMargin: Kirigami.Units.smallSpacing 0093 Layout.leftMargin: Kirigami.Units.largeSpacing 0094 0095 Kirigami.Heading { 0096 id: heading 0097 0098 level: 5 0099 text: accountDelegate.text 0100 textFormat: Text.RichText 0101 type: Kirigami.Heading.Type.Primary 0102 color: Kirigami.Theme.textColor 0103 verticalAlignment: Text.AlignTop 0104 0105 Layout.fillWidth: true 0106 } 0107 0108 Kirigami.Heading { 0109 level: 5 0110 elide: Text.ElideRight 0111 color: Kirigami.Theme.disabledTextColor 0112 text: `@${accountDelegate.authorIdentity.account}` 0113 verticalAlignment: Text.AlignTop 0114 0115 Layout.fillWidth: true 0116 } 0117 } 0118 } 0119 } 0120 } 0121 0122 DelegateChoice { 0123 roleValue: SearchModel.Status 0124 StatusDelegate { 0125 x: Kirigami.Units.smallSpacing 0126 width: ListView.view.width - Kirigami.Units.smallSpacing * 2 0127 secondary: true 0128 showSeparator: true 0129 showInteractionButton: false 0130 0131 leftPadding: 0 0132 rightPadding: 0 0133 topPadding: Kirigami.Units.smallSpacing 0134 bottomPadding: Kirigami.Units.smallSpacing 0135 } 0136 } 0137 0138 DelegateChoice { 0139 roleValue: SearchModel.Hashtag 0140 0141 Delegates.RoundedItemDelegate { 0142 id: delegate 0143 0144 required property string id 0145 0146 text: "#" + id 0147 Accessible.description: i18n("Hashtag") 0148 0149 onClicked: { 0150 Navigation.openTag(id); 0151 root.itemSelected(); 0152 } 0153 0154 contentItem: ColumnLayout { 0155 Layout.fillWidth: true 0156 Layout.bottomMargin: Kirigami.Units.smallSpacing 0157 Layout.leftMargin: Kirigami.Units.largeSpacing 0158 spacing: 0 0159 Kirigami.Heading { 0160 id: heading 0161 level: 5 0162 text: delegate.text 0163 type: Kirigami.Heading.Type.Primary 0164 color: Kirigami.Theme.textColor 0165 verticalAlignment: Text.AlignTop 0166 } 0167 } 0168 } 0169 } 0170 } 0171 }