From 72d33df1d5b0eba70d59591703988c19a033d94e Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 16 May 2017 10:23:48 +0200 Subject: [PATCH] feat(ui): remove `DropDownMenu` component, create a `Popup` component instead --- linphone-desktop/resources.qrc | 2 +- .../ui/modules/Common/Popup/DropDownMenu.qml | 11 --- .../ui/modules/Common/Popup/Popup.qml | 80 +++++++++++++++++++ linphone-desktop/ui/modules/Common/qmldir | 2 +- .../ui/modules/Linphone/Calls/Calls.qml | 9 +-- 5 files changed, 86 insertions(+), 18 deletions(-) delete mode 100644 linphone-desktop/ui/modules/Common/Popup/DropDownMenu.qml create mode 100644 linphone-desktop/ui/modules/Common/Popup/Popup.qml diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc index e0e472481..009b54f84 100644 --- a/linphone-desktop/resources.qrc +++ b/linphone-desktop/resources.qrc @@ -231,7 +231,7 @@ ui/modules/Common/Popup/AbstractDropDownMenu.qml ui/modules/Common/Popup/DesktopPopup.qml ui/modules/Common/Popup/DropDownDynamicMenu.qml - ui/modules/Common/Popup/DropDownMenu.qml + ui/modules/Common/Popup/Popup.qml ui/modules/Common/Popup/PopupShadow.qml ui/modules/Common/qmldir ui/modules/Common/Styles/Animations/BusyIndicatorStyle.qml diff --git a/linphone-desktop/ui/modules/Common/Popup/DropDownMenu.qml b/linphone-desktop/ui/modules/Common/Popup/DropDownMenu.qml deleted file mode 100644 index 90473de27..000000000 --- a/linphone-desktop/ui/modules/Common/Popup/DropDownMenu.qml +++ /dev/null @@ -1,11 +0,0 @@ -import Utils 1.0 - -// ============================================================================= -// Menu which supports menu like `ActionMenu` or `Menu`. -// ============================================================================= - -AbstractDropDownMenu { - function _computeHeight () { - return _content[0].height - } -} diff --git a/linphone-desktop/ui/modules/Common/Popup/Popup.qml b/linphone-desktop/ui/modules/Common/Popup/Popup.qml new file mode 100644 index 000000000..da00b7691 --- /dev/null +++ b/linphone-desktop/ui/modules/Common/Popup/Popup.qml @@ -0,0 +1,80 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.1 as Controls + +import Utils 1.0 + +// ============================================================================= + +Item { + // Optionnal parameters, set the position of popup relative to this item. + property var relativeTo + property int relativeX: 0 + property int relativeY: 0 + + default property alias _content: popup.contentItem + + // --------------------------------------------------------------------------- + + visible: false + + function show () { + if (popup.visible) { + return + } + + if (relativeTo) { + var parent = Utils.getTopParent(this) + + popup.x = Qt.binding(function () { + return relativeTo ? relativeTo.mapToItem(null, relativeX, relativeY).x : 0 + }) + popup.y = Qt.binding(function () { + return relativeTo ? relativeTo.mapToItem(null, relativeX, relativeY).y : 0 + }) + } else { + popup.x = Qt.binding(function () { + return x + }) + popup.y = Qt.binding(function () { + return y + }) + } + + popup.open() + } + + function hide () { + if (!popup.visible) { + return + } + + popup.x = 0 + popup.y = 0 + + popup.close() + } + + // --------------------------------------------------------------------------- + + Controls.Popup { + id: popup + + background: Rectangle { + height: popup.height + width: popup.width + + layer { + enabled: true + effect: PopupShadow {} + } + } + + contentItem: Column { + id: internalData + } + + padding: 0 + + Component.onCompleted: parent = Utils.getTopParent(this) + } +} diff --git a/linphone-desktop/ui/modules/Common/qmldir b/linphone-desktop/ui/modules/Common/qmldir index fc6483c2c..13851de6a 100644 --- a/linphone-desktop/ui/modules/Common/qmldir +++ b/linphone-desktop/ui/modules/Common/qmldir @@ -73,7 +73,7 @@ Paned 1.0 Misc/Paned.qml AbstractDropDownMenu 1.0 Popup/AbstractDropDownMenu.qml DesktopPopup 1.0 Popup/DesktopPopup.qml DropDownDynamicMenu 1.0 Popup/DropDownDynamicMenu.qml -DropDownMenu 1.0 Popup/DropDownMenu.qml +Popup 1.0 Popup/Popup.qml PopupShadow 1.0 Popup/PopupShadow.qml TooltipArea 1.0 Tooltip/TooltipArea.qml diff --git a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml index 65e0c5c3c..b970dcbfa 100644 --- a/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml +++ b/linphone-desktop/ui/modules/Linphone/Calls/Calls.qml @@ -59,13 +59,12 @@ ListView { : 'burger_menu' iconSize: CallsStyle.entry.iconMenuSize - onClicked: menu.showMenu() + onClicked: popup.show() - DropDownMenu { - id: menu + Popup { + id: popup implicitWidth: actionMenu.width - launcher: button relativeTo: callControls relativeX: callControls.width @@ -82,7 +81,7 @@ ListView { entryName: modelData.name onClicked: { - menu.hideMenu() + popup.hide() params.actions[index].handler() } }