SearchTable.qml 3.2 KB
Newer Older
1
import QtQuick 2.9
2
import QtQuick.Controls 2.2
3
import org.kde.kirigami 2.2 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
4
import org.kde.mauikit 1.0 as Maui
5
import QtQuick.Layouts 1.3
6 7
import "../../view_models"
import QtGraphicalEffects 1.0
8

9 10
import "../../view_models/BabeTable"
import "../../db/Queries.js" as Q
11

Camilo higuita's avatar
Camilo higuita committed
12 13

BabeTable
14
{
Camilo higuita's avatar
Camilo higuita committed
15 16
    id: searchTable

17
    property alias searchInput : searchInput
18
    property var savedQueries : []
19

Camilo higuita's avatar
Camilo higuita committed
20 21
//    property bool autoSuggestions : bae.loadSetting("AUTOSUGGESTIONS", "BABE", false) === "true" ? true : false
    property bool autoSuggestions : false
22

Camilo higuita's avatar
Camilo higuita committed
23
    trackNumberVisible: false
camilo higuita's avatar
camilo higuita committed
24
    headBar.visible: count
Camilo higuita's avatar
Camilo higuita committed
25 26 27 28
    holder.emoji: "qrc:/assets/BugSearch.png"
    holder.isMask: false
    holder.title : "No search results!"
    holder.body: "Try with another query"
29
    holder.emojiSize: Maui.Style.iconSizes.huge
Camilo higuita's avatar
Camilo higuita committed
30 31 32
    coverArtVisible: true
    trackDuration: true
    trackRating: true
33 34 35 36 37 38

    headBar.leftContent: ToolButton
    {
        icon.name: "edit-clear"
        onClicked: clearSearch()
    }
Camilo higuita's avatar
Camilo higuita committed
39 40 41 42 43

    footBar.middleContent:  Maui.TextField
    {
        id: searchInput
        placeholderText: qsTr("Search...")
44
        Layout.fillWidth: true
Camilo higuita's avatar
Camilo higuita committed
45 46 47 48 49 50 51 52

        onAccepted: runSearch(searchInput.text)
        //                    onActiveFocusChanged: if(activeFocus && autoSuggestions) suggestionsPopup.open()
        onTextEdited: if(autoSuggestions) suggestionsPopup.updateSuggestions()

    }


53
//    footBar.leftContent: ToolButton
Camilo higuita's avatar
Camilo higuita committed
54 55
//    {
//        visible: true
56 57
//        icon.name: "view-filter"
//        icon.color: autoSuggestions ? babeColor : textColor
Camilo higuita's avatar
Camilo higuita committed
58 59 60 61 62 63 64 65
//        onClicked:
//        {
//            autoSuggestions = !autoSuggestions
//            Maui.FM.saveSettings("AUTOSUGGESTIONS", autoSuggestions, "BABE")
//            if(!autoSuggestions)
//                suggestionsPopup.close()
//        }
//    }
Camilo higuita's avatar
Camilo higuita committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79

    SearchSuggestions
    {
        id: suggestionsPopup
//        focus: false
        parent: parent
//        modal: false
//        closePolicy: Popup.CloseOnPressOutsideParent
    }

    Rectangle
    {
        visible: suggestionsPopup.visible
        width: parent.width
Camilo higuita's avatar
Camilo higuita committed
80
        height: parent.height - searchInput.height
Camilo higuita's avatar
Camilo higuita committed
81

camilo higuita's avatar
camilo higuita committed
82
        color: Kirigami.Theme.backgroundColor
Camilo higuita's avatar
Camilo higuita committed
83 84 85 86 87
        z: 999
        opacity: 0.5
    }


Camilo Higuita's avatar
Camilo Higuita committed
88
    function runSearch(searchTxt)
89
    {
Camilo Higuita's avatar
Camilo Higuita committed
90
        if(searchTxt)
camilo higuita's avatar
camilo higuita committed
91
            if(searchTxt !== searchTable.title)
92
            {
Camilo Higuita's avatar
Camilo Higuita committed
93
                if(savedQueries.indexOf(searchTxt) < 0)
94
                {
Camilo Higuita's avatar
Camilo Higuita committed
95 96
                    savedQueries.unshift(searchTxt)
                    //                    suggestionsPopup.model.insert(0, {suggestion: searchInput.text})
97
                    Maui.FM.saveSettings("QUERIES", savedQueries.join(","), "BABE")
98 99
                }

camilo higuita's avatar
camilo higuita committed
100
                searchTable.title = searchTxt
Camilo Higuita's avatar
Camilo Higuita committed
101
                var queries = searchTxt.split(",")
102
                searchTable.list.searchQueries(queries)
Camilo Higuita's avatar
Camilo Higuita committed
103 104
                searchTable.forceActiveFocus()
                suggestionsPopup.close()
105 106 107 108 109 110
            }
    }

    function clearSearch()
    {
        searchInput.clear()
camilo higuita's avatar
camilo higuita committed
111
        searchTable.list.clear()
camilo higuita's avatar
camilo higuita committed
112
        searchTable.title = ""
113
        suggestionsPopup.close()
114 115
    }

116 117
    function populate(tracks)
    {
118
        searchTable.clearTable()
119 120 121
        for(var i in tracks)
            searchTable.model.append(tracks[i])
    }
122

123
}
Camilo higuita's avatar
Camilo higuita committed
124