SearchView.qml 1.49 KB
Newer Older
1 2 3 4 5
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../../db/Query.js" as Q
6
import org.kde.mauikit 1.0 as Maui
Camilo Higuita's avatar
Camilo Higuita committed
7 8 9


Maui.Page
10
{
11 12
    property string currentQuery : ""

Camilo Higuita's avatar
Camilo Higuita committed
13 14
    headBarExitIcon: "edit-clear"
    headBarTitle: searchResults.grid.count + qsTr(" results")
15
    headBar.visible: true
Camilo Higuita's avatar
Camilo Higuita committed
16

17
    PixGrid
18 19 20 21
    {
        id: searchResults
        height: parent.height
        width: parent.width
22
        headBar.visible: false
Camilo Higuita's avatar
Camilo Higuita committed
23

Camilo Higuita's avatar
Camilo Higuita committed
24 25 26 27 28
        holder.emoji: "qrc:/img/assets/BugSearch.png"
        holder.isMask: false
        holder.title : "No Results!"
        holder.body: "Try with another query"
        holder.emojiSize: iconSizes.huge
29 30 31

    }

Camilo higuita's avatar
Camilo higuita committed
32
    footBar.drawBorder: false
33
    footBar.middleContent: Maui.TextField
Camilo Higuita's avatar
Camilo Higuita committed
34 35 36
    {
        id: searchInput
        placeholderText: qsTr("Search...")
Camilo higuita's avatar
Camilo higuita committed
37 38
        width: footBar.middleLayout.width * 0.9

Camilo Higuita's avatar
Camilo Higuita committed
39 40
        onAccepted: runSearch(searchInput.text)
    }
41 42 43 44 45 46

    function runSearch(query)
    {
        searchResults.clear()
        if(query)
        {
47
            currentQuery = query
48 49 50

            var queries = query.split(",")
            for(var i in queries)
51 52 53 54 55 56
            {
                var res =[]
                res.push(pix.get(Q.Query.searchFor_.arg(queries[i])))
                res.push(tag.getUrls(query, true))
                populate(res)
            }
57 58 59 60 61 62 63
        }
    }

    function populate(data)
    {
        if(data.length > 0)
            for(var i in data)
64
                searchResults.model.append(data[i])
65 66
    }
}