Warning, /plasma/kwin/src/kcms/rules/ui/OptionsComboBox.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 0011 import org.kde.kirigami 2.10 as Kirigami 0012 import org.kde.kcms.kwinrules 0013 0014 0015 QQC2.ComboBox { 0016 id: optionsCombo 0017 0018 textRole: "display" 0019 valueRole: "value" 0020 0021 property bool multipleChoice: false 0022 property int selectionMask: 0 0023 readonly property int allOptionsMask: model.allOptionsMask 0024 0025 currentIndex: multipleChoice ? -1 : model.selectedIndex 0026 0027 displayText: { 0028 if (!multipleChoice) { 0029 return currentText; 0030 } 0031 const selectionCount = selectionMask.toString(2).replace(/0/g, '').length; 0032 const optionsCount = allOptionsMask.toString(2).replace(/0/g, '').length; 0033 switch (selectionCount) { 0034 case 0: 0035 return i18n("None selected"); 0036 case 1: 0037 const selectedBit = selectionMask.toString(2).length - 1; 0038 const selectedIndex = (model.useFlags) ? model.indexOf(selectionMask) : selectedBit 0039 return model.data(model.index(selectedIndex, 0), Qt.DisplayRole); 0040 case optionsCount: 0041 return i18n("All selected"); 0042 } 0043 return i18np("%1 selected", "%1 selected", selectionCount); 0044 } 0045 0046 delegate: QQC2.ItemDelegate { 0047 id: delegateItem 0048 0049 highlighted: optionsCombo.highlightedIndex == index 0050 width: parent.width 0051 0052 contentItem: RowLayout { 0053 QQC2.RadioButton { 0054 id: radioButton 0055 visible: multipleChoice && model.optionType === OptionsModel.ExclusiveOption 0056 checked: (selectionMask & bitMask) == bitMask 0057 enabled: false // We don't want to uncheck the exclusive option on toggle 0058 } 0059 QQC2.CheckBox { 0060 id: checkBox 0061 visible: multipleChoice && model.optionType !== OptionsModel.ExclusiveOption 0062 checked: (selectionMask & model.bitMask) == model.bitMask 0063 onToggled: { 0064 selectionMask = (checked) ? selectionMask | model.bitMask : selectionMask & ~model.bitMask; 0065 selectionMask &= allOptionsMask; 0066 activated(index); 0067 } 0068 } 0069 Kirigami.Icon { 0070 source: model.decoration 0071 Layout.preferredHeight: Kirigami.Units.iconSizes.small 0072 Layout.preferredWidth: Kirigami.Units.iconSizes.small 0073 } 0074 QQC2.Label { 0075 text: model.display 0076 color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor 0077 Layout.fillWidth: true 0078 horizontalAlignment: Text.AlignLeft 0079 } 0080 } 0081 0082 MouseArea { 0083 anchors.fill: contentItem 0084 enabled: multipleChoice 0085 onClicked: { 0086 if (checkBox.visible) { 0087 checkBox.toggle(); 0088 checkBox.toggled(); 0089 } else if (radioButton.visible) { 0090 selectionMask = model.bitMask; // Only check the exclusive option 0091 activated(index); 0092 } 0093 } 0094 } 0095 0096 QQC2.ToolTip { 0097 text: model.tooltip 0098 visible: hovered && (model.tooltip.length > 0) 0099 } 0100 0101 Component.onCompleted: { 0102 //FIXME: work around bug https://bugs.kde.org/show_bug.cgi?id=403153 0103 optionsCombo.popup.width = Math.max(implicitWidth, optionsCombo.width, optionsCombo.popup.width); 0104 } 0105 0106 onActiveFocusChanged: { 0107 if (!activeFocus) { 0108 popup.close(); 0109 } 0110 } 0111 } 0112 }