Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | |
| 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 | */ |
| 19 | import QtQuick 2.14 |
| 20 | import QtQuick.Controls 2.14 |
| 21 | import QtQuick.Layouts 1.14 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 22 | import QtGraphicalEffects 1.12 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 23 | import net.jami.Models 1.0 |
| 24 | |
| 25 | Rectangle { |
| 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 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 48 | radius: height/2 |
| 49 | color: "white" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 50 | |
| 51 | FocusScope { |
| 52 | id: fakeFocus |
| 53 | } |
| 54 | |
| 55 | Image { |
| 56 | id: searchIconImage |
| 57 | |
| 58 | anchors.verticalCenter: contactSearchBarRect.verticalCenter |
| 59 | anchors.left: contactSearchBarRect.left |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 60 | anchors.leftMargin: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 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 | |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 70 | ColorOverlay { |
| 71 | anchors.fill: searchIconImage |
| 72 | source: searchIconImage |
| 73 | color: JamiTheme.contactSearchBarPlaceHolderTextFontColor |
| 74 | } |
| 75 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 76 | 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 |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 94 | anchors.leftMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 95 | |
| 96 | text: qsTr("Find or start a conversation") |
ababi | df651a2 | 2020-07-30 13:38:57 +0200 | [diff] [blame] | 97 | font.pointSize: JamiTheme.textFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 98 | 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 | } |
| 113 | } |