Warning, /plasma/latte-dock/shell/package/contents/controls/CustomVisibilityModeButton.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.1
0007 
0008 import org.kde.plasma.plasmoid 2.0
0009 import org.kde.plasma.core 2.0 as PlasmaCore
0010 
0011 import org.kde.latte.core 0.2 as LatteCore
0012 import org.kde.latte.components 1.0 as LatteComponents
0013 
0014 LatteComponents.ComboBoxButton{
0015     id: custom
0016     checkable: true
0017 
0018     buttonText: modes[currentModeIndex].name
0019     buttonToolTip: modes[currentModeIndex].tooltip
0020 
0021     comboBoxTextRole: "name"
0022     comboBoxMinimumPopUpWidth: width
0023     comboBoxBlankSpaceForEmptyIcons: false
0024     comboBoxForcePressed: checked // latteView.visibility.mode === mode
0025     comboBoxPopUpAlignRight: Qt.application.layoutDirection !== Qt.RightToLeft
0026     comboBoxPopupTextHorizontalAlignment: Text.AlignHCenter
0027 
0028     property int mode: LatteCore.Types.WindowsGoBelow
0029     readonly property int currentModeIndex: {
0030         for (var i=0; i<modes.length; ++i) {
0031             if (modes[i].pluginId === mode) {
0032                 return i;
0033             }
0034         }
0035 
0036         return 0;
0037     }
0038 
0039     readonly property int firstVisibilityMode:  modes[0].pluginId
0040     readonly property int lastVisibilityMode: modes[modes.length - 1].pluginId
0041 
0042     property variant modes: []
0043 
0044     signal viewRelevantVisibilityModeChanged();
0045 
0046     Component.onCompleted: {
0047         reloadModel();
0048     }
0049 
0050     ListModel {
0051         id: actionsModel
0052     }
0053 
0054     Connections{
0055         target: custom.button
0056         onClicked: {
0057             latteView.visibility.mode = custom.mode;
0058         }
0059     }
0060 
0061     Connections{
0062         target: custom.comboBox.popup
0063         onVisibleChanged: {
0064             if (visible) {
0065                 custom.selectChosenType();
0066             }
0067         }
0068     }
0069 
0070     Connections {
0071         target: latteView.visibility
0072         onModeChanged: {
0073             for (var i=0; i<custom.modes.length; ++i) {
0074                 if (custom.modes[i].pluginId === latteView.visibility.mode) {
0075                     custom.viewRelevantVisibilityModeChanged();
0076                     return;
0077                 }
0078             }
0079         }
0080     }
0081 
0082     Connections{
0083         target: custom.comboBox
0084 
0085         onActivated: {
0086             if (index>=0) {
0087                 var item = actionsModel.get(index);
0088                 latteView.visibility.mode = item.pluginId;
0089             }
0090         }
0091     }
0092 
0093     function reloadModel() {
0094         actionsModel.clear();
0095         appendDefaults();
0096         comboBox.model = actionsModel;
0097         selectChosenType();
0098     }
0099 
0100     function selectChosenType() {
0101         var found = false;
0102 
0103         for (var i=0; i<actionsModel.count; ++i) {
0104             if (actionsModel.get(i).pluginId === custom.mode) {
0105                 found = true;
0106                 custom.comboBox.currentIndex = i;
0107                 break;
0108             }
0109         }
0110 
0111         if (!found) {
0112             custom.comboBox.currentIndex = -1;
0113         }
0114     }
0115 
0116     function emptyModel() {
0117         actionsModel.clear();
0118         appendDefaults();
0119 
0120         comboBox.model = actionsModel;
0121         comboBox.currentIndex = -1;
0122     }
0123 
0124     function appendDefaults() {
0125         for (var i=0; i<modes.length; ++i) {
0126             actionsModel.append(modes[i]);
0127         }
0128     }
0129 }