Commit 667970c7 authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 88e0688e
...@@ -16,22 +16,35 @@ Rectangle { ...@@ -16,22 +16,35 @@ Rectangle {
default property alias _content: content.data default property alias _content: content.data
function show () { signal menuClosed
signal menuOpened
function showMenu () {
if (visible) {
return
}
if (drawOnRoot) { if (drawOnRoot) {
this.x = relativeTo.mapToItem(null, relativeTo.width, 0).x this.x = relativeTo.mapToItem(null, relativeTo.width, 0).x
this.y = relativeTo.mapToItem(null, relativeTo.width, 0).y this.y = relativeTo.mapToItem(null, relativeTo.width, 0).y
} }
visible = true visible = true
menuOpened()
} }
function hide () { function hideMenu () {
if (!visible) {
return
}
visible = false visible = false
menuClosed()
} }
function _computeHeight () { function _computeHeight () {
var model = _content[0].model var model = _content[0].model
if (model == null) { if (model == null || !Utils.qmlTypeof(model, 'QQmlListModel')) {
return content.height return content.height
} }
...@@ -45,6 +58,8 @@ Rectangle { ...@@ -45,6 +58,8 @@ Rectangle {
visible: false visible: false
z: Constants.zPopup z: Constants.zPopup
Keys.onEscapePressed: hideMenu()
Component.onCompleted: { Component.onCompleted: {
if (drawOnRoot) { if (drawOnRoot) {
parent = Utils.getTopParent(this) parent = Utils.getTopParent(this)
...@@ -62,4 +77,11 @@ Rectangle { ...@@ -62,4 +77,11 @@ Rectangle {
effect: PopupShadow {} effect: PopupShadow {}
} }
} }
InvertedMouseArea {
anchors.fill: parent
enabled: parent.visible
onPressed: hideMenu()
}
} }
...@@ -25,7 +25,7 @@ Item { ...@@ -25,7 +25,7 @@ Item {
signal menuOpened () signal menuOpened ()
function _hideMenu () { function _hideMenu () {
menu.hide() menu.hideMenu()
shadow.visible = false shadow.visible = false
searchField.focus = false searchField.focus = false
...@@ -33,7 +33,7 @@ Item { ...@@ -33,7 +33,7 @@ Item {
} }
function _showMenu () { function _showMenu () {
menu.show() menu.showMenu()
shadow.visible = true shadow.visible = true
menuOpened() menuOpened()
...@@ -69,7 +69,7 @@ Item { ...@@ -69,7 +69,7 @@ Item {
anchors.top: searchField.bottom anchors.top: searchField.bottom
width: searchField.width width: searchField.width
Keys.onEscapePressed: _hideMenu() onMenuClosed: _hideMenu()
ScrollableListView { ScrollableListView {
id: list id: list
...@@ -78,13 +78,6 @@ Item { ...@@ -78,13 +78,6 @@ Item {
} }
} }
InvertedMouseArea {
anchors.fill: parent
enabled: menu.visible
onPressed: _hideMenu()
}
PopupShadow { PopupShadow {
id: shadow id: shadow
......
...@@ -44,7 +44,7 @@ RowLayout { ...@@ -44,7 +44,7 @@ RowLayout {
hoverEnabled: true hoverEnabled: true
onClicked: { onClicked: {
menu.show() menu.showMenu()
} }
} }
} }
...@@ -56,7 +56,6 @@ RowLayout { ...@@ -56,7 +56,6 @@ RowLayout {
height: 100 height: 100
width: 120 width: 120
relativeTo: button relativeTo: button
Keys.onEscapePressed: hide()
Rectangle { Rectangle {
color: 'red' color: 'red'
......
...@@ -106,9 +106,9 @@ function clearTimeout (timer) { ...@@ -106,9 +106,9 @@ function clearTimeout (timer) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Returns the top (root) parent of one component. // Returns the top (root) parent of one object.
function getTopParent (component) { function getTopParent (object) {
var parent = component.parent var parent = object.parent
while (parent.parent != null) { while (parent.parent != null) {
parent = parent.parent parent = parent.parent
...@@ -119,6 +119,23 @@ function getTopParent (component) { ...@@ -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[`. // Invoke a `cb` function with each value of the interval: `[0, n[`.
// Return a mapped array created with the returned values of `cb`. // Return a mapped array created with the returned values of `cb`.
function times (n, cb, context) { function times (n, cb, context) {
......
...@@ -111,6 +111,25 @@ TestCase { ...@@ -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 () { function test_times1_data () {
return [ return [
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment