SearchView.qml 1.92 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 15 16
    headBarExitIcon: "edit-clear"
    headBarTitle: searchResults.grid.count + qsTr(" results")
    headBarVisible: true

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

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.leftContent:  Maui.ToolButton
33
    {
Camilo Higuita's avatar
Camilo Higuita committed
34 35
        iconName: "view-filter"
    }
36

Camilo Higuita's avatar
Camilo Higuita committed
37 38 39 40 41 42 43 44 45 46 47 48 49
    footBar.middleContent:  TextField
    {
        id: searchInput
        placeholderText: qsTr("Search...")
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment:  Text.AlignVCenter
        selectByMouse: !isMobile
        focus: true
        wrapMode: TextEdit.Wrap
        selectionColor: highlightColor
        selectedTextColor: highlightedTextColor
        onAccepted: runSearch(searchInput.text)
    }
50

Camilo Higuita's avatar
Camilo Higuita committed
51 52 53 54 55
    footBar.rightContent : Maui.ToolButton
    {
        iconName: "edit-clear"
        Layout.alignment: Qt.AlignRight
        onClicked: searchInput.clear()
56 57 58 59 60 61 62
    }

    function runSearch(query)
    {
        searchResults.clear()
        if(query)
        {
63
            currentQuery = query
64 65 66

            var queries = query.split(",")
            for(var i in queries)
67 68 69 70 71 72
            {
                var res =[]
                res.push(pix.get(Q.Query.searchFor_.arg(queries[i])))
                res.push(tag.getUrls(query, true))
                populate(res)
            }
73 74 75 76 77 78 79 80 81 82
        }
    }

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