From 95e6c2e120ca6623ca9a1a4c3c39abd03be400ea Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Thu, 9 Sep 2021 18:53:44 +0200 Subject: [PATCH] Add a shortcut on username in chat room to put its address in smartSearchBar --- .../ui/modules/Common/Form/SearchBox.qml | 330 +++++++++--------- .../ui/modules/Common/Tooltip/TooltipArea.qml | 7 +- .../modules/Linphone/Chat/IncomingMessage.qml | 4 + .../ui/views/App/Main/ContactEdit.qml | 1 + linphone-app/ui/views/App/Main/MainWindow.qml | 4 + 5 files changed, 182 insertions(+), 164 deletions(-) diff --git a/linphone-app/ui/modules/Common/Form/SearchBox.qml b/linphone-app/ui/modules/Common/Form/SearchBox.qml index 24ff035e6..ec4e297c9 100644 --- a/linphone-app/ui/modules/Common/Form/SearchBox.qml +++ b/linphone-app/ui/modules/Common/Form/SearchBox.qml @@ -7,165 +7,173 @@ import Utils 1.0 // ============================================================================= Item { - id: searchBox - - // --------------------------------------------------------------------------- - - readonly property alias filter: searchField.text - readonly property alias isOpen: searchBox._isOpen - readonly property var view: _content[0] - - property alias entryHeight: menu.entryHeight - property alias maxMenuHeight: menu.maxMenuHeight - property alias placeholderText: searchField.placeholderText - property alias tooltipText : tooltip.text - - default property alias _content: menu._content - - property bool _isOpen: false - - // --------------------------------------------------------------------------- - - signal menuClosed - signal menuOpened - signal menuRequested - signal enterPressed - - // --------------------------------------------------------------------------- - - function closeMenu () { - if (!_isOpen) { - return - } - searchBox.state = '' - _isOpen = false - } - - function openMenu () { - if (_isOpen) { - return - } - searchBox.state = 'opened' - _isOpen = true - } - - function _filter (text) { - var model = searchBox.view.model - Utils.assert(model.setFilter != null, '`model.setFilter` must be defined.') - model.setFilter(text) - } - - - // --------------------------------------------------------------------------- - - implicitHeight: searchField.height - - Item { - implicitHeight: searchField.height + menu.height - width: parent.width - - TextField { - id: searchField - - icon: 'search' - readOnly: !searchBox.enabled - width: parent.width - - Keys.onEscapePressed: searchBox.closeMenu() - Keys.onReturnPressed: { - searchBox.enterPressed() - searchBox.closeMenu() - } - onActiveFocusChanged: { - if (activeFocus && !_isOpen) { - - searchBox.menuRequested() - searchBox.openMenu() - } - } - - onTextChanged: _filter(text) - } - - // ------------------------------------------------------------------------- - - DropDownDynamicMenu { - id: menu - - relativeTo: searchField - relativeY: searchField.height - - // If the menu is focused, the main window loses the active status. - // So It's necessary to map the keys events. - Keys.forwardTo: searchField - - onClosed: searchBox.closeMenu() - } - - Binding { - target: searchBox.view - property: 'width' - value: searchField.width - } - - Binding { - target: searchBox.view - property: 'headerPositioning' - value: searchBox.view.header ? ListView.OverlayHeader : ListView.InlineFooter - } - } - MouseArea - {// Just take hover events and set popup to do its automatic close if mouse is not inside field/popup area - anchors.fill: parent - onContainsMouseChanged: menu.popup.closePolicy=(containsMouse?Controls.Popup.NoAutoClose:Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutside) - hoverEnabled:true - preventStealing: true - propagateComposedEvents:true - onPressed: mouse.accepted=false - onReleased: mouse.accepted=false - onClicked: mouse.accepted=false - onDoubleClicked: mouse.accepted=false - onPressAndHold: mouse.accepted=false - TooltipArea { - id:tooltip - visible: !isOpen && text !== '' - } - } - - // --------------------------------------------------------------------------- - - states: State { - name: 'opened' - } - - transitions: [ - Transition { - from: '' - to: 'opened' - - ScriptAction { - script: { - menu.open() - - searchBox.menuOpened() - } - } - }, - - Transition { - from: 'opened' - to: '' - - ScriptAction { - script: { - menu.close() - - searchField.focus = false - searchField.text = '' - - searchBox.menuClosed() - } - } - } - ] + id: searchBox + + // --------------------------------------------------------------------------- + + readonly property alias filter: searchField.text + readonly property alias isOpen: searchBox._isOpen + readonly property var view: _content[0] + + property alias entryHeight: menu.entryHeight + property alias maxMenuHeight: menu.maxMenuHeight + property alias placeholderText: searchField.placeholderText + property alias tooltipText : tooltip.text + property alias text : searchField.text + + default property alias _content: menu._content + + property bool _isOpen: false + + // --------------------------------------------------------------------------- + + signal menuClosed + signal menuOpened + signal menuRequested + signal enterPressed + + // --------------------------------------------------------------------------- + + function closeMenu () { + if (!_isOpen) { + return + } + searchBox.state = '' + _isOpen = false + } + + function openMenu () { + if (_isOpen) { + return + } + searchBox.state = 'opened' + _isOpen = true + } + + function _filter (text) { + var model = searchBox.view.model + Utils.assert(model.setFilter != null, '`model.setFilter` must be defined.') + model.setFilter(text) + if(!searchField.activeFocus) + searchField.focus = true + if(!_isOpen){ + searchBox.menuRequested() + searchBox.openMenu() + } + } + + + // --------------------------------------------------------------------------- + + implicitHeight: searchField.height + + Item { + implicitHeight: searchField.height + menu.height + width: parent.width + + TextField { + id: searchField + + icon: 'search' + readOnly: !searchBox.enabled + width: parent.width + + Keys.onEscapePressed: searchBox.closeMenu() + Keys.onReturnPressed: { + searchBox.enterPressed() + searchBox.closeMenu() + } + onActiveFocusChanged: { + if (activeFocus && !_isOpen) { + + searchBox.menuRequested() + searchBox.openMenu() + } + } + + onTextChanged: _filter(text) + } + + // ------------------------------------------------------------------------- + + DropDownDynamicMenu { + id: menu + + relativeTo: searchField + relativeY: searchField.height + + // If the menu is focused, the main window loses the active status. + // So It's necessary to map the keys events. + Keys.forwardTo: searchField + + onClosed: searchBox.closeMenu() + } + + Binding { + target: searchBox.view + property: 'width' + value: searchField.width + } + + Binding { + target: searchBox.view + property: 'headerPositioning' + value: searchBox.view.header ? ListView.OverlayHeader : ListView.InlineFooter + } + } + MouseArea + {// Just take hover events and set popup to do its automatic close if mouse is not inside field/popup area + anchors.fill: parent + onContainsMouseChanged: menu.popup.closePolicy=(containsMouse?Controls.Popup.NoAutoClose:Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutside) + hoverEnabled:true + preventStealing: true + propagateComposedEvents:true + onPressed: mouse.accepted=false + onReleased: mouse.accepted=false + onClicked: mouse.accepted=false + onDoubleClicked: mouse.accepted=false + onPressAndHold: mouse.accepted=false + TooltipArea { + id:tooltip + visible: !isOpen && text !== '' + isClickable:false + } + } + + // --------------------------------------------------------------------------- + + states: State { + name: 'opened' + } + + transitions: [ + Transition { + from: '' + to: 'opened' + + ScriptAction { + script: { + menu.open() + + searchBox.menuOpened() + } + } + }, + + Transition { + from: 'opened' + to: '' + + ScriptAction { + script: { + menu.close() + + searchField.focus = false + searchField.text = '' + + searchBox.menuClosed() + } + } + } + ] } diff --git a/linphone-app/ui/modules/Common/Tooltip/TooltipArea.qml b/linphone-app/ui/modules/Common/Tooltip/TooltipArea.qml index 99e29f085..4bd7d56a9 100644 --- a/linphone-app/ui/modules/Common/Tooltip/TooltipArea.qml +++ b/linphone-app/ui/modules/Common/Tooltip/TooltipArea.qml @@ -16,7 +16,7 @@ MouseArea { property bool _visible: false property int hoveringCursor : Qt.PointingHandCursor - property bool isClickable : true + property bool isClickable : false anchors.fill:parent @@ -26,13 +26,14 @@ MouseArea { onContainsMouseChanged: _visible = containsMouse cursorShape: containsMouse ? hoveringCursor : Qt.ArrowCursor - onPressed: mouse.accepted = false + onPressed: { + mouse.accepted = isClickable + } onWheel: { _visible = false wheel.accepted = false } onClicked:{ - console.log("Clicked") if(isClickable){ if(tooltip.delay>0) { tooltip.oldDelay = tooltip.delay diff --git a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml index 8e41a305e..ce71d4696 100644 --- a/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml +++ b/linphone-app/ui/modules/Linphone/Chat/IncomingMessage.qml @@ -44,6 +44,10 @@ RowLayout { delay:0 text:avatar.username+'\n'+$chatEntry.fromSipAddress tooltipParent:mainRow + isClickable: true + onDoubleClicked: { + window.mainSearchBar.text = $chatEntry.fromSipAddress + } } } } diff --git a/linphone-app/ui/views/App/Main/ContactEdit.qml b/linphone-app/ui/views/App/Main/ContactEdit.qml index 7ce2cf051..3a7fb4e26 100644 --- a/linphone-app/ui/views/App/Main/ContactEdit.qml +++ b/linphone-app/ui/views/App/Main/ContactEdit.qml @@ -131,6 +131,7 @@ ColumnLayout { onClicked: sipAddressesMenu.open() TooltipArea { + isClickable: false text: qsTr('tooltipShowConversation') } } diff --git a/linphone-app/ui/views/App/Main/MainWindow.qml b/linphone-app/ui/views/App/Main/MainWindow.qml index 7d816cb4e..98c55bf75 100644 --- a/linphone-app/ui/views/App/Main/MainWindow.qml +++ b/linphone-app/ui/views/App/Main/MainWindow.qml @@ -18,6 +18,7 @@ ApplicationWindow { property string _currentView property var _lockedInfo + property SmartSearchBar mainSearchBar : (mainLoader.item ? mainLoader.item.mainSearchBar : null) // --------------------------------------------------------------------------- @@ -74,6 +75,7 @@ ApplicationWindow { readonly property alias menu: menu readonly property alias timeline: timeline + readonly property alias mainSearchBar: toolBar.mainSearchBar spacing: 0 @@ -88,6 +90,8 @@ ApplicationWindow { // ----------------------------------------------------------------------- ToolBar { + id: toolBar + property alias mainSearchBar : smartSearchBar Layout.fillWidth: true Layout.preferredHeight: MainWindowStyle.toolBar.height hoverEnabled : true