From e25e77f4197921b83b5d15f7af17f3830cde175f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 26 Oct 2016 16:46:59 +0200 Subject: [PATCH] unstable --- tests/resources.qrc | 1 + tests/ui/modules/Common/InvertedMouseArea.qml | 2 +- .../Common/Popup/AbstractDropDownMenu.qml | 27 +++++++----- .../ui/modules/Common/Popup/DesktopPopup.qml | 43 +++++++++++++++++++ tests/ui/modules/Common/SearchBox.qml | 10 ++++- tests/ui/modules/Common/qmldir | 1 + tests/ui/scripts/Utils/utils.js | 11 +++-- tests/ui/views/MainWindow/MainWindow.qml | 31 ++++++++++--- 8 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 tests/ui/modules/Common/Popup/DesktopPopup.qml diff --git a/tests/resources.qrc b/tests/resources.qrc index e437e30f6..db2c1c484 100644 --- a/tests/resources.qrc +++ b/tests/resources.qrc @@ -53,6 +53,7 @@ ui/modules/Common/Menu/Menu.qml ui/modules/Common/Paned.qml ui/modules/Common/Popup/AbstractDropDownMenu.qml + ui/modules/Common/Popup/DesktopPopup.qml ui/modules/Common/Popup/DropDownDynamicMenu.qml ui/modules/Common/Popup/DropDownMenu.qml ui/modules/Common/Popup/PopupShadow.qml diff --git a/tests/ui/modules/Common/InvertedMouseArea.qml b/tests/ui/modules/Common/InvertedMouseArea.qml index 1cf714521..e52370458 100644 --- a/tests/ui/modules/Common/InvertedMouseArea.qml +++ b/tests/ui/modules/Common/InvertedMouseArea.qml @@ -57,7 +57,7 @@ Item { function _checkPosition (positionEvent) { // Propagate event. positionEvent.accepted = false - + console.log('click', positionEvent.x, positionEvent.y) // Click is outside or not. if (!Utils.pointIsInItem(this, item, positionEvent)) { if (_timeout != null) { diff --git a/tests/ui/modules/Common/Popup/AbstractDropDownMenu.qml b/tests/ui/modules/Common/Popup/AbstractDropDownMenu.qml index 2dacf8249..71fc792ef 100644 --- a/tests/ui/modules/Common/Popup/AbstractDropDownMenu.qml +++ b/tests/ui/modules/Common/Popup/AbstractDropDownMenu.qml @@ -74,6 +74,13 @@ Item { } } + // Block clicks, wheel... below menu. + MouseArea { + anchors.fill: content + hoverEnabled: true + onWheel: {} + } + // Menu content. Rectangle { id: content @@ -102,19 +109,17 @@ Item { // ----------------------------------------------------------------- - states: [ - State { - name: 'opened' - when: _isOpen + states: State { + name: 'opened' + when: _isOpen - PropertyChanges { - focus: true // Necessary to use `Keys.onEscapePressed`. - opacity: 1 - target: menu - visible: true - } + PropertyChanges { + focus: true // Necessary to use `Keys.onEscapePressed`. + opacity: 1 + target: menu + visible: true } - ] + } transitions: [ Transition { diff --git a/tests/ui/modules/Common/Popup/DesktopPopup.qml b/tests/ui/modules/Common/Popup/DesktopPopup.qml new file mode 100644 index 000000000..73ced88ab --- /dev/null +++ b/tests/ui/modules/Common/Popup/DesktopPopup.qml @@ -0,0 +1,43 @@ +import QtQuick 2.7 +import QtQuick.Window 2.2 + +import Utils 1.0 + +Item { + id: wrapper + + // Not a private property. Can be used with an id. + default property alias content: content.data + + property alias popupX: popup.x + property alias popupY: popup.y + + function show () { + popup.show() + } + + function hide () { + popup.hide() + } + + x: 0 + y: 0 + height: 0 + width: 0 + visible: false + + Window { + id: popup + + flags: Qt.SplashScreen + height: wrapper.content[0] != null ? wrapper.content[0].height : 0 + width: wrapper.content[0] != null ? wrapper.content[0].width : 0 + + Item { + id: content + + // Fake parent. + property var $parent: wrapper + } + } +} diff --git a/tests/ui/modules/Common/SearchBox.qml b/tests/ui/modules/Common/SearchBox.qml index 069268024..3a98b6d04 100644 --- a/tests/ui/modules/Common/SearchBox.qml +++ b/tests/ui/modules/Common/SearchBox.qml @@ -2,7 +2,7 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import Common.Styles 1.0 - +import Utils 1.0 // =================================================================== // A reusable search input which display a entries model in a menu. // Each entry can be filtered with the search input. @@ -41,6 +41,12 @@ Item { menuOpened() } + function getMenuInstance () { + console.log('instance parent', Utils.getTopParent(item)) + + return menu + } + implicitHeight: searchField.height Item { @@ -70,7 +76,7 @@ Item { DropDownDynamicMenu { id: menu - anchors.top: searchField.bottom + //anchors.top: searchField.bottom launcher: searchField width: searchField.width diff --git a/tests/ui/modules/Common/qmldir b/tests/ui/modules/Common/qmldir index 13f6e1eb1..3b24043b3 100644 --- a/tests/ui/modules/Common/qmldir +++ b/tests/ui/modules/Common/qmldir @@ -56,6 +56,7 @@ Menu 1.0 Menu/Menu.qml Paned 1.0 Paned.qml # Popup +DesktopPopup 1.0 Popup/DesktopPopup.qml DropDownDynamicMenu 1.0 Popup/DropDownDynamicMenu.qml DropDownMenu 1.0 Popup/DropDownMenu.qml PopupShadow 1.0 Popup/PopupShadow.qml diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 20bc18cd2..bf1d99e1d 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -108,10 +108,14 @@ function clearTimeout (timer) { // Returns the top (root) parent of one object. function getTopParent (object) { - var parent = object.parent + function _getTopParent (object) { + return object.$parent || object.parent + } - while (parent.parent != null) { - parent = parent.parent + var parent = _getTopParent(object) + + while (_getTopParent(parent) != null) { + parent = _getTopParent(parent) } return parent @@ -144,6 +148,7 @@ function qmlTypeof (object, className) { function pointIsInItem (source, target, point) { point = source.mapToItem(target.parent, point.x, point.y) + console.log('mapped point', point.x, point.y, target.x, target.y) return ( point.x >= target.x && point.y >= target.y && diff --git a/tests/ui/views/MainWindow/MainWindow.qml b/tests/ui/views/MainWindow/MainWindow.qml index 89907dc1a..7ef8ddd5d 100644 --- a/tests/ui/views/MainWindow/MainWindow.qml +++ b/tests/ui/views/MainWindow/MainWindow.qml @@ -71,20 +71,40 @@ ApplicationWindow { onClicked: Utils.openWindow('NewCall', window) } + DesktopPopup { + id: desktopPopup + + property point coords: { + var point = searchBox.mapToItem(null, 0, searchBox.height) + point.x += window.x + point.y += window.y + + return point + } + + content: searchBox.getMenuInstance() + popupX: coords.x + popupY: coords.y + + onVisibleChanged: !visible && searchBox._hideMenu() + } + // Search. SearchBox { + id: searchBox + Layout.fillWidth: true maxMenuHeight: 300 // See Hick's law for good choice. placeholderText: qsTr('mainSearchBarPlaceholder') entryHeight: 50 - onMenuClosed: content.enabled = true + onMenuClosed: { + console.log('close') + desktopPopup.hide() + } onMenuOpened: { - if (!collapse.isCollapsed()) { - // TODO, open desktop popup. - } - content.enabled = false + desktopPopup.show() } model: model1 @@ -120,7 +140,6 @@ ApplicationWindow { RowLayout { anchors.fill: parent - id: content spacing: 0 // Main menu.