diff --git a/src/controls/Action.qml b/src/controls/Action.qml --- a/src/controls/Action.qml +++ b/src/controls/Action.qml @@ -18,67 +18,36 @@ */ import QtQuick 2.7 +import QtQuick.Controls 2.5 as Controls import "private" /** * An item that represents an abstract Action * * @inherit QtObject */ -QtObject { +Controls.Action { id: root /** - * Emitted whenever a action's checked property changes. - * This usually happens at the same time as triggered. - * @param checked - */ - signal toggled(bool checked) - - /** - * Emitted when either the menu item or its bound action have been activated. Includes the object that triggered the event if relevant (e.g. a Button). - * You shouldn't need to emit this signal, use trigger() instead. - * @param source Object that triggered the event if relevant, often null - */ - signal triggered(QtObject source) - - /** - * 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 - - /** - * checkable: bool - * Whether action can be checked, or toggled. Defaults to false. - */ - property bool checkable: false - - /** - * checked: bool - * Whether the action is checked. Defaults to false. - */ - property bool checked: false - - /** - * enabled: bool - * Whether the action is enabled, and can be triggered. Defaults to true. - */ - property bool enabled: 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: iconGroup.name + 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: iconGroup.source + property alias iconSource: root.icon.source /** * metadata for the icon, such as width/height.name and source @@ -104,22 +73,17 @@ * *color This property holds the color of the icon. * The icon is tinted with the specified color, unless the color is set to "transparent". */ - property ActionIconGroup icon: ActionIconGroup { - id: iconGroup - } +// property ActionIconGroup icon: ActionIconGroup { +// id: iconGroup +// } /** * shortcut : keysequence * Shortcut bound to the action. The keysequence can be a string or a Qt standard key. */ - property alias shortcut: shortcutItem.sequence - - /** - * Text for the action. This text will show as the button text, or as title in a menu item, depending from the way the developer will choose to represent it - */ - property string text +// property alias shortcut: shortcutItem.sequence - /** + /** * 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 @@ -185,22 +149,22 @@ return visible; } - property Shortcut __shortcut: Shortcut { - property bool checked: false - id: shortcutItem - enabled: root.enabled - onActivated: root.trigger(); - } - function trigger(source) { - if (!enabled) { - return; - } - root.triggered(source); - if (root.checkable) { - root.checked = !root.checked; - root.toggled(root.checked); - } - } - - onCheckedChanged: root.toggled(root.checked); +// property Shortcut __shortcut: Shortcut { +// property bool checked: false +// id: shortcutItem +// enabled: root.enabled +// onActivated: root.trigger(); +// } +// function trigger(source) { +// if (!enabled) { +// return; +// } +// root.triggered(source); +// if (root.checkable) { +// root.checked = !root.checked; +// root.toggled(root.checked); +// } +// } + +// onCheckedChanged: root.toggled(root.checked); } diff --git a/src/controls/ActionToolBar.qml b/src/controls/ActionToolBar.qml --- a/src/controls/ActionToolBar.qml +++ b/src/controls/ActionToolBar.qml @@ -17,9 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.6 +import QtQuick 2.7 import QtQuick.Layouts 1.2 -import QtQuick.Controls 2.2 as Controls +import QtQuick.Controls 2.5 as Controls import org.kde.kirigami 2.5 as Kirigami import "private" @@ -116,25 +116,26 @@ enabled: opacity display: root.display - visible: modelData.visible + visible: !modelData.hasOwnProperty("visible") || modelData.visible Layout.fillWidth: false Layout.alignment: Qt.AlignVCenter Layout.minimumWidth: implicitWidth - kirigamiAction: modelData + action: modelData onOpacityChanged: updateOverflowSet() function updateOverflowSet() { var index = actionsLayout.findIndex(actionsLayout.overflowSet, function(act) { return act === modelData}); - if ((opacity > 0 || !modelData.visible) && index > -1) { + if ((opacity > 0 || (modelData.hasOwnProperty("visible") || !modelData.visible)) && index > -1) { actionsLayout.overflowSet.splice(index, 1); - } else if (opacity === 0 && 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: { @@ -175,12 +176,12 @@ Binding { target: parentItem property: "visible" - value: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === parentAction}) > -1 && (parentAction.visible === undefined || parentAction.visible) + value: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === parentAction}) > -1 && (!parentAction.hasOwnProperty("visible") || parentAction.visible === undefined || parentAction.visible) } } } itemDelegate: ActionMenuItem { - visible: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === ourAction}) > -1 && (ourAction.visible === undefined || ourAction.visible) + visible: actionsLayout.findIndex(actionsLayout.overflowSet, function(act) {return act === ourAction}) > -1 && (!ourAction.hasOwnProperty("visible") || ourAction.visible === undefined || ourAction.visible) } Instantiator { diff --git a/src/controls/GlobalDrawer.qml b/src/controls/GlobalDrawer.qml --- a/src/controls/GlobalDrawer.qml +++ b/src/controls/GlobalDrawer.qml @@ -317,7 +317,7 @@ } visible: root.collapsible - kirigamiAction: Action { + action: Action { icon.name: "application-menu" checkable: true checked: !root.collapsed diff --git a/src/controls/ToolBarApplicationHeader.qml b/src/controls/ToolBarApplicationHeader.qml --- a/src/controls/ToolBarApplicationHeader.qml +++ b/src/controls/ToolBarApplicationHeader.qml @@ -95,19 +95,19 @@ PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter - kirigamiAction: page && page.actions ? page.actions.left : null + action: page && page.actions ? page.actions.left : null showText: !parent.toobig } PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter Layout.rightMargin: Units.smallSpacing - kirigamiAction: page && page.actions ? page.actions.main : null + action: page && page.actions ? page.actions.main : null showText: !parent.toobig flat: false } PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter - kirigamiAction: page && page.actions ? page.actions.right : null + action: page && page.actions ? page.actions.right : null showText: !parent.toobig } } @@ -128,7 +128,7 @@ children: page && page.actions.contextualActions ? page.actions.contextualActions : null } - kirigamiAction: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction + action: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction } } } diff --git a/src/controls/private/ActionButton.qml b/src/controls/private/ActionButton.qml --- a/src/controls/private/ActionButton.qml +++ b/src/controls/private/ActionButton.qml @@ -42,7 +42,7 @@ readonly property Page page: root.parent.page //either Action or QAction should work here - function isActionAvailable(action) { return action && (action.visible === undefined || action.visible); } + function isActionAvailable(action) { return action && (action.hasOwnProperty("visible") ? action.visible === undefined || action.visible : !action.hasOwnProperty("visible")); } readonly property QtObject action: root.page && isActionAvailable(root.page.mainAction) ? root.page.mainAction : null readonly property QtObject leftAction: root.page && isActionAvailable(root.page.leftAction) ? root.page.leftAction : null @@ -181,7 +181,7 @@ actionUnderMouse.trigger(); } - if (actionUnderMouse.children.length > 0) { + if (actionUnderMouse.hasOwnProperty("children") && actionUnderMouse.children.length > 0) { var subMenuUnderMouse; switch (actionUnderMouse) { case leftAction: @@ -254,7 +254,7 @@ id: mainActionSubMenu y: -height x: -width/2 + parent.width/2 - actions: root.action ? root.action.children : "" + actions: root.action && root.action.hasOwnProperty("children") ? root.action.children : "" submenuComponent: Component { ActionsMenu {} } @@ -264,7 +264,7 @@ anchors.centerIn: parent width: Units.iconSizes.smallMedium height: width - source: root.action && root.action.iconName ? root.action.iconName : "" + source: root.action && root.action.icon.name ? root.action.icon.name : "" selected: true color: root.action && root.action.color && root.action.color.a > 0 ? root.action.color : (selected ? Theme.highlightedTextColor : Theme.textColor) } @@ -309,13 +309,13 @@ id: leftActionSubMenu y: -height x: -width/2 + parent.width/2 - actions: root.leftAction ? root.leftAction.children : "" + actions: root.leftAction && root.leftAction.hasOwnProperty("children") ? root.leftAction.children : "" submenuComponent: Component { ActionsMenu {} } } Icon { - source: root.leftAction && root.leftAction.iconName ? root.leftAction.iconName : "" + source: root.leftAction && root.leftAction.icon.name ? root.leftAction.icon.name : "" width: Units.iconSizes.smallMedium height: width selected: leftButtonGraphics.pressed @@ -355,13 +355,13 @@ id: rightActionSubMenu y: -height x: -width/2 + parent.width/2 - actions: root.rightAction ? root.rightAction.children : "" + actions: root.rightAction && root.rightAction.hasOwnProperty("children") ? root.rightAction.children : "" submenuComponent: Component { ActionsMenu {} } } Icon { - source: root.rightAction && root.rightAction.iconName ? root.rightAction.iconName : "" + source: root.rightAction && root.rightAction.icon.name ? root.rightAction.icon.name : "" width: Units.iconSizes.smallMedium height: width selected: rightButtonGraphics.pressed diff --git a/src/controls/private/ActionsMenu.qml b/src/controls/private/ActionsMenu.qml --- a/src/controls/private/ActionsMenu.qml +++ b/src/controls/private/ActionsMenu.qml @@ -53,7 +53,7 @@ property QtObject item: null function create() { - if (!action.children || action.children.length === 0) { + if (!action.hasOwnProperty("children") && !action.children || action.children.length === 0) { if (action.hasOwnProperty("separator") && action.separator) { item = theMenu.separatorDelegate.createObject(null, {}); } @@ -69,7 +69,7 @@ } } function remove() { - if (!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) diff --git a/src/controls/private/GlobalDrawerActionItem.qml b/src/controls/private/GlobalDrawerActionItem.qml --- a/src/controls/private/GlobalDrawerActionItem.qml +++ b/src/controls/private/GlobalDrawerActionItem.qml @@ -45,7 +45,7 @@ MnemonicData.label: modelData.text property ActionsMenu actionsMenu: ActionsMenu { x: Qt.application.layoutDirection === Qt.RightToLeft ? -width : listItem.width - actions: modelData.children + actions: modelData.hasOwnProperty("children") ? modelData.children : null submenuComponent: Component { ActionsMenu {} } @@ -95,12 +95,12 @@ 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.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.tooltip.length || root.collapsed) && (!actionsMenu || !actionsMenu.visible) && listItem.hovered && text.length > 0 - text: modelData.tooltip.length ? modelData.tooltip : modelData.text + 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 @@ -128,8 +128,8 @@ if (!supportsMouseEvents) { return; } - modelData.trigger(); - if (modelData.children!==undefined && modelData.children.length > 0) { + 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) { 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 @@ -27,99 +27,112 @@ 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 +// implicitWidth: menuArrow.visible || (showText && ( action ? action.text.length > 0 : text.length > 0)) +// ? background.implicitWidth + menuArrow.width +// : 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 +// Theme.colorSet: Theme.Button +// Theme.inherit: action && action.icon.color.a === 0 + + Theme.colorSet: checked && (control.action && control.action.icon.color.a) ? Theme.Selection : Theme.Button + Theme.inherit: control.action && Theme.colorSet != Theme.Selection && control.action.icon.color.a === 0 + Theme.backgroundColor: action && action.icon.color.a ? action.icon.color : undefined + Theme.textColor: action && !flat && action.icon.color.a ? Theme.highlightedTextColor : undefined + hoverEnabled: true - flat: !control.kirigamiAction || !control.kirigamiAction.icon.color.a + flat: !control.action || !control.action.icon.color.a //TODO: replace with upstream action when we depend on Qt 5.10 - property Action kirigamiAction +// property Action action property bool showText: true property bool showMenuArrow: true property alias menu: menu //we need our own text delegate - text: "" - checkable: kirigamiAction && kirigamiAction.checkable - checked: (kirigamiAction && kirigamiAction.checked) || menu.visible - enabled: kirigamiAction && kirigamiAction.enabled + display: control.showText ? Controls.ToolButton.TextBesideIcon : Controls.ToolButton.IconOnly + text: (action && action.text && action.text.length > 0) ? action.text : "" + checkable: action && action.checkable + checked: (action && action.checked) || menu.visible + enabled: action && action.enabled opacity: enabled ? 1 : 0.4 - visible: kirigamiAction && kirigamiAction.visible + visible: action !== null && (!action.hasOwnProperty("visible") || action.visible) onClicked: { - if (kirigamiAction) { - kirigamiAction.trigger(); - } - if (kirigamiAction.children.length > 0 && !menu.visible) { + + if (action.hasOwnProperty("children") && action.children.length > 0 && !menu.visible) { control.menuAboutToShow(); menu.popup(control, 0, control.height) } } ActionsMenu { id: menu y: control.height - actions: control.kirigamiAction ? control.kirigamiAction.children : null + actions: control.action && control.action.hasOwnProperty("children") ? control.action.children : null submenuComponent: Component { ActionsMenu {} } } - 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 + contentItem.anchors.rightMargin: menuArrow.visible ? Units.iconSizes.small : 0 + + Icon { + id: menuArrow + anchors.left: control.right + anchors.verticalCenter: control.verticalCenter + color: control.icon.color + source: "arrow-down" + height: Units.iconSizes.small + width: height + visible: showMenuArrow && menu.actions && menu.actions.length > 0 + } + - 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 - } - } - } + +// contentItem: MouseArea { +// hoverEnabled: true +// onPressed: mouse.accepted = false +// Theme.colorSet: checked && (control.action && control.action.icon.color.a) ? Theme.Selection : control.Theme.colorSet +// Theme.inherit: control.action && Theme.colorSet != Theme.Selection && control.action.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.action ? (control.action.icon ? control.action.icon.name : control.action.iconName) : "" +// visible: control.action && control.action.iconName != "" && control.display != Controls.ToolButton.TextOnly +// color: control.flat && control.action && control.action.icon && control.action.icon.color.a > 0 ? control.action.icon.color : label.color +// } +// Controls.Label { +// id: label +// MnemonicData.enabled: control.enabled +// MnemonicData.controlType: MnemonicData.ActionElement +// MnemonicData.label: control.action ? control.action.text : "" +// +// text: MnemonicData.richTextLabel +// visible: control.showText && text.length > 0 && control.display != Controls.ToolButton.IconOnly +// +// Shortcut { +// sequence: label.MnemonicData.sequence +// onActivated: control.clicked() +// } +// } +// +// } +// } Controls.ToolTip { visible: control.hovered && text.length > 0 && !menu.visible && !control.pressed - text: kirigamiAction ? (kirigamiAction.tooltip.length ? kirigamiAction.tooltip : kirigamiAction.text) : "" + text: action && action.hasOwnProperty("tooltip") ? (action.tooltip.length ? action.tooltip : action.text) : "" delay: Units.toolTipDelay timeout: 5000 y: control.height } + +// background : null //now the button icon is drawn by the conteniTem and the style background } diff --git a/src/controls/private/globaltoolbar/ToolBarPageHeader.qml b/src/controls/private/globaltoolbar/ToolBarPageHeader.qml --- a/src/controls/private/globaltoolbar/ToolBarPageHeader.qml +++ b/src/controls/private/globaltoolbar/ToolBarPageHeader.qml @@ -76,18 +76,18 @@ Private.PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter - kirigamiAction: page && page.actions ? page.actions.left : null + action: page && page.actions ? page.actions.left : null showText: !parent.toobig } Private.PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter Layout.rightMargin: Units.smallSpacing - kirigamiAction: page && page.actions ? page.actions.main : null + action: page && page.actions ? page.actions.main : null showText: !parent.toobig } Private.PrivateActionToolButton { Layout.alignment: Qt.AlignVCenter - kirigamiAction: page && page.actions ? page.actions.right : null + action: page && page.actions ? page.actions.right : null showText: !parent.toobig } } @@ -109,7 +109,7 @@ children: page && page.actions.contextualActions ? page.actions.contextualActions : null } - kirigamiAction: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction + action: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction } }