Warning, /multimedia/kasts/src/qml/SearchBar.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * SPDX-FileCopyrightText: 2023 Bart De Vries <bart@mogwai.be> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Controls as Controls 0009 import QtQuick.Layouts 0010 import org.kde.kirigami as Kirigami 0011 0012 import org.kde.kasts 0013 0014 Controls.Control { 0015 id: searchFilterBar 0016 0017 required property var proxyModel 0018 required property var parentKey 0019 property bool showSearchFilters: true 0020 0021 leftPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing 0022 rightPadding: Kirigami.Units.largeSpacing 0023 topPadding: Kirigami.Units.smallSpacing 0024 bottomPadding: Kirigami.Units.smallSpacing 0025 0026 background: Rectangle { 0027 Kirigami.Theme.inherit: false 0028 Kirigami.Theme.colorSet: Kirigami.Theme.Header 0029 color: Kirigami.Theme.backgroundColor 0030 0031 Kirigami.Separator { 0032 anchors.bottom: parent.bottom 0033 anchors.left: parent.left 0034 anchors.right: parent.right 0035 } 0036 } 0037 0038 contentItem: Kirigami.SearchField { 0039 Layout.fillWidth: true 0040 id: searchField 0041 placeholderText: i18nc("@label:textbox Placeholder text for episode search field", "Search episodes…") 0042 focus: true 0043 autoAccept: false 0044 onAccepted: { 0045 proxyModel.searchFilter = searchField.text; 0046 } 0047 0048 Kirigami.Action { 0049 id: searchSettingsButton 0050 visible: showSearchFilters 0051 enabled: visible 0052 icon.name: "settings-configure" 0053 text: i18nc("@action:intoolbar", "Advanced Search Options") 0054 0055 onTriggered: { 0056 if (searchSettingsMenu.visible) { 0057 searchSettingsMenu.dismiss(); 0058 } else { 0059 searchSettingsMenu.popup(searchSettingsButton); 0060 } 0061 } 0062 } 0063 Component.onCompleted: { 0064 // rightActions are defined from right-to-left 0065 // if we want to insert the settings action as the rightmost, then it 0066 // must be defined as first action, which means that we need to save the 0067 // default clear action and push that as a second action 0068 var origAction = searchField.rightActions[0]; 0069 searchField.rightActions[0] = searchSettingsButton; 0070 searchField.rightActions.push(origAction); 0071 } 0072 0073 Keys.onEscapePressed: (event) => { 0074 proxyModel.searchFilter = ""; 0075 parentKey.checked = false; 0076 event.accepted = true; 0077 } 0078 Keys.onReturnPressed: (event) => { 0079 accepted(); 0080 event.accepted = true; 0081 } 0082 } 0083 0084 Component.onCompleted: { 0085 searchField.forceActiveFocus(); 0086 } 0087 0088 ListModel { 0089 id: searchSettingsModel 0090 0091 function reload() { 0092 clear(); 0093 if (showSearchFilters) { 0094 var searchList = [AbstractEpisodeProxyModel.TitleFlag, 0095 AbstractEpisodeProxyModel.ContentFlag, 0096 AbstractEpisodeProxyModel.FeedNameFlag] 0097 for (var i in searchList) { 0098 searchSettingsModel.append({"name": proxyModel.getSearchFlagName(searchList[i]), 0099 "searchFlag": searchList[i], 0100 "checked": proxyModel.searchFlags & searchList[i]}); 0101 } 0102 } 0103 } 0104 0105 Component.onCompleted: { 0106 reload(); 0107 } 0108 } 0109 0110 Controls.Menu { 0111 id: searchSettingsMenu 0112 0113 title: i18nc("@title:menu", "Search Preferences") 0114 0115 Controls.Label { 0116 padding: Kirigami.Units.smallSpacing 0117 text: i18nc("@title:group Group of fields in which can be searched", "Search in:") 0118 } 0119 0120 Repeater { 0121 model: searchSettingsModel 0122 0123 Controls.MenuItem { 0124 text: model.name 0125 checkable: true 0126 checked: model.checked 0127 onTriggered: { 0128 if (checked) { 0129 proxyModel.searchFlags = proxyModel.searchFlags | model.searchFlag; 0130 } else { 0131 proxyModel.searchFlags = proxyModel.searchFlags & ~model.searchFlag; 0132 } 0133 } 0134 } 0135 } 0136 0137 onOpened: { 0138 searchSettingsModel.reload(); 0139 } 0140 } 0141 }