PageMessageSearch.qml 6.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * Copyright (C) 2014-2017 CZ.NIC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

import QtQuick 2.7
import QtQuick.Controls 2.1
26
import QtQuick.Layouts 1.3
27
import cz.nic.mobileDatovka 1.0
28
import cz.nic.mobileDatovka.messages 1.0
29
import cz.nic.mobileDatovka.models 1.0
30 31 32 33 34 35

/*
 * Roles are defined in MessageListModel::roleNames() and are accessed directly
 * via their names.
 */

36 37
Item {
    id: pageMessageSearch
38

39 40 41
    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
Martin Straka's avatar
Martin Straka committed
42

43 44 45 46 47 48
    property int soughtMsgType: MessageType.TYPE_RECEIVED | MessageType.TYPE_SENT
    Component.onCompleted: {
         searchPhraseText.forceActiveFocus()
    }
    MessageListModel {
        id: messageModel
49 50
        Component.onCompleted: {
        }
51 52 53 54 55 56 57 58 59 60 61 62 63 64
    }
    PageHeader {
        id: headerBar
        title: qsTr("Search message")
        Item {
            anchors.left: parent.left
            width: parent.width * 0.5
            height: parent.height
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    statusBar.visible = false
                    pageView.pop(StackView.Immediate)
                }
65 66
            }
        }
67 68 69 70 71 72 73 74 75 76
        Row {
            anchors.verticalCenter: parent.verticalCenter
            spacing: defaultMargin
            anchors.right: parent.right
            anchors.rightMargin: defaultMargin
            Image {
                id: actionButton
                anchors.verticalCenter: parent.verticalCenter
                sourceSize.height: imgHeight
                source: "qrc:/ui/magnify.svg"
77 78 79
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
80 81 82 83
                        // Set textfield focus on false = hide input keyboard
                        // and obtain textfield value
                        searchPhraseText.focus = false
                        emptyList.visible = searchPanel.doSearchRequest()
84 85 86 87
                    }
                }
            }
        }
88 89 90 91 92 93 94 95
    } // PageHeader
    Pane {
        id: searchPanel
        anchors.top: headerBar.bottom
        width: parent.width
        function doSearchRequest() {
            return (messages.searchMsg(messageModel, searchPhraseText.text, soughtMsgType) <= 0)
        }
96
        Column {
97 98
            anchors.right: parent.right
            anchors.left: parent.left
99
            spacing: formItemVerticalSpacing
100 101 102
            ComboBox {
                id: searchOptionComboBox
                currentIndex: 0
103
                width: parent.width
104 105 106 107 108
                height: inputItemHeight
                textRole: "label"
                font.pointSize: defaultTextFont.font.pointSize
                delegate: ItemDelegate {
                    width: searchOptionComboBox.width
109
                    height: inputItemHeight
110 111 112 113 114 115
                    contentItem: Text {
                        text: label
                        color: datovkaPalette.text
                        font.pointSize: defaultTextFont.font.pointSize
                        elide: Text.ElideRight
                        verticalAlignment: Text.AlignVCenter
Martin Straka's avatar
Martin Straka committed
116
                    }
117
                    highlighted: searchOptionComboBox.highlightedIndex == index
Martin Straka's avatar
Martin Straka committed
118
                }
119 120 121 122 123 124 125 126 127 128 129 130 131
                model: ListModel {
                    id: searchOptionComboBoxModel
                    // Don't change position of list elements and keys.
                    /* Cannot have an expression here becacuse QML complains that it cannot use script for property value. */
                    ListElement { label: qsTr("All messages"); value: -1 }
                    ListElement { label: qsTr("Received messages"); value: MessageType.TYPE_RECEIVED }
                    ListElement { label: qsTr("Sent messages"); value: MessageType.TYPE_SENT }
                }
                onCurrentIndexChanged: {
                    if (searchOptionComboBoxModel.get(currentIndex).value == -1) {
                        soughtMsgType = MessageType.TYPE_RECEIVED | MessageType.TYPE_SENT
                    } else {
                        soughtMsgType = searchOptionComboBoxModel.get(currentIndex).value
132 133 134
                    }
                }
            }
135 136 137 138
            TextField {
                id: searchPhraseText
                placeholderText: qsTr("Enter phrase")
                focus: true
139
                width: parent.width
140 141 142 143 144 145 146 147 148 149 150 151 152 153
                font.pointSize: defaultTextFont.font.pointSize
                height: inputItemHeight
                onAccepted: emptyList.visible = searchPanel.doSearchRequest()
                InputLineMenu {
                    id: searchPhraseTextMenu
                    inputTextControl: searchPhraseText
                    isPassword: false
                }
                onPressAndHold: {
                    if (settings.useExplicitClipboardOperations()) {
                        searchPhraseTextMenu.implicitWidth = computeMenuWidth(searchPhraseTextMenu)
                        searchPhraseTextMenu.open()
                    }
                }
154 155
            }
        }
156 157 158 159 160 161 162 163 164 165
    } // Pane
    Text {
        id: emptyList
        visible: false
        color: datovkaPalette.text
        anchors.centerIn: parent
        width: parent.width
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.Wrap
        text: qsTr("No message found for given search phrase.")
166
    }
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    MessageList {
        id: messageList
        anchors.top: searchPanel.bottom
        anchors.bottom: parent.bottom
        clip: true
        spacing: 1
        opacity: 1
        visible: true
        width: parent.width
        interactive: true
        model: messageModel
        onMsgClicked: {
            statusBar.visible = false
            pageView.push(pageMessageDetail, {
                    "pageView": pageView,
                    "statusBar": statusBar,
                    "fromLocalDb": true,
                    "acntName": "",
                    "userName": userName,
                    "msgType": msgType,
                    "msgId": msgId,
                    "messageModel": messageModel
Martin Straka's avatar
Martin Straka committed
189
                })
190 191 192
        }
    } // MessageList
} // Item