blob: ef75bbcd96c330dd664a863308a0621c3e9fbef6 [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
35 /*
36 * Hack - there is no real way now to make TextField lose its focus,
37 * unless transfer it to other component.
38 */
39 function clearFocus() {
40 fakeFocus.forceActiveFocus()
41 }
42
43 function clearText() {
44 contactSearchBar.clear()
45 fakeFocus.forceActiveFocus()
46 }
47
ababidf651a22020-07-30 13:38:57 +020048 radius: height/2
49 color: "white"
Sébastien Blin1f915762020-08-03 13:27:42 -040050
51 FocusScope {
52 id: fakeFocus
53 }
54
55 Image {
56 id: searchIconImage
57
58 anchors.verticalCenter: contactSearchBarRect.verticalCenter
59 anchors.left: contactSearchBarRect.left
ababidf651a22020-07-30 13:38:57 +020060 anchors.leftMargin: 8
Sébastien Blin1f915762020-08-03 13:27:42 -040061
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
ababidf651a22020-07-30 13:38:57 +020070 ColorOverlay {
71 anchors.fill: searchIconImage
72 source: searchIconImage
73 color: JamiTheme.contactSearchBarPlaceHolderTextFontColor
74 }
75
Sébastien Blin1f915762020-08-03 13:27:42 -040076 TextField {
77 id: contactSearchBar
78
79 anchors.verticalCenter: contactSearchBarRect.verticalCenter
80 anchors.left: searchIconImage.right
81
82 width: contactSearchBarRect.width - searchIconImage.width - 10
83 height: contactSearchBarRect.height - 5
84
85 font.pointSize: JamiTheme.textFontSize - 1
86 selectByMouse: true
87 selectionColor: JamiTheme.contactSearchBarPlaceHolderTextFontColor
88
89 Text {
90 id: placeholderTextForSearchBar
91
92 anchors.verticalCenter: contactSearchBar.verticalCenter
93 anchors.left: contactSearchBar.left
ababidf651a22020-07-30 13:38:57 +020094 anchors.leftMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -040095
96 text: qsTr("Find or start a conversation")
ababidf651a22020-07-30 13:38:57 +020097 font.pointSize: JamiTheme.textFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -040098 color: JamiTheme.contactSearchBarPlaceHolderTextFontColor
99 visible: !contactSearchBar.text && !contactSearchBar.activeFocus
100 }
101
102 background: Rectangle {
103 id: searchBarBackground
104
105 color: "transparent"
106 }
107
108 onTextChanged: {
109 contactSearchBarRect.contactSearchBarTextChanged(
110 contactSearchBar.text)
111 }
112 }
Sébastien Blin214d9ad2020-08-13 13:05:17 -0400113
114 Shortcut {
115 sequence: "Ctrl+F"
116 context: Qt.ApplicationShortcut
117 onActivated: contactSearchBar.forceActiveFocus()
118 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400119}