blob: 89fb42c9ea79a077b58680d61d43be691ae5363b [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
ababidf651a22020-07-30 13:38:57 +020022import QtGraphicalEffects 1.12
Sébastien Blin1f915762020-08-03 13:27:42 -040023import net.jami.Models 1.0
24
25Rectangle {
26 id: contactSearchBarRect
27
28 signal contactSearchBarTextChanged(string text)
29
30 function setPlaceholderString(str) {
31 placeholderTextForSearchBar.text = str
32 }
33
34
agsantosc5687502020-09-03 21:19:10 -040035 // Hack - there is no real way now to make TextField lose its focus,
36 // unless transfer it to other component.
Sébastien Blin1f915762020-08-03 13:27:42 -040037 function clearFocus() {
38 fakeFocus.forceActiveFocus()
39 }
40
41 function clearText() {
42 contactSearchBar.clear()
43 fakeFocus.forceActiveFocus()
44 }
45
ababidf651a22020-07-30 13:38:57 +020046 radius: height/2
47 color: "white"
Sébastien Blin1f915762020-08-03 13:27:42 -040048
49 FocusScope {
50 id: fakeFocus
51 }
52
53 Image {
54 id: searchIconImage
55
56 anchors.verticalCenter: contactSearchBarRect.verticalCenter
57 anchors.left: contactSearchBarRect.left
ababidf651a22020-07-30 13:38:57 +020058 anchors.leftMargin: 8
Sébastien Blin1f915762020-08-03 13:27:42 -040059
60 width: 20
61 height: 20
62
63 fillMode: Image.PreserveAspectFit
64 mipmap: true
65 source: "qrc:/images/icons/ic_baseline-search-24px.svg"
66 }
67
ababidf651a22020-07-30 13:38:57 +020068 ColorOverlay {
69 anchors.fill: searchIconImage
70 source: searchIconImage
71 color: JamiTheme.contactSearchBarPlaceHolderTextFontColor
72 }
73
Sébastien Blin1f915762020-08-03 13:27:42 -040074 TextField {
75 id: contactSearchBar
76
77 anchors.verticalCenter: contactSearchBarRect.verticalCenter
78 anchors.left: searchIconImage.right
79
80 width: contactSearchBarRect.width - searchIconImage.width - 10
81 height: contactSearchBarRect.height - 5
82
83 font.pointSize: JamiTheme.textFontSize - 1
84 selectByMouse: true
85 selectionColor: JamiTheme.contactSearchBarPlaceHolderTextFontColor
86
87 Text {
88 id: placeholderTextForSearchBar
89
90 anchors.verticalCenter: contactSearchBar.verticalCenter
91 anchors.left: contactSearchBar.left
ababidf651a22020-07-30 13:38:57 +020092 anchors.leftMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040093
94 text: qsTr("Find or start a conversation")
ababidf651a22020-07-30 13:38:57 +020095 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -040096 color: JamiTheme.contactSearchBarPlaceHolderTextFontColor
97 visible: !contactSearchBar.text && !contactSearchBar.activeFocus
98 }
99
100 background: Rectangle {
101 id: searchBarBackground
102
103 color: "transparent"
104 }
105
106 onTextChanged: {
107 contactSearchBarRect.contactSearchBarTextChanged(
108 contactSearchBar.text)
109 }
110 }
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400111
112 Shortcut {
113 sequence: "Ctrl+F"
114 context: Qt.ApplicationShortcut
115 onActivated: contactSearchBar.forceActiveFocus()
116 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400117}