diff --git a/src/app/mainview/components/AddMemberPanel.qml b/src/app/mainview/components/AddMemberPanel.qml index 954be20d42611c300e05a8338f1e7c4cb122cd99..a958615c6daa9c452a648d067f298fb902ab65b9 100644 --- a/src/app/mainview/components/AddMemberPanel.qml +++ b/src/app/mainview/components/AddMemberPanel.qml @@ -34,7 +34,7 @@ Rectangle { anchors.fill: parent - ContactSearchBar { + Searchbar { id: contactPickerContactSearchBar Layout.alignment: Qt.AlignCenter @@ -44,7 +44,7 @@ Rectangle { placeHolderText: JamiStrings.addParticipant - onContactSearchBarTextChanged: { + onSearchBarTextChanged: function(text){ ContactAdapter.setSearchFilter(text); } } diff --git a/src/app/mainview/components/ChatViewHeader.qml b/src/app/mainview/components/ChatViewHeader.qml index 4672c1d5c3447eb5b3b4db1459b4f371f3aff40b..9d7c82ebe7c1efb4629c0eb589142f9363f22a08 100644 --- a/src/app/mainview/components/ChatViewHeader.qml +++ b/src/app/mainview/components/ChatViewHeader.qml @@ -151,12 +151,29 @@ Rectangle { Searchbar { id: rowSearchBar + reductionEnabled: true + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter Layout.preferredHeight: 30 - Layout.preferredWidth: 30 + (isOpen? JamiTheme.searchbarSize : 0) + Layout.preferredWidth: 40 + (isOpen? JamiTheme.searchbarSize : 0) + colorSearchBar: JamiTheme.backgroundColor + + Behavior on Layout.preferredWidth { + NumberAnimation { + duration: 150 + } + } visible: root.swarmDetailsVisibility + onSearchBarTextChanged: function(text){ + MessagesAdapter.searchbarPrompt = text; + } + + onSearchClicked: { + root.searchClicked(); + } + Shortcut { sequence: "Ctrl+Shift+F" context: Qt.ApplicationShortcut diff --git a/src/app/mainview/components/ContactPicker.qml b/src/app/mainview/components/ContactPicker.qml index df0eecfcf52f982f85bf70dec63ae17f82db1c8b..cddfd72ad71ad432a8d3ec7c185f3d3a87d634cf 100644 --- a/src/app/mainview/components/ContactPicker.qml +++ b/src/app/mainview/components/ContactPicker.qml @@ -89,7 +89,7 @@ Popup { } } - ContactSearchBar { + Searchbar { id: contactPickerContactSearchBar Layout.alignment: Qt.AlignCenter @@ -99,7 +99,7 @@ Popup { placeHolderText: type === ContactList.TRANSFER ? JamiStrings.transferTo : JamiStrings.addParticipant - onContactSearchBarTextChanged: { + onSearchBarTextChanged: function(text){ ContactAdapter.setSearchFilter(text); } } diff --git a/src/app/mainview/components/Searchbar.qml b/src/app/mainview/components/Searchbar.qml index d562d65c9f9f9b5b105277d34ec1ef578f5435a6..a6b433b00ea98d63d0e13ffc14104c992ee22a3f 100644 --- a/src/app/mainview/components/Searchbar.qml +++ b/src/app/mainview/components/Searchbar.qml @@ -1,6 +1,5 @@ /* - * Copyright (C) 2023 Savoir-faire Linux Inc. - * Author: Nicolas Vengeon <nicolas.vengeon@savoirfairelinux.com> + * Copyright (C) 2020-2023 Savoir-faire Linux Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -16,45 +15,79 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ import QtQuick -import QtQuick.Layouts import QtQuick.Controls +import net.jami.Models 1.1 import net.jami.Adapters 1.1 import net.jami.Constants 1.1 import "../../commoncomponents" -RowLayout { +Rectangle { id: root + + signal searchBarTextChanged(string text) + signal returnPressedWhileSearching + signal searchClicked + + property bool reductionEnabled: false + property alias textContent: textArea.text + property alias placeHolderText: textArea.placeholderText + + property var colorSearchBar: JamiTheme.secondaryBackgroundColor + property string currentConversationId: CurrentConversation.id - property bool isOpen: extrasPanel.isOpen(ChatView.MessagesResearchPanel) + property bool isOpen: reductionEnabled ? extrasPanel.isOpen(ChatView.MessagesResearchPanel) : true onIsOpenChanged: { if (isOpen) textArea.forceActiveFocus() } + function clearText() { + textArea.clear(); + textArea.forceActiveFocus(); + } + + radius: JamiTheme.primaryRadius + color: isOpen ? colorSearchBar : "transparent" + + onFocusChanged: { + if (focus) { + textArea.forceActiveFocus(); + } + } + + LineEditContextMenu { + id: lineEditContextMenu + + lineEditObj: textArea + } + PushButton { - id: startSearchMessages - Layout.preferredHeight: 30 - Layout.preferredWidth: 30 + id: startSearch - source: JamiResources.search_svg - normalColor: JamiTheme.chatviewBgColor + anchors.verticalCenter: root.verticalCenter + anchors.left: root.left + anchors.leftMargin: 10 + hoverEnabled: reductionEnabled + enabled: reductionEnabled + + + source: JamiResources.ic_baseline_search_24dp_svg + normalColor: "transparent" imageColor: JamiTheme.chatviewButtonColor - onClicked: chatViewHeader.searchClicked() + onClicked: root.searchClicked() } Rectangle { id: rectTextArea - Layout.preferredHeight: startSearchMessages.height - Layout.alignment: Qt.AlignVCenter - + height: root.height-5 + anchors.left: startSearch.right + anchors.right: root.right + anchors.verticalCenter: root.verticalCenter color: "transparent" - border.color: JamiTheme.chatviewTextColor - radius: 10 - border.width: 2 opacity: isOpen visible: opacity @@ -65,7 +98,7 @@ RowLayout { } width: isOpen ? JamiTheme.searchbarSize : 0 - Behavior on Layout.preferredWidth { + Behavior on width { NumberAnimation { duration: 150 } @@ -73,45 +106,54 @@ RowLayout { TextField { id: textArea + property bool dontShowFocusState: true background.visible: false - anchors.right: clearTextButton.left - anchors.left: rectTextArea.left + + + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.right: textArea.text.length ? clearTextButton.left : parent.right + color: JamiTheme.chatviewTextColor + placeholderText: JamiStrings.search placeholderTextColor: JamiTheme.chatviewTextColor - onTextChanged: { - MessagesAdapter.searchbarPrompt = text; + height: root.height - 5 + + font.pointSize: JamiTheme.textFontSize + font.kerning: true + + onTextChanged: root.searchBarTextChanged(textArea.text) + onReleased: function (event) { + if (event.button === Qt.RightButton) + lineEditContextMenu.openMenuAt(event); } } PushButton { id: clearTextButton - anchors.verticalCenter: rectTextArea.verticalCenter - anchors.right: rectTextArea.right - anchors.margins: 5 - preferredSize: 21 - radius: rectTextArea.radius + anchors.verticalCenter: parent.verticalCenter + anchors.right: parent.right + anchors.rightMargin: 15 + + preferredSize: 15 + radius: JamiTheme.primaryRadius + visible: textArea.text.length opacity: visible ? 1 : 0 - normalColor: "transparent" - imageColor: JamiTheme.chatviewButtonColor + + normalColor: root.color + imageColor: JamiTheme.primaryForegroundColor + source: JamiResources.ic_clear_24dp_svg toolTipText: JamiStrings.clearText - property string convId: CurrentConversation.id - onConvIdChanged: { - textArea.clear(); - } - - onClicked: { - textArea.clear(); - textArea.forceActiveFocus(); - } + onClicked: textArea.clear() Behavior on opacity { NumberAnimation { @@ -121,4 +163,13 @@ RowLayout { } } } + + Keys.onPressed: function (keyEvent) { + if (keyEvent.key === Qt.Key_Enter || keyEvent.key === Qt.Key_Return) { + if (textArea.text !== "") { + returnPressedWhileSearching(); + keyEvent.accepted = true; + } + } + } } diff --git a/src/app/mainview/components/SidePanel.qml b/src/app/mainview/components/SidePanel.qml index cd5b6166d467da3e100363acaa188c80a25b6377..170ade693d2e7e3167a0307375a5149131f4e44a 100644 --- a/src/app/mainview/components/SidePanel.qml +++ b/src/app/mainview/components/SidePanel.qml @@ -244,13 +244,13 @@ SidePanelBase { } } - ContactSearchBar { + Searchbar { id: contactSearchBar Layout.fillHeight: true Layout.fillWidth: true - onContactSearchBarTextChanged: function (text) { + onSearchBarTextChanged: function(text){ // not calling positionViewAtBeginning will cause // sort animation visual bugs conversationListView.positionViewAtBeginning()