diff --git a/src/controls/private/ActionsMenu.qml b/src/controls/private/ActionsMenu.qml new file mode 100644 --- /dev/null +++ b/src/controls/private/ActionsMenu.qml @@ -0,0 +1,48 @@ +/* + * Copyright 2018 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.3 +import QtQuick.Controls 2.0 as Controls + +Controls.Menu +{ + id: theMenu + property alias actions: actionsRepeater.model + property Component submenuComponent + + Repeater { + id: actionsRepeater + + delegate: Controls.MenuItem { + id: menuItem + text: model.text +// TODO: enable when we depend on Qt 5.10 +// icon.name: model.iconName + visible: model.visible + enabled: modelData.enabled + checkable: modelData.checkable + checked: modelData.checked + onTriggered: { + modelData.trigger() + } + + readonly property var ourMenu: theMenu.submenuComponent ? theMenu.submenuComponent.createObject(menuItem, { actions: modelData.children }) : null + } + } +} diff --git a/src/controls/private/PrivateActionToolButton.qml b/src/controls/private/PrivateActionToolButton.qml --- a/src/controls/private/PrivateActionToolButton.qml +++ b/src/controls/private/PrivateActionToolButton.qml @@ -44,6 +44,18 @@ if (kirigamiAction) { kirigamiAction.trigger(); } + if (menu.count>0 && !menu.visible) { + menu.popup(control, 0, control.height) + } + } + + ActionsMenu { + id: menu + y: control.height + actions: control.kirigamiAction ? control.kirigamiAction.children : "" + submenuComponent: Component { + ActionsMenu {} + } } flat: true diff --git a/tests/actionsMenu.qml b/tests/actionsMenu.qml new file mode 100644 --- /dev/null +++ b/tests/actionsMenu.qml @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Aleix Pol Gonzalez + * Copyright 2016 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import org.kde.kirigami 2.2 as Kirigami + +Kirigami.ApplicationWindow +{ + id: main + + header: Kirigami.ToolBarApplicationHeader {} + + pageStack.initialPage: Kirigami.Page { + + Button { + text: "button" + onClicked: menu.popup() + Menu { + id: menu + + MenuItem { text: "xxx" } + MenuItem { text: "xxx" } + MenuItem { + text: "yyy" + Menu { + MenuItem { text: "yyy" } + } + } + } + } + + contextualActions: [ + Kirigami.Action { + text: "fua" + icon.name: "kalgebra" + + Kirigami.Action { text: "xxx"; onTriggered: console.log("xxx") } + Kirigami.Action { text: "xxx"; onTriggered: console.log("xxx") } + Kirigami.Action { text: "xxx"; onTriggered: console.log("xxx") } + Kirigami.Action { + text: "yyy" + Kirigami.Action { text: "yyy" } + Kirigami.Action { text: "yyy" } + Kirigami.Action { text: "yyy" } + Kirigami.Action { text: "yyy" } + } + } + ] + } +}