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

unstable

parent 88e0688e
......@@ -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()
}
}
......@@ -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
......
......@@ -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'
......
......@@ -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) {
......
......@@ -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 [
{
......
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