Warning, /plasma/plasma-sdk/plasmoidviewer/qmlpackages/shell/contents/configuration/ConfigurationContainmentActions.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.0
0008 import QtQuick.Controls 2.3 as QtControls
0009 import QtQuick.Layouts 1.0
0010 
0011 Item {
0012     id: root
0013 
0014     signal configurationChanged
0015     implicitWidth: mainColumn.implicitWidth
0016     implicitHeight: mainColumn.implicitHeight
0017 
0018     property var prettyStrings: {
0019         "LeftButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Left-Button"),
0020         "RightButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Right-Button"),
0021         "MiddleButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Middle-Button"),
0022         "BackButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Back-Button"),
0023         "ForwardButton": i18nd("plasma_shell_org.kde.plasma.desktop", "Forward-Button"),
0024 
0025         "wheel:Vertical": i18nd("plasma_shell_org.kde.plasma.desktop", "Vertical-Scroll"),
0026         "wheel:Horizontal": i18nd("plasma_shell_org.kde.plasma.desktop", "Horizontal-Scroll"),
0027 
0028         "ShiftModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Shift"),
0029         "ControlModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Ctrl"),
0030         "AltModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Alt"),
0031         "MetaModifier": i18nd("plasma_shell_org.kde.plasma.desktop", "Meta")
0032     }
0033 
0034     function saveConfig() {
0035         configDialog.currentContainmentActionsModel.save();
0036     }
0037 
0038     Connections {
0039         target: configDialog.currentContainmentActionsModel
0040         function onConfigurationChanged() {
0041             root.configurationChanged()
0042         }
0043     }
0044 
0045     GridLayout {
0046         id: mainColumn
0047         flow: GridLayout.TopToBottom
0048         y: 25
0049         width: parent.width
0050 
0051         Repeater {
0052             id: actionsRepeater
0053             model: configDialog.currentContainmentActionsModel
0054 
0055             MouseEventInputButton {
0056                 Layout.column: 0
0057                 Layout.row: index
0058                 Layout.fillWidth: true
0059                 Layout.minimumWidth: implicitWidth
0060                 defaultText: {
0061                     var splitAction = model.action.split(';');
0062 
0063                     var button = splitAction[0];
0064                     var modifiers = (splitAction[1] || "").split('|').filter(function (item) {
0065                         return item !== "NoModifier";
0066                     });
0067 
0068                     var parts = modifiers;
0069                     modifiers.push(button);
0070 
0071                     return parts.map(function (item) {
0072                         return prettyStrings[item] || item;
0073                     }).join(i18nc("Concatenation sign for shortcuts, e.g. Ctrl+Shift", "+"));
0074                 }
0075                 eventString: model.action
0076                 onEventStringChanged: {
0077                     configDialog.currentContainmentActionsModel.update(index, eventString, model.pluginName);
0078                 }
0079             }
0080         }
0081 
0082         Repeater {
0083             model: configDialog.currentContainmentActionsModel
0084 
0085             QtControls.ComboBox {
0086                 id: pluginsCombo
0087                 // "index" argument of onActivated shadows the model index
0088                 readonly property int pluginIndex: index
0089                 Layout.fillWidth: true
0090                 Layout.column: 1
0091                 Layout.row: index
0092                 // both MouseEventInputButton and this ComboBox have fillWidth for a uniform layout
0093                 // however, their implicit sizes is taken into account and they compete against
0094                 // each other for available space. By setting an insane preferredWidth we give
0095                 // ComboBox a greater share of the available space
0096                 Layout.preferredWidth: 9000
0097                 model: configDialog.containmentActionConfigModel
0098                 textRole: "name"
0099                 property bool initialized: false
0100                 Component.onCompleted: {
0101                     for (var i = 0; i < configDialog.containmentActionConfigModel.count; ++i) {
0102                         if (configDialog.containmentActionConfigModel.get(i).pluginName === pluginName) {
0103                             pluginsCombo.currentIndex = i;
0104                             break;
0105                         }
0106                     }
0107                     pluginsCombo.initialized = true;
0108                 }
0109                 onActivated: {
0110                     if (initialized) {
0111                         var newPluginName = configDialog.containmentActionConfigModel.get(index).pluginName;
0112                         if (newPluginName !== pluginName) {
0113                             configDialog.currentContainmentActionsModel.update(pluginIndex, action, newPluginName);
0114                         }
0115                     }
0116                 }
0117             }
0118         }
0119 
0120         Repeater {
0121             model: configDialog.currentContainmentActionsModel
0122 
0123             RowLayout {
0124                 Layout.column: 2
0125                 Layout.row: index
0126 
0127                 QtControls.Button {
0128                     icon.name: "configure"
0129                     width: height
0130                     enabled: model.hasConfigurationInterface
0131                     onClicked: {
0132                         configDialog.currentContainmentActionsModel.showConfiguration(index, this);
0133                     }
0134                 }
0135                 QtControls.Button {
0136                     icon.name: "dialog-information"
0137                     width: height
0138                     onClicked: {
0139                         configDialog.currentContainmentActionsModel.showAbout(index, this);
0140                     }
0141                 }
0142                 QtControls.Button {
0143                     icon.name: "list-remove"
0144                     width: height
0145                     onClicked: {
0146                         configDialog.currentContainmentActionsModel.remove(index);
0147                     }
0148                 }
0149             }
0150         }
0151 
0152         MouseEventInputButton {
0153             defaultText: i18nd("plasma_shell_org.kde.plasma.desktop", "Add Action");
0154             onEventStringChanged: {
0155                 configDialog.currentContainmentActionsModel.append(eventString, "org.kde.contextmenu");
0156             }
0157         }
0158     }
0159 
0160 }