Commit 732d143d authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Popup/AbstractDropDownMenu): add transitions

parent fcb1b2a5
...@@ -9,6 +9,8 @@ import Utils 1.0 ...@@ -9,6 +9,8 @@ import Utils 1.0
// =================================================================== // ===================================================================
Item { Item {
id: menu
// Optionnal parameter, if defined and if a click is detected // Optionnal parameter, if defined and if a click is detected
// on it, menu is not closed. // on it, menu is not closed.
property var launcher property var launcher
...@@ -20,6 +22,7 @@ Item { ...@@ -20,6 +22,7 @@ Item {
property int relativeY: 0 property int relativeY: 0
default property alias _content: content.data default property alias _content: content.data
property bool _isOpen: false
signal menuClosed signal menuClosed
signal menuOpened signal menuOpened
...@@ -27,11 +30,11 @@ Item { ...@@ -27,11 +30,11 @@ Item {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
function isOpen () { function isOpen () {
return visible return _isOpen
} }
function showMenu () { function showMenu () {
if (visible) { if (_isOpen) {
return return
} }
...@@ -40,20 +43,15 @@ Item { ...@@ -40,20 +43,15 @@ Item {
this.y = relativeTo.mapToItem(null, relativeX, relativeY).y this.y = relativeTo.mapToItem(null, relativeX, relativeY).y
} }
visible = true _isOpen = true
menuOpened()
// Necessary to use `Keys.onEscapePressed`.
focus = true
} }
function hideMenu () { function hideMenu () {
if (!visible) { if (!_isOpen) {
return return
} }
visible = false _isOpen = false
menuClosed()
} }
function _computeHeight () { function _computeHeight () {
...@@ -63,6 +61,7 @@ Item { ...@@ -63,6 +61,7 @@ Item {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
implicitHeight: _computeHeight() implicitHeight: _computeHeight()
opacity: 0
visible: false visible: false
z: Constants.zPopup z: Constants.zPopup
...@@ -100,4 +99,73 @@ Item { ...@@ -100,4 +99,73 @@ Item {
hideMenu() hideMenu()
} }
} }
// -----------------------------------------------------------------
states: [
State {
name: 'Opened'
when: _isOpen
PropertyChanges {
focus: true // Necessary to use `Keys.onEscapePressed`.
opacity: 1
target: menu
visible: true
}
}
]
transitions: [
Transition {
from: ''
to: 'Opened'
NumberAnimation {
duration: 250
easing.type: Easing.InOutQuad
property: 'opacity'
target: menu
}
SequentialAnimation {
PauseAnimation {
duration: 250
}
ScriptAction {
script: menuOpened()
}
}
},
Transition {
from: 'Opened'
to: ''
NumberAnimation {
duration: 250
easing.type: Easing.InOutQuad
property: 'opacity'
target: menu
}
NumberAnimation {
duration: 250
easing.type: Easing.InOutQuad
property: 'visible' // Ugly, use `NumberAnimation` on bool.
target: menu
}
SequentialAnimation {
PauseAnimation {
duration: 250
}
ScriptAction {
script: menuClosed()
}
}
}
]
} }
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