blob: 896b48c7c1aefdef4bff0a568f4e10b1aaecc3ad [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001
2/*
3 * Copyright (C) 2020 by Savoir-faire Linux
4 * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19import QtQuick 2.14
20import QtQuick.Controls 2.14
21import QtQuick.Layouts 1.14
22import net.jami.Models 1.0
23
24Rectangle {
25 id: contactSearchBarRect
26
27 signal contactSearchBarTextChanged(string text)
28
29 function setPlaceholderString(str) {
30 placeholderTextForSearchBar.text = str
31 }
32
33
34 /*
35 * Hack - there is no real way now to make TextField lose its focus,
36 * unless transfer it to other component.
37 */
38 function clearFocus() {
39 fakeFocus.forceActiveFocus()
40 }
41
42 function clearText() {
43 contactSearchBar.clear()
44 fakeFocus.forceActiveFocus()
45 }
46
47 border.color: JamiTheme.pressColor
48 radius: 10
49 color: contactSearchBar.activeFocus ? "white" : JamiTheme.contactSearchBarPlaceHolderGreyBackground
50
51 FocusScope {
52 id: fakeFocus
53 }
54
55 Image {
56 id: searchIconImage
57
58 anchors.verticalCenter: contactSearchBarRect.verticalCenter
59 anchors.left: contactSearchBarRect.left
60 anchors.leftMargin: 5
61
62 width: 20
63 height: 20
64
65 fillMode: Image.PreserveAspectFit
66 mipmap: true
67 source: "qrc:/images/icons/ic_baseline-search-24px.svg"
68 }
69
70 TextField {
71 id: contactSearchBar
72
73 anchors.verticalCenter: contactSearchBarRect.verticalCenter
74 anchors.left: searchIconImage.right
75
76 width: contactSearchBarRect.width - searchIconImage.width - 10
77 height: contactSearchBarRect.height - 5
78
79 font.pointSize: JamiTheme.textFontSize - 1
80 selectByMouse: true
81 selectionColor: JamiTheme.contactSearchBarPlaceHolderTextFontColor
82
83 Text {
84 id: placeholderTextForSearchBar
85
86 anchors.verticalCenter: contactSearchBar.verticalCenter
87 anchors.left: contactSearchBar.left
88 anchors.leftMargin: 5
89
90 text: qsTr("Find or start a conversation")
91 font.pointSize: JamiTheme.textFontSize - 1
92 color: JamiTheme.contactSearchBarPlaceHolderTextFontColor
93 visible: !contactSearchBar.text && !contactSearchBar.activeFocus
94 }
95
96 background: Rectangle {
97 id: searchBarBackground
98
99 color: "transparent"
100 }
101
102 onTextChanged: {
103 contactSearchBarRect.contactSearchBarTextChanged(
104 contactSearchBar.text)
105 }
106 }
107}