diff --git a/tests/ui/modules/Common/Popup/DropDownMenu.qml b/tests/ui/modules/Common/Popup/DropDownMenu.qml index 66a310a89..c659e3135 100644 --- a/tests/ui/modules/Common/Popup/DropDownMenu.qml +++ b/tests/ui/modules/Common/Popup/DropDownMenu.qml @@ -16,22 +16,35 @@ Rectangle { default property alias _content: content.data - function show () { + signal menuClosed + signal menuOpened + + function showMenu () { + if (visible) { + return + } + if (drawOnRoot) { this.x = relativeTo.mapToItem(null, relativeTo.width, 0).x this.y = relativeTo.mapToItem(null, relativeTo.width, 0).y } visible = true + menuOpened() } - function hide () { + function hideMenu () { + if (!visible) { + return + } + visible = false + menuClosed() } function _computeHeight () { var model = _content[0].model - if (model == null) { + if (model == null || !Utils.qmlTypeof(model, 'QQmlListModel')) { return content.height } @@ -45,6 +58,8 @@ Rectangle { visible: false z: Constants.zPopup + Keys.onEscapePressed: hideMenu() + Component.onCompleted: { if (drawOnRoot) { parent = Utils.getTopParent(this) @@ -62,4 +77,11 @@ Rectangle { effect: PopupShadow {} } } + + InvertedMouseArea { + anchors.fill: parent + enabled: parent.visible + + onPressed: hideMenu() + } } diff --git a/tests/ui/modules/Common/SearchBox.qml b/tests/ui/modules/Common/SearchBox.qml index c0b023f4e..6aab9e4a8 100644 --- a/tests/ui/modules/Common/SearchBox.qml +++ b/tests/ui/modules/Common/SearchBox.qml @@ -25,7 +25,7 @@ Item { signal menuOpened () function _hideMenu () { - menu.hide() + menu.hideMenu() shadow.visible = false searchField.focus = false @@ -33,7 +33,7 @@ Item { } function _showMenu () { - menu.show() + menu.showMenu() shadow.visible = true menuOpened() @@ -69,7 +69,7 @@ Item { anchors.top: searchField.bottom width: searchField.width - Keys.onEscapePressed: _hideMenu() + onMenuClosed: _hideMenu() ScrollableListView { id: list @@ -78,13 +78,6 @@ Item { } } - InvertedMouseArea { - anchors.fill: parent - enabled: menu.visible - - onPressed: _hideMenu() - } - PopupShadow { id: shadow diff --git a/tests/ui/modules/Linphone/Call/CallControls.qml b/tests/ui/modules/Linphone/Call/CallControls.qml index d671eb997..8240c5439 100644 --- a/tests/ui/modules/Linphone/Call/CallControls.qml +++ b/tests/ui/modules/Linphone/Call/CallControls.qml @@ -44,7 +44,7 @@ RowLayout { hoverEnabled: true onClicked: { - menu.show() + menu.showMenu() } } } @@ -56,7 +56,6 @@ RowLayout { height: 100 width: 120 relativeTo: button - Keys.onEscapePressed: hide() Rectangle { color: 'red' diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 4149ebf38..32c66126c 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -106,9 +106,9 @@ function clearTimeout (timer) { // ------------------------------------------------------------------- -// Returns the top (root) parent of one component. -function getTopParent (component) { - var parent = component.parent +// Returns the top (root) parent of one object. +function getTopParent (object) { + var parent = object.parent while (parent.parent != null) { parent = parent.parent @@ -119,6 +119,23 @@ function getTopParent (component) { // ------------------------------------------------------------------- +// Test the type of a qml object. +// Warning: this function is probably not portable +// on new versions of Qt. +// +// So, if you want to use it on a specific `className`, please to add +// a test in `test_qmlTypeof_data` of `utils.spec.qml`. +function qmlTypeof (object, className) { + var str = object.toString() + + return ( + str.indexOf(className + '(') == 0 || + str.indexOf(className + '_QML') == 0 + ) +} + +// ------------------------------------------------------------------- + // Invoke a `cb` function with each value of the interval: `[0, n[`. // Return a mapped array created with the returned values of `cb`. function times (n, cb, context) { diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml index d06c3292f..3f1077851 100644 --- a/tests/ui/scripts/Utils/utils.spec.qml +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -111,6 +111,25 @@ TestCase { // ----------------------------------------------------------------- + function test_qmlTypeof_data () { + return [ + { + component: 'import QtQuick 2.7; ListModel {}', + result: true, + type: 'QQmlListModel' + } + ] + } + + function test_qmlTypeof (data) { + var object = Qt.createQmlObject(data.component, testCase) + verify(object) + + compare(Utils.qmlTypeof(object, data.type), data.result) + } + + // ----------------------------------------------------------------- + function test_times1_data () { return [ {