Commit 9976c543 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(MainWindow): main search bar can get out of the window

parent 2fa7c843
......@@ -10,6 +10,7 @@ import Utils 1.0
Item {
id: item
property bool _mouseAlwaysOutside
property var _mouseArea
// When emitted, returns a function to test if the click
......@@ -21,7 +22,9 @@ Item {
_mouseArea = builder.createObject()
}
_mouseArea.parent = Utils.getTopParent(item)
_mouseArea.parent = Utils.getTopParent(item, true)
_mouseAlwaysOutside =
_mouseArea.parent !== Utils.getTopParent(item)
}
function _deleteMouseArea () {
......@@ -59,7 +62,7 @@ Item {
positionEvent.accepted = false
// Click is outside or not.
if (!Utils.pointIsInItem(this, item, positionEvent)) {
if (_mouseAlwaysOutside || !Utils.pointIsInItem(this, item, positionEvent)) {
if (_timeout != null) {
// Remove existing timeout to avoid the creation of
// many children.
......
......@@ -115,9 +115,8 @@ Item {
PropertyChanges {
focus: true // Necessary to use `Keys.onEscapePressed`.
opacity: 1
opacity: 1.0
target: menu
visible: true
}
}
......@@ -126,6 +125,10 @@ Item {
from: ''
to: 'opened'
ScriptAction {
script: menu.visible = true
}
NumberAnimation {
duration: PopupStyle.animation.openingDuration
easing.type: Easing.InOutQuad
......@@ -135,7 +138,7 @@ Item {
SequentialAnimation {
PauseAnimation {
duration: PopupStyle.animation.closingDuration
duration: PopupStyle.animation.openingDuration
}
ScriptAction {
......@@ -148,17 +151,10 @@ Item {
from: 'opened'
to: ''
NumberAnimation {
duration: PopupStyle.animation.openingDuration
easing.type: Easing.InOutQuad
property: 'opacity'
target: menu
}
NumberAnimation {
duration: PopupStyle.animation.closingDuration
easing.type: Easing.InOutQuad
property: 'visible' // Ugly, use `NumberAnimation` with a bool.
property: 'opacity'
target: menu
}
......@@ -168,7 +164,10 @@ Item {
}
ScriptAction {
script: menuClosed()
script: {
visible = false
menuClosed()
}
}
}
}
......
import QtQuick 2.7
import QtQuick.Window 2.2
import Common.Styles 1.0
// ===================================================================
Item {
......@@ -10,13 +12,14 @@ Item {
property alias popupY: popup.y
default property alias _content: content.data
property bool _isOpen: false
function show () {
popup.show()
_isOpen = true
}
function hide () {
popup.hide()
_isOpen = false
}
// DO NOT TOUCH THIS PROPERTIES.
......@@ -34,6 +37,7 @@ Item {
id: popup
flags: Qt.SplashScreen
opacity: 0
height: _content[0] != null ? _content[0].height : 0
width: _content[0] != null ? _content[0].width : 0
......@@ -44,4 +48,56 @@ Item {
property var $parent: wrapper
}
}
// -----------------------------------------------------------------
states: State {
name: 'opened'
when: _isOpen
PropertyChanges {
opacity: 1.0
target: popup
}
}
transitions: [
Transition {
from: ''
to: 'opened'
ScriptAction {
script: popup.show()
}
NumberAnimation {
duration: PopupStyle.animation.openingDuration
easing.type: Easing.InOutQuad
property: 'opacity'
target: popup
}
},
Transition {
from: 'opened'
to: ''
NumberAnimation {
duration: PopupStyle.animation.closingDuration
easing.type: Easing.InOutQuad
property: 'opacity'
target: popup
}
SequentialAnimation {
PauseAnimation {
duration: PopupStyle.animation.closingDuration
}
ScriptAction {
script: popup.hide()
}
}
}
]
}
......@@ -107,15 +107,16 @@ function clearTimeout (timer) {
// -------------------------------------------------------------------
// Returns the top (root) parent of one object.
function getTopParent (object) {
function _getTopParent (object) {
return object.$parent || object.parent
function getTopParent (object, useFakeParent) {
function _getTopParent (object, useFakeParent) {
return (useFakeParent && object.$parent) || object.parent
}
var parent = _getTopParent(object)
var parent = _getTopParent(object, useFakeParent)
var p
while (_getTopParent(parent) != null) {
parent = _getTopParent(parent)
while ((p = _getTopParent(parent, useFakeParent)) != null) {
parent = p
}
return parent
......
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