diff --git a/src/controls/Action.qml b/src/controls/Action.qml index f3e4ab4b..3894f3f1 100644 --- a/src/controls/Action.qml +++ b/src/controls/Action.qml @@ -1,117 +1,117 @@ /* * 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.4 as Controls import "private" /** * An item that represents an abstract Action * * @inherit QtQuick.Controls.Action */ Controls.Action { id: root /** * visible: bool * True (default) when the graphic representation of the action * is supposed to be visible. * It's up to the action representation to honor this property. */ property bool visible: true /** * iconName: string * Sets the icon name for the action. This will pick the icon with the given name from the current theme. */ property alias iconName: root.icon.name /** * iconSource: string * Sets the icon file or resource url for the action. Defaults to the empty URL. Use this if you want a specific file rather than an icon from the theme */ property alias iconSource: root.icon.source /** * A tooltip text to be shown when hovering the control bound to this action. Not all controls support tooltips on all platforms */ property string tooltip /** * children: list * A list of children actions. * Useful for tree-like menus * @code * Action { * text: "Tools" * Action { * text: "Action1" * } * Action { * text: "Action2" * } * } * @endcode */ /** * separator: bool * Whether the action is is a separator action; defaults to false. */ property bool separator: false /** * expandible: bool * When true, actions in globalDrawers and contextDrawers will become titles displaying te child actions as sub items * @since 2.6 */ property bool expandible: false - property QtObject parent + property Controls.Action parent default property alias children: root.__children property list __children onChildrenChanged: { var child; for (var i in children) { child = children[i]; if (child.hasOwnProperty("parent")) { child.parent = root } } } /** * visibleChildren: list * All child actions that are visible */ readonly property var visibleChildren: { var visible = []; var child; for (var i in children) { child = children[i]; if (!child.hasOwnProperty("visible") || child.visible) { visible.push(child) } } return visible; } } diff --git a/src/controls/private/ActionsMenu.qml b/src/controls/private/ActionsMenu.qml index 59d2eb13..7bc773eb 100644 --- a/src/controls/private/ActionsMenu.qml +++ b/src/controls/private/ActionsMenu.qml @@ -1,77 +1,77 @@ /* * 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.2 as Controls +import QtQuick.Controls 2.4 as Controls import org.kde.kirigami 2.4 as Kirigami Controls.Menu { id: theMenu z: 999999999 property alias actions: actionsInstantiator.model property Component submenuComponent //renamed to work on both Qt 5.9 and 5.10 property Component itemDelegate: ActionMenuItem {} property Component separatorDelegate: Controls.MenuSeparator { } - property QtObject parentAction + property Controls.Action parentAction property Controls.MenuItem parentItem Item { id: invisibleItems visible: false } Instantiator { id: actionsInstantiator active: theMenu.visible delegate: QtObject { - readonly property QtObject action: modelData + readonly property Controls.Action action: modelData property QtObject item: null function create() { if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { if (action.hasOwnProperty("separator") && action.separator) { item = theMenu.separatorDelegate.createObject(null, {}); } else { item = theMenu.itemDelegate.createObject(null, { ourAction: action }); } theMenu.addItem(item) } else if (theMenu.submenuComponent) { item = theMenu.submenuComponent.createObject(null, { parentAction: action, title: action.text, actions: action.children }); theMenu.insertMenu(theMenu.count, item) item.parentItem = theMenu.contentData[theMenu.contentData.length-1] item.parentItem.icon = action.icon } } function remove() { if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { theMenu.removeItem(item) } else if (theMenu.submenuComponent) { theMenu.removeMenu(item) } } } onObjectAdded: object.create() onObjectRemoved: object.remove() } } diff --git a/src/controls/private/PrivateActionToolButton.qml b/src/controls/private/PrivateActionToolButton.qml index fbfb1c5e..53ca41fc 100644 --- a/src/controls/private/PrivateActionToolButton.qml +++ b/src/controls/private/PrivateActionToolButton.qml @@ -1,141 +1,141 @@ /* * 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.Layouts 1.2 -import QtQuick.Controls 2.2 as Controls +import QtQuick.Controls 2.4 as Controls import org.kde.kirigami 2.4 Controls.ToolButton { id: control signal menuAboutToShow implicitWidth: menuArrow.visible || (showText && ( kirigamiAction ? kirigamiAction.text.length > 0 : text.length > 0)) ? Math.max(layout.implicitWidth + Units.largeSpacing*2, background.implicitWidth) : implicitHeight implicitHeight: background.implicitHeight Theme.colorSet: Theme.Button Theme.inherit: kirigamiAction && kirigamiAction.icon.color.a === 0 Theme.backgroundColor: kirigamiAction && kirigamiAction.icon.color.a ? kirigamiAction.icon.color : undefined Theme.textColor: kirigamiAction && !flat && kirigamiAction.icon.color.a ? Theme.highlightedTextColor : undefined hoverEnabled: true flat: !control.kirigamiAction || !control.kirigamiAction.icon.color.a //TODO: replace with upstream action when we depend on Qt 5.10 //TODO: upstream action makes the style to re-draw the content, it'd be ideal except for the custom dropDown icon needed for actionsMenu - property QtObject kirigamiAction + property Controls.Action kirigamiAction property bool showText: true property bool showMenuArrow: true property alias menu: menu //we need our own text delegate text: "" checkable: (kirigamiAction && kirigamiAction.checkable) || (menu.actions && menu.actions.length > 0) checked: (kirigamiAction && kirigamiAction.checked) enabled: kirigamiAction && kirigamiAction.enabled opacity: enabled ? 1 : 0.4 visible: kirigamiAction && kirigamiAction.visible onClicked: { if (kirigamiAction) { kirigamiAction.trigger(); } } onToggled: { if (menu.actions.length > 0) { if (checked) { control.menuAboutToShow(); menu.popup(control, 0, control.height) } else { menu.dismiss() } } } ActionsMenu { id: menu y: control.height actions: control.kirigamiAction && kirigamiAction.hasOwnProperty("children") ? control.kirigamiAction.children : null // Important: We handle the press on parent in the parent, so ignore it here. closePolicy: Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutsideParent submenuComponent: Component { ActionsMenu {} } onClosed: { control.checked = false } } contentItem: MouseArea { hoverEnabled: true onPressed: mouse.accepted = false Theme.colorSet: checked && (control.kirigamiAction && control.kirigamiAction.icon.color.a) ? Theme.Selection : control.Theme.colorSet Theme.inherit: control.kirigamiAction && Theme.colorSet != Theme.Selection && control.kirigamiAction.icon.color.a === 0 GridLayout { id: layout columns: control.display == Controls.ToolButton.TextUnderIcon ? 1 : 2 + (menuArrow.visible ? 1 : 0) rows: control.display == Controls.ToolButton.TextUnderIcon ? 2 : 1 anchors.centerIn: parent Icon { id: mainIcon Layout.alignment: Qt.AlignCenter Layout.minimumWidth: Units.iconSizes.smallMedium Layout.minimumHeight: Units.iconSizes.smallMedium source: control.kirigamiAction ? (control.kirigamiAction.icon ? control.kirigamiAction.icon.name : control.kirigamiAction.iconName) : "" visible: control.kirigamiAction && control.kirigamiAction.iconName != "" && control.display != Controls.ToolButton.TextOnly color: control.flat && control.kirigamiAction && control.kirigamiAction.icon && control.kirigamiAction.icon.color.a > 0 ? control.kirigamiAction.icon.color : label.color } Controls.Label { id: label MnemonicData.enabled: control.enabled MnemonicData.controlType: MnemonicData.ActionElement MnemonicData.label: control.kirigamiAction ? control.kirigamiAction.text : "" text: MnemonicData.richTextLabel visible: control.showText && text.length > 0 && control.display != Controls.ToolButton.IconOnly Shortcut { sequence: label.MnemonicData.sequence onActivated: control.clicked() } } Icon { id: menuArrow Layout.minimumWidth: Units.iconSizes.small Layout.minimumHeight: Units.iconSizes.small color: mainIcon.color source: "arrow-down" visible: showMenuArrow && menu.actions && menu.actions.length > 0 } } } Controls.ToolTip { visible: control.hovered && text.length > 0 && !menu.visible && !control.pressed text: kirigamiAction ? (kirigamiAction.tooltip.length ? kirigamiAction.tooltip : kirigamiAction.text) : "" delay: Units.toolTipDelay timeout: 5000 y: control.height } }