SearchView.qml 1.72 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
{
Camilo Higuita's avatar
Camilo Higuita committed
11 12 13 14
    headBarExitIcon: "edit-clear"
    headBarTitle: searchResults.grid.count + qsTr(" results")
    headBarVisible: true

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

22 23 24 25 26
        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
27
    footBar.leftContent:  Maui.ToolButton
28
    {
Camilo Higuita's avatar
Camilo Higuita committed
29 30
        iconName: "view-filter"
    }
31

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

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

    function runSearch(query)
    {
        searchResults.clear()
        if(query)
        {
            console.log(query)
Camilo Higuita's avatar
Camilo Higuita committed
59
            headBarTitle = query
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

            var queries = query.split(",")
            for(var i in queries)
                populate(pix.get(Q.Query.searchFor_.arg(queries[i])))
        }
    }

    function populate(data)
    {

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