/*SPDX-FileCopyrightText: 2013-2015 Eike Hein <hein@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport org.kde.kirigami as Kirigamiimport org.kde.ksvg as KSvgimport org.kde.plasma.components as PlasmaComponents3import "code/tools.js" as ToolsItem {id: itemheight: isSeparator ? separatorHeight : itemHeightwidth: ListView.view.width// if it's not disabled and is either a leaf node or a node with childrenenabled: !isSeparator && !disabled && (!isParent || (isParent && hasChildren))signal actionTriggered(string actionId, var actionArgument)signal aboutToShowActionMenu(var actionMenu)required property int indexrequired property bool isSeparatorrequired property bool hasChildrenrequired property bool isParentrequired property bool disabledrequired property bool hasActionListrequired property string favoriteIdrequired property var /*QVariantList*/ actionListrequired property url urlrequired property string descriptionrequired property string decorationrequired property string displayproperty alias pressed: tapHandler.pressedproperty alias hovered: mouseArea.containsMouseproperty alias hoverEnabled: mouseArea.hoverEnabledreadonly property bool iconAndLabelsShouldlookSelected: pressed && !hasChildrenreadonly property real fullTextWidth: Math.ceil(icon.width + label.implicitWidth + arrow.width + row.anchors.leftMargin + row.anchors.rightMargin + row.actualSpacing)property bool showSeparators: trueproperty QtObject childDialog: nullproperty ActionMenu menu: actionMenuproperty bool dialogDefaultRight: Qt.application.layoutDirection !== Qt.RightToLeftAccessible.role: isSeparator ? Accessible.Separator : Accessible.MenuItemAccessible.name: label.textonHasChildrenChanged: {if (!hasChildren && ListView.view.currentItem === item) {ListView.view.currentIndex = -1;}}onAboutToShowActionMenu: actionMenu => {var actionList = item.hasActionList ? item.actionList : [];Tools.fillActionMenu(i18n, actionMenu, actionList, ListView.view.model.favoritesModel, item.favoriteId);}onActionTriggered: (actionId, actionArgument) => {if (Tools.triggerAction(ListView.view.model, item.index, actionId, actionArgument) === true) {kicker.expanded = false;}}function openActionMenu(visualParent, x, y) {aboutToShowActionMenu(actionMenu);actionMenu.visualParent = visualParent;actionMenu.open(x, y);}ActionMenu {id: actionMenuonActionClicked: (actionId, actionArgument) => {item.actionTriggered(actionId, actionArgument);}}DragHandler {target: nullonActiveChanged: {if (active && url) {// we need dragHelper and can't use attached Drag; submenus are destroyed too soon and Plasma crashesdragHelper.startDrag(kicker, url, decoration)}}}TapHandler {id: tapHandleronTapped: {if (!item.hasChildren) {item.ListView.view.model.trigger(index, "", null);kicker.expanded = false;}}}MouseArea {id: mouseAreaanchors.fill: parentproperty int mouseColhoverEnabled: trueacceptedButtons: Qt.RightButtononPressed: mouse => {if (item.hasActionList) {item.openActionMenu(mouseArea, mouse.x, mouse.y);}}onPositionChanged: mouse => {// FIXME: Correct escape angle calc for right screen edge.if (justOpenedTimer.running || !item.hasChildren) {item.ListView.view.currentIndex = item.index;} else {mouseCol = mouse.x;if (item.index === item.ListView.view.currentIndex) {updateCurrentItem();} else if ((item.index === item.ListView.view.currentIndex - 1) && mouse.y < (itemHeight - 6)|| (item.index === item.ListView.view.currentIndex + 1) && mouse.y > 5) {if ((item.childDialog && item.childDialog.facingLeft)? mouse.x > item.ListView.view.eligibleWidth - 5 : mouse.x < item.ListView.view.eligibleWidth + 5) {updateCurrentItem();}} else if ((item.childDialog && item.childDialog.facingLeft)? mouse.x > item.ListView.view.eligibleWidth : mouse.x < item.ListView.view.eligibleWidth) {updateCurrentItem();}updateCurrentItemTimer.start();}}onContainsMouseChanged: {if (!containsMouse) {updateCurrentItemTimer.stop();}}function updateCurrentItem() {item.ListView.view.currentIndex = item.index;item.ListView.view.eligibleWidth = Math.min(width, mouseCol);}Timer {id: updateCurrentItemTimerinterval: 50repeat: falseonTriggered: parent.updateCurrentItem()}}Row {id: rowanchors.left: parent.leftanchors.leftMargin: highlightItemSvg.margins.leftanchors.right: parent.rightanchors.rightMargin: highlightItemSvg.margins.rightheight: parent.heightspacing: Kirigami.Units.smallSpacing * 2readonly property real actualSpacing: ((icon.visible ? 1 : 0) * spacing) + ((arrow.visible ? 1 : 0) * spacing)LayoutMirroring.enabled: (Qt.application.layoutDirection === Qt.RightToLeft)Kirigami.Icon {id: iconanchors.verticalCenter: parent.verticalCenterwidth: visible ? Kirigami.Units.iconSizes.small : 0height: widthvisible: iconsEnabledanimated: falseselected: item.iconAndLabelsShouldlookSelectedsource: item.decoration}PlasmaComponents3.Label {id: labelenabled: !item.isParent || (item.isParent && item.hasChildren)anchors.verticalCenter: parent.verticalCenterwidth: parent.width - icon.width - arrow.width - parent.actualSpacingverticalAlignment: Text.AlignVCentertextFormat: Text.PlainTextwrapMode: Text.NoWrapelide: Text.ElideRightcolor: item.iconAndLabelsShouldlookSelected ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColortext: item.display ?? ""}Kirigami.Icon {id: arrowanchors.verticalCenter: parent.verticalCenterwidth: visible ? Kirigami.Units.iconSizes.small : 0height: widthvisible: item.hasChildrenopacity: (item.ListView.view.currentIndex === item.index) ? 1.0 : 0.4selected: item.iconAndLabelsShouldlookSelectedsource: item.dialogDefaultRight? "go-next-symbolic": "go-next-rtl-symbolic"}}Component {id: separatorComponentKSvg.SvgItem {width: parent.widthimagePath: "widgets/line"elementId: "horizontal-line"}}Loader {id: separatorLoaderanchors.left: parent.leftanchors.leftMargin: highlightItemSvg.margins.leftanchors.right: parent.rightanchors.rightMargin: highlightItemSvg.margins.rightanchors.verticalCenter: parent.verticalCenter// Separator positions don't make sense when sorting everything alphabeticallyactive: item.isSeparator && item.showSeparatorsasynchronous: falsesourceComponent: separatorComponent}Keys.onPressed: event => {if (event.key === Qt.Key_Menu && item.hasActionList) {event.accepted = true;item.openActionMenu(mouseArea);} else if ((event.key === Qt.Key_Enter || event.key === Qt.Key_Return) && !item.hasChildren) {if (!item.hasChildren) {event.accepted = true;item.ListView.view.model.trigger(item.index, "", null);kicker.expanded = false;}}}}