Warning, /plasma/plasma-desktop/desktoppackage/contents/explorer/AppletAlternatives.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.15 0008 import QtQuick.Controls 2.5 as QQC2 0009 import QtQuick.Layouts 1.1 0010 import QtQuick.Window 2.1 0011 import org.kde.plasma.core as PlasmaCore 0012 import org.kde.plasma.components 3.0 as PlasmaComponents3 0013 import org.kde.plasma.extras 2.0 as PlasmaExtras 0014 import org.kde.plasma.plasmoid 0015 import org.kde.kirigami 2.20 as Kirigami 0016 0017 import org.kde.plasma.private.shell 2.0 0018 0019 PlasmaCore.Dialog { 0020 id: dialog 0021 visualParent: alternativesHelper.applet 0022 location: alternativesHelper.applet.Plasmoid.location 0023 hideOnWindowDeactivate: true 0024 backgroundHints: (alternativesHelper.applet.Plasmoid.containmentDisplayHints & PlasmaCore.Types.ContainmentPrefersOpaqueBackground) ? PlasmaCore.Dialog.SolidBackground : PlasmaCore.Dialog.StandardBackground 0025 0026 Component.onCompleted: { 0027 flags = flags | Qt.WindowStaysOnTopHint; 0028 dialog.show(); 0029 } 0030 0031 ColumnLayout { 0032 id: root 0033 0034 signal configurationChanged 0035 0036 Layout.minimumWidth: Kirigami.Units.gridUnit * 20 0037 Layout.minimumHeight: Math.min(Screen.height - Kirigami.Units.gridUnit * 10, implicitHeight) 0038 0039 LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft 0040 LayoutMirroring.childrenInherit: true 0041 0042 property string currentPlugin: "" 0043 0044 Shortcut { 0045 sequence: "Escape" 0046 onActivated: dialog.close() 0047 } 0048 Shortcut { 0049 sequence: "Return" 0050 onActivated: root.savePluginAndClose() 0051 } 0052 Shortcut { 0053 sequence: "Enter" 0054 onActivated: root.savePluginAndClose() 0055 } 0056 0057 0058 WidgetExplorer { 0059 id: widgetExplorer 0060 provides: alternativesHelper.appletProvides 0061 } 0062 0063 PlasmaExtras.PlasmoidHeading { 0064 Kirigami.Heading { 0065 id: heading 0066 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Alternative Widgets") 0067 textFormat: Text.PlainText 0068 } 0069 } 0070 0071 // This timer checks with a short delay whether a new item in the list has been hovered by the cursor. 0072 // If not, then the cursor has left the view and thus no item should be selected. 0073 Timer { 0074 id: resetCurrentIndex 0075 property string oldPlugin 0076 interval: 100 0077 onTriggered: { 0078 if (root.currentPlugin === oldPlugin) { 0079 mainList.currentIndex = -1 0080 root.currentPlugin = "" 0081 } 0082 } 0083 } 0084 0085 function savePluginAndClose() { 0086 alternativesHelper.loadAlternative(currentPlugin); 0087 dialog.close(); 0088 } 0089 0090 PlasmaComponents3.ScrollView { 0091 Layout.fillWidth: true 0092 Layout.fillHeight: true 0093 0094 Layout.preferredHeight: mainList.contentHeight 0095 0096 focus: true 0097 0098 ListView { 0099 id: mainList 0100 0101 focus: dialog.visible 0102 model: widgetExplorer.widgetsModel 0103 boundsBehavior: Flickable.StopAtBounds 0104 highlight: PlasmaExtras.Highlight { 0105 pressed: mainList.currentItem && mainList.currentItem.pressed 0106 } 0107 highlightMoveDuration : 0 0108 highlightResizeDuration: 0 0109 0110 height: contentHeight+Kirigami.Units.smallSpacing 0111 0112 delegate: PlasmaComponents3.ItemDelegate { 0113 id: listItem 0114 0115 implicitHeight: contentLayout.implicitHeight + Kirigami.Units.smallSpacing * 2 0116 width: ListView.view.width 0117 0118 onHoveredChanged: { 0119 if (hovered) { 0120 resetCurrentIndex.stop() 0121 mainList.currentIndex = index 0122 } else { 0123 resetCurrentIndex.oldPlugin = model.pluginName 0124 resetCurrentIndex.restart() 0125 } 0126 } 0127 0128 Connections { 0129 target: mainList 0130 function onCurrentIndexChanged() { 0131 if (mainList.currentIndex === index) { 0132 root.currentPlugin = model.pluginName 0133 } 0134 } 0135 } 0136 0137 onClicked: root.savePluginAndClose() 0138 0139 Component.onCompleted: { 0140 if (model.pluginName === alternativesHelper.currentPlugin) { 0141 root.currentPlugin = model.pluginName 0142 setAsCurrent.restart() 0143 } 0144 } 0145 0146 // we don't want to select any entry by default 0147 // this cannot be set in Component.onCompleted 0148 Timer { 0149 id: setAsCurrent 0150 interval: 100 0151 onTriggered: { 0152 mainList.currentIndex = index 0153 } 0154 } 0155 0156 contentItem: RowLayout { 0157 id: contentLayout 0158 spacing: Kirigami.Units.largeSpacing 0159 0160 Kirigami.Icon { 0161 implicitWidth: Kirigami.Units.iconSizes.huge 0162 implicitHeight: Kirigami.Units.iconSizes.huge 0163 source: model.decoration 0164 } 0165 0166 ColumnLayout { 0167 id: labelLayout 0168 0169 readonly property color textColor: listItem.pressed ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor 0170 0171 Layout.fillHeight: true 0172 Layout.fillWidth: true 0173 spacing: 0 // The labels bring their own bottom margins 0174 0175 Kirigami.Heading { 0176 level: 4 0177 Layout.fillWidth: true 0178 text: model.name 0179 textFormat: Text.PlainText 0180 elide: Text.ElideRight 0181 type: model.pluginName === alternativesHelper.currentPlugin ? PlasmaExtras.Heading.Type.Primary : PlasmaExtras.Heading.Type.Normal 0182 color: labelLayout.textColor 0183 } 0184 0185 PlasmaComponents3.Label { 0186 Layout.fillWidth: true 0187 text: model.description 0188 textFormat: Text.PlainText 0189 font.pointSize: Kirigami.Theme.smallFont.pointSize 0190 font.family: Kirigami.Theme.smallFont.family 0191 font.bold: model.pluginName === alternativesHelper.currentPlugin 0192 opacity: 0.6 0193 maximumLineCount: 2 0194 wrapMode: Text.WordWrap 0195 elide: Text.ElideRight 0196 color: labelLayout.textColor 0197 } 0198 } 0199 } 0200 } 0201 } 0202 } 0203 } 0204 }