Debian Codegraph @

qml/Components/HeaderMain.qml

raw
1 /*
2 * This file is part of the 2FA Manager App for Ubuntu Touch
3 * Copyright (C) 2019 Joan CiberSheep
4 *
5 * This App is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 *
10 * This App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 import QtQuick 2.9
21 import Lomiri.Components 1.3
22
23 HeaderBase {
24 signal searchText(string typedText)
25
26 property bool isSearching: false
27
28 contents: Row {
29 anchors.centerIn: parent
30 width: parent.width
31 spacing: units.gu(1.5)
32
33 Label {
34 visible: !isSearching
35 text: header.title
36 textSize: Label.Large
37 color: root.titleColor
38 }
39
40 TextField {
41 id: searchField
42 visible: isSearching
43 width: parent.width
44
45 // Disable predictive text
46 inputMethodHints: Qt.ImhNoPredictiveText
47
48 primaryItem: Icon {
49 width: units.gu(2); height: width
50 name: "find"
51 }
52
53 placeholderText: i18n.tr("Search key…")
54
55 onTextChanged: searchText(text);
56 }
57 }
58
59 leadingActionBar.actions: Action {
60 iconName: "close"
61 visible: isSearching
62 text: i18n.tr("Close")
63
64 onTriggered: closeHeader();
65 }
66
67 trailingActionBar {
68 actions: [
69 Action {
70 iconName: "settings"
71 text: i18n.tr("Settings")
72
73 onTriggered: {
74 if (isSearching) {
75 closeHeader();
76 }
77
78 mainStack.push(Qt.resolvedUrl("PageSettings.qml"));
79 }
80 },
81 Action {
82 iconName: "search"
83 text: i18n.tr("Search")
84 visible: !isSearching
85
86 onTriggered: {
87 isSearching = true;
88 searchField.focus = true;
89 }
90 }
91 ]
92 }
93
94 function closeHeader() {
95 searchField.text = "";
96 isSearching = false;
97 searchField.focus = false;
98 }
99 }