diff --git a/src/controls/Action.qml b/src/controls/Action.qml index 203b7e79..f3e4ab4b 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 - + * 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 + 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 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/ActionToolBar.qml b/src/controls/ActionToolBar.qml index f29dd045..4728efee 100644 --- a/src/controls/ActionToolBar.qml +++ b/src/controls/ActionToolBar.qml @@ -1,189 +1,189 @@ /* * Copyright 2018 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.4 as Controls import org.kde.kirigami 2.5 as Kirigami import "private" /** * This is a simple toolbar built out of a list of actions * each action is represented by a ToolButton, those that won't fit * the size will go in a menu under a button with the overflow ... icon * * @inherits Item * @since 2.5 */ Item { id: root /** * actions: list * if the card should provide clickable actions, put them in this property, * they will be put in the footer as a list of ToolButtons plus an optional * overflow menu, when not all of them will fit in the available Card width. */ property list actions /** * actions: hiddenActions * This list of actions is for those you always want in the menu, even if there * is enough space. * @since 2.6 */ property list hiddenActions /** * flat: bool * Wether we want our buttons to have a flat appearance. Default: true */ property bool flat: true /** * display: enum * This controls the label position regarding the icon, is the same value to control individual Button components, * permitted values are: * * Button.IconOnly * * Button.TextOnly * * Button.TextBesideIcon * * Button.TextUnderIcon */ property int display: Controls.Button.TextBesideIcon /** * position enum * This property holds the position of the toolbar. * if this ActionToolBar is the contentItem of a QQC2 Toolbar, the position is binded to the ToolBar's position - * + * * permitted values are: * *ToolBar.Header: The toolbar is at the top, as a window or page header. * *ToolBar.Footer: The toolbar is at the bottom, as a window or page footer. */ property int position: parent && parent.hasOwnProperty("position") ? parent.position : Controls.ToolBar.Header implicitHeight: actionsLayout.implicitHeight implicitWidth: actionsLayout.implicitWidth Layout.minimumWidth: moreButton.implicitWidth RowLayout { id: actionsLayout anchors.fill: parent //anchors.rightMargin: moreButton.width - + spacing: Kirigami.Units.smallSpacing property var overflowSet: [] // TODO use Array.findIndex once we depend on Qt 5.9 function findIndex(array, cb) { for (var i = 0, length = array.length; i < length; ++i) { if (cb(array[i])) { return i; } } return -1; } function isActionVisible(action) { var index = actionsLayout.findIndex(actionsLayout.overflowSet, function(act){return act === action}); if (index === -1) { index = actionsLayout.findIndex(root.hiddenActions, function(act){return act === action}); if (index === -1) { return true } } return false } RowLayout { Layout.minimumWidth: 0 Layout.fillHeight: true Repeater { model: root.actions delegate: PrivateActionToolButton { id: actionDelegate flat: root.flat opacity: x + width <= parent.width enabled: opacity display: root.display visible: !modelData.hasOwnProperty("visible") || modelData.visible Layout.fillWidth: false Layout.alignment: Qt.AlignVCenter Layout.minimumWidth: implicitWidth kirigamiAction: modelData onOpacityChanged: updateOverflowSet() function updateOverflowSet() { var index = actionsLayout.findIndex(actionsLayout.overflowSet, function(act) { return act === modelData}); - if ((opacity > 0 || (modelData.hasOwnProperty("visible") || !modelData.visible)) && index > -1) { + if ((opacity > 0 || (modelData.hasOwnProperty("visible") || !modelData.visible)) && index > -1) { actionsLayout.overflowSet.splice(index, 1); - } else if (opacity === 0 && (!modelData.hasOwnProperty("visible") || modelData.visible) && index === -1) { + } else if (opacity === 0 && (!modelData.hasOwnProperty("visible") || modelData.visible) && index === -1) { actionsLayout.overflowSet.push(modelData); } actionsLayout.overflowSetChanged(); } Connections { target: modelData ignoreUnknownSignals: !modelData.hasOwnProperty("visible") onVisibleChanged: actionDelegate.updateOverflowSet(); } Component.onCompleted: { actionDelegate.updateOverflowSet(); } } } } Item { Layout.fillWidth: true visible: root.Layout.fillWidth } PrivateActionToolButton { id: moreButton Layout.alignment: Qt.AlignRight visible: hiddenActions.length > 0 || actionsLayout.overflowSet.length > 0 showMenuArrow: false kirigamiAction: Kirigami.Action { icon.name: "overflow-menu" children: Array.prototype.map.call(root.actions, function (i) { return i }).concat(Array.prototype.map.call(hiddenActions, function (i) { return i })) } menu.submenuComponent: ActionsMenu { Binding { target: parentItem property: "visible" value: !actionsLayout.isActionVisible(parentAction) && (parentAction.visible === undefined || parentAction.visible) } } menu.itemDelegate: ActionMenuItem { visible: !actionsLayout.isActionVisible(ourAction) && (ourAction.visible === undefined || ourAction.visible) } } } } diff --git a/src/controls/OverlayDrawer.qml b/src/controls/OverlayDrawer.qml index 92b77103..8ede7270 100644 --- a/src/controls/OverlayDrawer.qml +++ b/src/controls/OverlayDrawer.qml @@ -1,162 +1,162 @@ /* * 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.1 import QtGraphicalEffects 1.0 import QtQuick.Templates 2.0 as T2 import org.kde.kirigami 2.5 import "private" import "templates" as T /** * Overlay Drawers are used to expose additional UI elements needed for * small secondary tasks for which the main UI elements are not needed. * For example in Okular Active, an Overlay Drawer is used to display * thumbnails of all pages within a document along with a search field. * This is used for the distinct task of navigating to another page. */ T.OverlayDrawer { id: root //BEGIN Properties focus: false modal: true drawerOpen: !modal closePolicy: modal ? T2.Popup.CloseOnEscape | T2.Popup.CloseOnReleaseOutside : T2.Popup.NoAutoClose handleVisible: (modal || !drawerOpen) && (typeof(applicationWindow)===typeof(Function) && applicationWindow() ? applicationWindow().controlsVisible : true) onPositionChanged: { if (!modal && !root.peeking && !root.animating) { position = 1; } } background: Rectangle { color: Theme.backgroundColor Item { parent: root.handle anchors.fill: parent DropShadow { anchors.fill: handleGraphics visible: !parent.parent.handleAnchor || !parent.parent.handleAnchor.visible || root.handle.pressed || (root.modal && root.position > 0) horizontalOffset: 0 verticalOffset: Units.devicePixelRatio radius: Units.gridUnit /2 samples: 16 color: Qt.rgba(0, 0, 0, root.handle.pressed ? 0.6 : 0.4) source: handleGraphics } Rectangle { id: handleGraphics anchors.centerIn: parent Theme.colorSet: parent.parent.handleAnchor && parent.parent.handleAnchor.visible ? parent.parent.handleAnchor.Theme.colorSet : Theme.Button - + Theme.backgroundColor: parent.parent.handleAnchor && parent.parent.handleAnchor.visible ? parent.parent.handleAnchor.Theme.backgroundColor : undefined Theme.textColor: parent.parent.handleAnchor && parent.parent.handleAnchor.visible ? parent.parent.handleAnchor.Theme.textColor : undefined Theme.inherit: false color: root.handle.pressed ? Theme.highlightColor : Theme.backgroundColor visible: !parent.parent.handleAnchor || !parent.parent.handleAnchor.visible width: Units.iconSizes.smallMedium + Units.smallSpacing * 2 height: width radius: Units.devicePixelRatio * 2 Behavior on color { ColorAnimation { duration: Units.longDuration easing.type: Easing.InOutQuad } } } Loader { anchors.centerIn: handleGraphics width: height height: Units.iconSizes.smallMedium Theme.colorSet: handleGraphics.Theme.colorSet Theme.backgroundColor: handleGraphics.Theme.backgroundColor Theme.textColor: handleGraphics.Theme.textColor source: { var edge = root.edge; if (Qt.application.layoutDirection == Qt.RightToLeft) { if (edge === Qt.LeftEdge) { edge = Qt.RightEdge; } else { edge = Qt.LeftEdge; } } - - if (root.handleClosedIcon.source && root.handleOpenIcon.source) { - return Qt.resolvedUrl("templates/private/GenericDrawerIcon.qml"); - } else if (edge == Qt.LeftEdge ) { - return Qt.resolvedUrl("templates/private/MenuIcon.qml"); - } else if(edge == Qt.RightEdge && root.hasOwnProperty("actions")) { - return Qt.resolvedUrl("templates/private/ContextIcon.qml"); - }else { - return ""; - } + + if (root.handleClosedIcon.source && root.handleOpenIcon.source) { + return Qt.resolvedUrl("templates/private/GenericDrawerIcon.qml"); + } else if (edge == Qt.LeftEdge ) { + return Qt.resolvedUrl("templates/private/MenuIcon.qml"); + } else if(edge == Qt.RightEdge && root.hasOwnProperty("actions")) { + return Qt.resolvedUrl("templates/private/ContextIcon.qml"); + }else { + return ""; + } } onItemChanged: { if(item) { item.drawer = Qt.binding(function(){return root}); item.color = Qt.binding(function(){return root.handle.pressed ? Theme.highlightedTextColor : Theme.textColor}); } } } } Separator { anchors { right: root.edge == Qt.RightEdge ? parent.left : (root.edge == Qt.LeftEdge ? undefined : parent.right) left: root.edge == Qt.LeftEdge ? parent.right : (root.edge == Qt.RightEdge ? undefined : parent.left) top: root.edge == Qt.TopEdge ? parent.bottom : (root.edge == Qt.BottomEdge ? undefined : parent.top) bottom: root.edge == Qt.BottomEdge ? parent.top : (root.edge == Qt.TopEdge ? undefined : parent.bottom) } visible: !root.modal } EdgeShadow { z: -2 visible: root.modal edge: root.edge anchors { right: root.edge == Qt.RightEdge ? parent.left : (root.edge == Qt.LeftEdge ? undefined : parent.right) left: root.edge == Qt.LeftEdge ? parent.right : (root.edge == Qt.RightEdge ? undefined : parent.left) top: root.edge == Qt.TopEdge ? parent.bottom : (root.edge == Qt.BottomEdge ? undefined : parent.top) bottom: root.edge == Qt.BottomEdge ? parent.top : (root.edge == Qt.TopEdge ? undefined : parent.bottom) } opacity: root.position == 0 ? 0 : 1 Behavior on opacity { NumberAnimation { duration: Units.longDuration easing.type: Easing.InOutQuad } } } } } diff --git a/src/controls/private/ActionsMenu.qml b/src/controls/private/ActionsMenu.qml index 805239aa..59d2eb13 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 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.MenuItem parentItem Item { id: invisibleItems visible: false } Instantiator { id: actionsInstantiator active: theMenu.visible delegate: QtObject { readonly property QtObject 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) { + 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/GlobalDrawerActionItem.qml b/src/controls/private/GlobalDrawerActionItem.qml index 7606c3a7..c289350f 100644 --- a/src/controls/private/GlobalDrawerActionItem.qml +++ b/src/controls/private/GlobalDrawerActionItem.qml @@ -1,153 +1,153 @@ /* * Copyright 2015 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.6 import QtQuick.Controls 2.0 as QQC2 import QtQuick.Layouts 1.2 import org.kde.kirigami 2.5 BasicListItem { id: listItem supportsMouseEvents: (!isExpandible || root.collapsed) readonly property bool wideMode: width > height * 2 readonly property bool isSeparator: modelData.hasOwnProperty("separator") && modelData.separator readonly property bool isExpandible: modelData && modelData.hasOwnProperty("expandible") && modelData.expandible reserveSpaceForIcon: !isSeparator reserveSpaceForLabel: !isSeparator checked: modelData.checked || (actionsMenu && actionsMenu.visible) width: parent.width icon: modelData.icon.name || modelData.icon.source iconColor: modelData.icon.color label: width > height * 2 ? MnemonicData.richTextLabel : "" MnemonicData.enabled: listItem.enabled && listItem.visible MnemonicData.controlType: MnemonicData.MenuItem MnemonicData.label: modelData.text property ActionsMenu actionsMenu: ActionsMenu { x: Qt.application.layoutDirection === Qt.RightToLeft ? -width : listItem.width actions: modelData.hasOwnProperty("children") ? modelData.children : null submenuComponent: Component { ActionsMenu {} } onVisibleChanged: { if (visible) { stackView.openSubMenu = listItem.actionsMenu; } else if (stackView.openSubMenu === listItem.actionsMenu) { stackView.openSubMenu = null; } } } separatorVisible: false //TODO: animate the hide by collapse visible: (model ? model.visible || model.visible===undefined : modelData.visible) && opacity > 0 opacity: !root.collapsed || icon.length > 0 Behavior on opacity { NumberAnimation { duration: Units.longDuration/2 easing.type: Easing.InOutQuad } } enabled: !isSeparator && ( (model && model.enabled !== undefined) ? model.enabled : modelData.enabled) hoverEnabled: (!isExpandible || root.collapsed) && !Settings.tabletMode sectionDelegate: isExpandible font.pointSize: isExpandible ? Theme.defaultFont.pointSize * 1.30 : Theme.defaultFont.pointSize opacity: !root.collapsed height: implicitHeight * opacity Separator { id: separatorAction visible: listItem.isSeparator Layout.fillWidth: true } Icon { Shortcut { sequence: listItem.MnemonicData.sequence onActivated: listItem.clicked() } isMask: true Layout.alignment: Qt.AlignVCenter Layout.rightMargin: !Settings.isMobile && mainFlickable.contentHeight > mainFlickable.height ? Units.gridUnit : 0 Layout.leftMargin: !root.collapsed ? 0 : parent.width - listItem.width Layout.preferredHeight: !root.collapsed ? Units.iconSizes.smallMedium : Units.iconSizes.small/2 selected: listItem.checked || listItem.pressed Layout.preferredWidth: Layout.preferredHeight source: (LayoutMirroring.enabled ? "go-next-symbolic-rtl" : "go-next-symbolic") - visible: (!isExpandible || root.collapsed) && !listItem.isSeparator && modelData.hasOwnProperty("children") && modelData.children!==undefined && modelData.children.length > 0 + visible: (!isExpandible || root.collapsed) && !listItem.isSeparator && modelData.hasOwnProperty("children") && modelData.children!==undefined && modelData.children.length > 0 } data: [ QQC2.ToolTip { - visible: !listItem.isSeparator && (modelData.hasOwnProperty("tooltip") && modelData.tooltip.length || root.collapsed) && (!actionsMenu || !actionsMenu.visible) && listItem.hovered && text.length > 0 + visible: !listItem.isSeparator && (modelData.hasOwnProperty("tooltip") && modelData.tooltip.length || root.collapsed) && (!actionsMenu || !actionsMenu.visible) && listItem.hovered && text.length > 0 text: modelData.hasOwnProperty("tooltip") && modelData.tooltip.length ? modelData.tooltip : modelData.text delay: Units.toolTipDelay timeout: 5000 y: listItem.height/2 - height/2 x: Qt.application.layoutDirection === Qt.RightToLeft ? -width : listItem.width } ] onHoveredChanged: { if (!hovered) { return; } if (stackView.openSubMenu) { stackView.openSubMenu.visible = false; if (!listItem.actionsMenu.hasOwnProperty("count") || listItem.actionsMenu.count>0) { if (listItem.actionsMenu.hasOwnProperty("popup")) { listItem.actionsMenu.popup(listItem, listItem.width, 0) } else { listItem.actionsMenu.visible = true; } } } } onClicked: { if (!supportsMouseEvents) { return; } - modelData.trigger(); + modelData.trigger(); if (modelData.hasOwnProperty("children") && modelData.children!==undefined && modelData.children.length > 0) { if (root.collapsed) { //fallbacks needed for Qt 5.9 if ((!listItem.actionsMenu.hasOwnProperty("count") || listItem.actionsMenu.count>0) && !listItem.actionsMenu.visible) { stackView.openSubMenu = listItem.actionsMenu; if (listItem.actionsMenu.hasOwnProperty("popup")) { listItem.actionsMenu.popup(listItem, listItem.width, 0) } else { listItem.actionsMenu.visible = true; } } } else { stackView.push(menuComponent, {model: modelData.children, level: level + 1, current: modelData }); } } else if (root.resetMenuOnTriggered) { root.resetMenu(); } checked = Qt.binding(function() { return modelData.checked || (actionsMenu && actionsMenu.visible) }); } } diff --git a/src/controls/private/PrivateActionToolButton.qml b/src/controls/private/PrivateActionToolButton.qml index d3b29322..fbfb1c5e 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 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 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 - } + 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 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 + } }