Warning, /plasma/kwin/src/kcms/rules/ui/RuleItemDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import QtQuick.Controls as QQC2
0010 import org.kde.kirigami 2.10 as Kirigami
0011 import org.kde.kcmutils as KCM
0012 
0013 QQC2.ItemDelegate {
0014     id: ruleDelegate
0015 
0016     property bool ruleEnabled: model.enabled
0017 
0018     Kirigami.Theme.colorSet: Kirigami.Theme.View
0019 
0020     width: ListView.view.width
0021     highlighted: false
0022     hoverEnabled: false
0023     down: false
0024 
0025     contentItem: RowLayout {
0026 
0027         Kirigami.Icon {
0028             id: itemIcon
0029             source: model.icon
0030             Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium
0031             Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
0032             Layout.rightMargin: Kirigami.Units.smallSpacing
0033             Layout.alignment: Qt.AlignVCenter
0034         }
0035 
0036         RowLayout {
0037             Layout.preferredWidth: 10 * Kirigami.Units.gridUnit
0038             spacing: Kirigami.Units.smallSpacing
0039 
0040             QQC2.Label {
0041                 id: label
0042                 text: model.name
0043                 horizontalAlignment: Text.AlignLeft
0044                 elide: Text.ElideRight
0045                 Layout.fillWidth: true
0046                 Layout.alignment: Qt.AlignVCenter
0047 
0048                 HoverHandler {
0049                     id: labelHover
0050                     enabled: label.truncated
0051                 }
0052 
0053                 QQC2.ToolTip.text: model.name
0054                 QQC2.ToolTip.visible: labelHover.hovered
0055                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0056             }
0057 
0058             KCM.ContextualHelpButton {
0059                 Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0060                 Layout.alignment: Qt.AlignVCenter
0061                 visible: model.description.length > 0
0062                 toolTipText: model.description
0063             }
0064         }
0065 
0066         RowLayout {
0067             // This layout keeps the width constant between delegates, independent of items visibility
0068             Layout.fillWidth: true
0069             Layout.preferredWidth: 20 * Kirigami.Units.gridUnit
0070             Layout.minimumWidth: 13 * Kirigami.Units.gridUnit
0071 
0072             OptionsComboBox {
0073                 id: policyCombo
0074                 Layout.preferredWidth: 50  // 50%
0075                 Layout.fillWidth: true
0076                 Layout.alignment: Qt.AlignVCenter
0077 
0078                 visible: count > 0
0079                 enabled: ruleEnabled
0080 
0081                 model: policyModel
0082                 onActivated: {
0083                     policy = currentValue;
0084                 }
0085             }
0086 
0087             ValueEditor {
0088                 id: valueEditor
0089                 Layout.preferredWidth: 50  // 50%
0090                 Layout.fillWidth: true
0091                 Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
0092 
0093                 enabled: model.enabled
0094 
0095                 ruleValue: model.value
0096                 ruleOptions: model.options
0097                 controlType: model.type
0098 
0099                 onValueEdited: (value) => {
0100                     model.value = value;
0101                 }
0102             }
0103 
0104             QQC2.ToolButton {
0105                 id: itemEnabled
0106                 icon.name: "edit-delete"
0107                 visible: model.selectable
0108                 Layout.alignment: Qt.AlignVCenter
0109                 onClicked: {
0110                     model.enabled = false;
0111                 }
0112             }
0113         }
0114 
0115         QQC2.ToolTip {
0116             text: model.description
0117             visible: hovered && (text.length > 0)
0118         }
0119     }
0120 }