Kirigami2

ContextDrawerActionItem.qml
1/*
2 * SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
3 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8import QtQuick
9import QtQuick.Controls as QQC2
10import QtQuick.Templates as T
11import QtQuick.Layouts
12import org.kde.kirigami as Kirigami
13
14QQC2.ItemDelegate {
15 id: listItem
16
17 required property T.Action tAction
18
19 readonly property Kirigami.Action kAction: tAction instanceof Kirigami.Action ? tAction : null
20
21 readonly property bool isSeparator: kAction?.separator ?? false
22 readonly property bool isExpandable: kAction?.expandible ?? false
23
24 checked: tAction.checked || (actionsMenu && actionsMenu.visible)
25 highlighted: checked
26 icon.name: tAction.icon.name
27
28 text: tAction.text ? tAction.text : tAction.tooltip
29 hoverEnabled: (!isExpandable || root.collapsed) && !Kirigami.Settings.tabletMode && !isSeparator
30 font.pointSize: Kirigami.Theme.defaultFont.pointSize * (isExpandable ? 1.30 : 1)
31
32 enabled: !isExpandable && tAction.enabled
33 visible: kAction?.visible ?? true
34 opacity: enabled || isExpandable ? 1.0 : 0.6
35
36 Accessible.onPressAction: listItem.clicked()
37
38 Kirigami.Separator {
39 id: separatorAction
40
41 visible: listItem.isSeparator
42 Layout.fillWidth: true
43 }
44
45 ActionsMenu {
46 id: actionsMenu
47 y: Kirigami.Settings.isMobile ? -height : listItem.height
48 actions: kAction?.children ?? []
49 submenuComponent: ActionsMenu {}
50 }
51
52 Loader {
53 Layout.fillWidth: true
54 Layout.fillHeight: true
55 sourceComponent: kAction?.displayComponent ?? null
56 onStatusChanged: {
57 for (const child of parent.children) {
58 if (child === this) {
59 child.visible = status === Loader.Ready;
60 break;
61 } else {
62 child.visible = status !== Loader.Ready;
63 }
64 }
65 }
66 Component.onCompleted: statusChanged()
67 }
68
69 onPressed: {
70 if (kAction && kAction.children.length > 0) {
71 actionsMenu.open();
72 }
73 }
74 onClicked: {
75 if (!kAction || kAction.children.length === 0) {
76 root.drawerOpen = false;
77 }
78
79 tAction?.trigger();
80 }
81}
Q_SCRIPTABLE CaptureState status()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:52:23 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.