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