KCMUtils

PluginDelegate.qml
1/*
2 SPDX-FileCopyrightText: 2022 Alexander Lohnau <alexander.lohnau@gmx.de>
3 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8pragma ComponentBehavior: Bound
9
10import QtQuick
11import QtQuick.Controls as QQC2
12import QtQuick.Layouts
13import QtQuick.Templates as T
15import org.kde.kirigami as Kirigami
16import org.kde.kcmutils as KCMUtils
17
18/// @since 6.0, this got renamed from KPluginDelegate to PluginDelegate
19Kirigami.CheckSubtitleDelegate {
20 id: listItem
21
22 // Note: when PluginDelegate is embedded in a more complex delegate, model
23 // object should be passed down explicitly, but it also means that it may
24 // become null right before delegate's destruction.
25 required property var model
27 property list<T.Action> additionalActions
28
29 property alias leading: leadingProxy.target
30
31 readonly property bool enabledByDefault: model?.enabledByDefault ?? false
32 readonly property var metaData: model?.metaData
33 readonly property bool configureVisible: model?.config.isValid ?? false
34
35 signal configTriggered()
36
37 // Let Optional chaining (?.) operator fall back to `undefined` which resets the width to an implicit value.
38 width: ListView.view?.width
39
40 icon.name: model?.icon ?? ""
41 text: model?.name ?? ""
42 subtitle: model?.description ?? ""
43 checked: model?.enabled ?? false
44
45 // TODO: It should be possible to disable this
46 onToggled: model.enabled = checked
47
48 contentItem: RowLayout {
49 spacing: Kirigami.Units.smallSpacing
50
51 // Used by CheckSubtitleDelegate through duck-typing
52 readonly property alias truncated: titleSubtitle.truncated
53
54 LayoutItemProxy {
55 id: leadingProxy
56 visible: target !== null
57 }
58
59 Kirigami.IconTitleSubtitle {
60 id: titleSubtitle
61
62 Layout.fillWidth: true
63 Layout.maximumWidth: Math.ceil(implicitWidth)
64
65 icon: icon.fromControlsIcon(listItem.icon)
66 title: listItem.text
67 subtitle: listItem.subtitle
68 reserveSpaceForSubtitle: true
69 }
70
71 Kirigami.ActionToolBar {
72 Layout.fillWidth: true
73 Layout.alignment: Qt.AlignRight
74 alignment: Qt.AlignRight
75 actions: [infoAction, configureAction, ...listItem.additionalActions]
76 }
77 }
78
79 KCMUtils.SettingHighlighter {
80 target: listItem.indicator
81 highlight: listItem.checked !== listItem.enabledByDefault
82 }
83
84 // Take care of displaying the actions
85 readonly property Kirigami.Action __infoAction: Kirigami.Action {
86 id: infoAction
87
88 icon.name: "help-about-symbolic"
89 text: i18ndc("kcmutils6", "@info:tooltip", "About")
90 displayHint: Kirigami.DisplayHint.IconOnly
91 onTriggered: {
92 const aboutDialog = (listItem.ListView.view ?? listItem.parent.ListView.view).__aboutDialog;
93 aboutDialog.metaDataInfo = listItem.metaData;
94 aboutDialog.open();
95 }
96 }
97
98 readonly property Kirigami.Action __configureAction: Kirigami.Action {
99 id: configureAction
100
101 visible: listItem.configureVisible
102 enabled: listItem.checked
103 icon.name: "configure-symbolic"
104 text: i18ndc("kcmutils6", "@info:tooltip", "Configureā€¦")
105 displayHint: Kirigami.DisplayHint.IconOnly
106 onTriggered: listItem.configTriggered()
107 }
108}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.