SearchView.qml 1.86 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
Camilo Higuita's avatar
Camilo Higuita committed
6 7 8 9
import org.kde.maui 1.0 as Maui


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 18 19 20 21
    contentData: PixGrid
    {
        id: searchResults
        height: parent.height
        width: parent.width
Camilo Higuita's avatar
Camilo Higuita committed
22 23
        headBarVisible: false

24 25 26 27 28
        holder.message: "<h2>No results!</h2><p>Try with another query</p>"
        holder.emoji: "qrc:/img/assets/face-sleeping.png"

    }

Camilo Higuita's avatar
Camilo Higuita committed
29
    footBar.leftContent:  Maui.ToolButton
30
    {
Camilo Higuita's avatar
Camilo Higuita committed
31 32
        iconName: "view-filter"
    }
33

Camilo Higuita's avatar
Camilo Higuita committed
34 35 36 37 38 39 40 41 42 43 44 45 46
    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)
    }
47

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

    function runSearch(query)
    {
        searchResults.clear()
        if(query)
        {
60
            currentQuery = query
61 62 63

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

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