mirror of https://github.com/KDE/kasts.git
Port to SearchDialog
This commit is contained in:
parent
5f8167e9b0
commit
1cdb5f2038
|
@ -10,37 +10,18 @@ import QtQuick.Layouts
|
||||||
import QtQml.Models
|
import QtQml.Models
|
||||||
|
|
||||||
import org.kde.kirigami as Kirigami
|
import org.kde.kirigami as Kirigami
|
||||||
import org.kde.kirigamiaddons.labs.components as Addons
|
|
||||||
import org.kde.kirigamiaddons.delegates as AddonDelegates
|
import org.kde.kirigamiaddons.delegates as AddonDelegates
|
||||||
import org.kde.kirigami.delegates as Delegates
|
import org.kde.kirigami.delegates as Delegates
|
||||||
|
|
||||||
import org.kde.kasts
|
import org.kde.kasts
|
||||||
|
|
||||||
Addons.SearchPopupField {
|
Kirigami.SearchField {
|
||||||
id: globalSearchField
|
id: globalSearchField
|
||||||
spaceAvailableLeft: false
|
|
||||||
spaceAvailableRight: true
|
|
||||||
|
|
||||||
autoAccept: false
|
autoAccept: false
|
||||||
|
|
||||||
popup.width: Math.min(Kirigami.Units.gridUnit * 20, kastsMainWindow.width - Kirigami.Units.gridUnit * 2)
|
|
||||||
|
|
||||||
property string searchFilter: ""
|
property string searchFilter: ""
|
||||||
|
|
||||||
onAccepted: {
|
|
||||||
globalSearchField.searchFilter = globalSearchField.text
|
|
||||||
}
|
|
||||||
|
|
||||||
popup.onClosed: {
|
|
||||||
globalSearchField.text = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
onTextChanged: {
|
|
||||||
if (globalSearchField.text === "") {
|
|
||||||
globalSearchField.searchFilter = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function openEntry(entry) {
|
function openEntry(entry) {
|
||||||
pushPage("EpisodeListPage");
|
pushPage("EpisodeListPage");
|
||||||
pageStack.push("qrc:/qt/qml/org/kde/kasts/qml/EntryPage.qml", {"entry": entry});
|
pageStack.push("qrc:/qt/qml/org/kde/kasts/qml/EntryPage.qml", {"entry": entry});
|
||||||
|
@ -62,45 +43,71 @@ Addons.SearchPopupField {
|
||||||
// if we want to insert the settings action as the rightmost, then it
|
// if we want to insert the settings action as the rightmost, then it
|
||||||
// must be defined as first action, which means that we need to save the
|
// must be defined as first action, which means that we need to save the
|
||||||
// default clear action and push that as a second action
|
// default clear action and push that as a second action
|
||||||
var origAction = searchField.rightActions[0];
|
var origAction = searchDialog.searchFieldRightActions[0];
|
||||||
searchField.rightActions[0] = searchSettingsButton;
|
searchDialog.searchFieldRightActions[0] = searchSettingsButton;
|
||||||
searchField.rightActions.push(origAction);
|
searchDialog.searchFieldRightActions.push(origAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
TapHandler {
|
||||||
id: searchListView
|
onTapped: {
|
||||||
reuseItems: true
|
searchDialog.open();
|
||||||
|
searchDialog.forceActiveFocus();
|
||||||
|
}
|
||||||
|
acceptedButtons: Qt.RightButton | Qt.LeftButton
|
||||||
|
}
|
||||||
|
Keys.onPressed: (event) => {
|
||||||
|
if (event.key !== Qt.Key_Tab || event.key !== Qt.Key_Backtab) {
|
||||||
|
searchDialog.open();
|
||||||
|
searchDialog.text = text;
|
||||||
|
searchDialog.forceActiveFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Keys.priority: Keys.AfterItem
|
||||||
|
|
||||||
|
Kirigami.SearchDialog {
|
||||||
|
id: searchDialog
|
||||||
|
|
||||||
|
parent: Controls.Overlay.overlay
|
||||||
|
|
||||||
EpisodeProxyModel {
|
EpisodeProxyModel {
|
||||||
id: proxyModel
|
id: proxyModel
|
||||||
searchFilter: globalSearchField.searchFilter
|
searchFilter: globalSearchField.searchFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
globalSearchField.searchFilter = searchDialog.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
onTextChanged: {
|
||||||
|
if (searchDialog.text === "") {
|
||||||
|
globalSearchField.searchFilter = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
model: globalSearchField.searchFilter === "" ? null : proxyModel
|
model: globalSearchField.searchFilter === "" ? null : proxyModel
|
||||||
|
|
||||||
delegate: AddonDelegates.RoundedItemDelegate {
|
delegate: AddonDelegates.RoundedItemDelegate {
|
||||||
|
id: albumDelegate
|
||||||
|
|
||||||
|
required property int index
|
||||||
|
required property var entry
|
||||||
|
|
||||||
contentItem: Delegates.IconTitleSubtitle {
|
contentItem: Delegates.IconTitleSubtitle {
|
||||||
icon.source: model.entry.cachedImage
|
icon.source: albumDelegate.entry.cachedImage
|
||||||
title: model.entry.title
|
title: albumDelegate.entry.title
|
||||||
subtitle: model.entry.feed.name
|
subtitle: albumDelegate.entry.feed.name
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
globalSearchField.openEntry(model.entry);
|
globalSearchField.openEntry(albumDelegate.entry);
|
||||||
globalSearchField.popup.close();
|
searchDialog.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.PlaceholderMessage {
|
emptyText: i18nc("@info Placeholder text in search box", "No search results")
|
||||||
id: loadingPlaceholder
|
|
||||||
anchors.fill: parent
|
|
||||||
visible: searchListView.count === 0
|
|
||||||
|
|
||||||
text: i18nc("@info Placeholder text in search box", "No search results")
|
|
||||||
}
|
|
||||||
|
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
id: searchSettingsButton
|
id: searchSettingsButton
|
||||||
visible: globalSearchField.popup.visible
|
visible: searchDialog.visible
|
||||||
icon.name: "settings-configure"
|
icon.name: "settings-configure"
|
||||||
text: i18nc("@action:intoolbar", "Advanced Search Options")
|
text: i18nc("@action:intoolbar", "Advanced Search Options")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue