Changeset View
Changeset View
Standalone View
Standalone View
mobile/app/package/contents/ui/SearchField.qml
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright © 2017 Aleix Pol Gonzalez <aleixpol@blue-systems.com> * | ||||
3 | * Copyright © 2019 Carl-Lucien Schwan <schwancarl@protonmail.com> * | ||||
4 | * * | ||||
5 | * This program is free software; you can redistribute it and/or * | ||||
6 | * modify it under the terms of the GNU General Public License as * | ||||
7 | * published by the Free Software Foundation; either version 2 of * | ||||
8 | * the License or (at your option) version 3 or any later version * | ||||
9 | * accepted by the membership of KDE e.V. (or its successor approved * | ||||
10 | * by the membership of KDE e.V.), which shall act as a proxy * | ||||
11 | * defined in Section 14 of version 3 of the license. * | ||||
12 | * * | ||||
13 | * This program is distributed in the hope that it will be useful, * | ||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
16 | * GNU General Public License for more details. * | ||||
17 | * * | ||||
18 | * You should have received a copy of the GNU General Public License * | ||||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||||
20 | ***************************************************************************/ | ||||
21 | | ||||
22 | import QtQuick 2.5 | ||||
23 | import QtQuick.Controls 2.5 | ||||
24 | import org.kde.kirigami 2.1 as Kirigami | ||||
25 | | ||||
26 | /** | ||||
27 | * SearchField component largely inspired by the one from Discover | ||||
28 | */ | ||||
29 | TextField { | ||||
30 | id: searchField | ||||
31 | property QtObject page | ||||
32 | property string currentSearchText | ||||
33 | | ||||
34 | placeholderText: i18n("Search...") | ||||
35 | | ||||
36 | Shortcut { | ||||
37 | sequence: "Ctrl+F" | ||||
38 | onActivated: { | ||||
39 | searchField.forceActiveFocus() | ||||
40 | searchField.selectAll() | ||||
41 | } | ||||
42 | } | ||||
43 | onAccepted: { | ||||
44 | currentSearchText = text | ||||
45 | } | ||||
46 | | ||||
47 | hoverEnabled: true | ||||
48 | | ||||
49 | function clearText() { | ||||
50 | searchField.text = "" | ||||
51 | searchField.accepted() | ||||
52 | } | ||||
53 | | ||||
54 | ToolButton { | ||||
55 | anchors { | ||||
56 | top: parent.top | ||||
57 | right: parent.right | ||||
58 | bottom: parent.bottom | ||||
59 | margins: Kirigami.Units.smallSpacing | ||||
60 | } | ||||
61 | icon.name: "edit-clear" | ||||
62 | visible: searchField.text != "" | ||||
63 | onClicked: clearText() | ||||
64 | } | ||||
65 | | ||||
66 | Connections { | ||||
67 | ignoreUnknownSignals: true | ||||
68 | target: page | ||||
69 | onClearSearch: clearText() | ||||
70 | } | ||||
71 | } |