Warning, /plasma/plasma-desktop/desktoppackage/contents/explorer/WidgetExplorer.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.7 0008 import QtQuick.Controls 2.5 as QQC2 0009 0010 import org.kde.plasma.components 3.0 as PC3 0011 import org.kde.plasma.core as PlasmaCore 0012 import org.kde.plasma.extras 2.0 as PlasmaExtras 0013 import org.kde.kquickcontrolsaddons 2.0 0014 import org.kde.kwindowsystem 1.0 0015 import org.kde.kirigami 2.20 as Kirigami 0016 0017 import QtQuick.Window 2.1 0018 import QtQuick.Layouts 1.1 0019 0020 import org.kde.plasma.private.shell 2.0 0021 0022 PC3.Page { 0023 id: main 0024 0025 width: Math.max(heading.paintedWidth, Kirigami.Units.iconSizes.enormous * 3 + Kirigami.Units.smallSpacing * 4 + Kirigami.Units.gridUnit * 2) 0026 height: 800//Screen.height 0027 0028 opacity: draggingWidget ? 0.3 : 1 0029 0030 property QtObject containment 0031 0032 property PlasmaCore.Dialog sidePanel 0033 0034 //external drop events can cause a raise event causing us to lose focus and 0035 //therefore get deleted whilst we are still in a drag exec() 0036 //this is a clue to the owning dialog that hideOnWindowDeactivate should be deleted 0037 //See https://bugs.kde.org/show_bug.cgi?id=332733 0038 property bool preventWindowHide: draggingWidget || categoriesDialog.status !== PlasmaExtras.Menu.Closed 0039 || getWidgetsDialog.status !== PlasmaExtras.Menu.Closed 0040 0041 property bool outputOnly: draggingWidget 0042 0043 property Item categoryButton 0044 0045 property bool draggingWidget: false 0046 0047 signal closed() 0048 0049 onVisibleChanged: { 0050 if (!visible) { 0051 KWindowSystem.showingDesktop = false 0052 } 0053 } 0054 0055 Component.onCompleted: { 0056 if (!root.widgetExplorer) { 0057 root.widgetExplorer = widgetExplorerComponent.createObject(root) 0058 } 0059 root.widgetExplorer.containment = main.containment 0060 } 0061 0062 Component.onDestruction: { 0063 if (pendingUninstallTimer.running) { 0064 // we're not being destroyed so at least reset the filters 0065 widgetExplorer.widgetsModel.filterQuery = "" 0066 widgetExplorer.widgetsModel.filterType = "" 0067 widgetExplorer.widgetsModel.searchTerm = "" 0068 } else { 0069 root.widgetExplorer.destroy() 0070 root.widgetExplorer = null 0071 } 0072 } 0073 0074 function addCurrentApplet() { 0075 var pluginName = list.currentItem ? list.currentItem.pluginName : "" 0076 if (pluginName) { 0077 widgetExplorer.addApplet(pluginName) 0078 } 0079 } 0080 0081 QQC2.Action { 0082 shortcut: "Escape" 0083 onTriggered: { 0084 if (searchInput.length > 0) { 0085 searchInput.text = "" 0086 } else { 0087 main.closed() 0088 } 0089 } 0090 } 0091 0092 QQC2.Action { 0093 shortcut: "Enter" 0094 onTriggered: addCurrentApplet() 0095 } 0096 QQC2.Action { 0097 shortcut: "Return" 0098 onTriggered: addCurrentApplet() 0099 } 0100 0101 Component { 0102 id: widgetExplorerComponent 0103 0104 WidgetExplorer { 0105 //view: desktop 0106 onShouldClose: main.closed(); 0107 } 0108 } 0109 0110 PlasmaExtras.ModelContextMenu { 0111 id: categoriesDialog 0112 visualParent: categoryButton 0113 // model set on first invocation 0114 0115 onClicked: { 0116 list.contentX = 0 0117 list.contentY = 0 0118 categoryButton.text = (model.filterData ? model.display : i18nd("plasma_shell_org.kde.plasma.desktop", "All Widgets")) 0119 widgetExplorer.widgetsModel.filterQuery = model.filterData 0120 widgetExplorer.widgetsModel.filterType = model.filterType 0121 } 0122 } 0123 0124 PlasmaExtras.ModelContextMenu { 0125 id: getWidgetsDialog 0126 visualParent: getWidgetsButton 0127 placement: PlasmaExtras.Menu.TopPosedLeftAlignedPopup 0128 // model set on first invocation 0129 onClicked: model.trigger() 0130 } 0131 0132 header: PlasmaExtras.PlasmoidHeading { 0133 ColumnLayout { 0134 id: header 0135 anchors.fill: parent 0136 0137 spacing: Kirigami.Units.smallSpacing 0138 0139 RowLayout { 0140 spacing: Kirigami.Units.smallSpacing 0141 Kirigami.Heading { 0142 id: heading 0143 level: 1 0144 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Widgets") 0145 textFormat: Text.PlainText 0146 elide: Text.ElideRight 0147 0148 Layout.fillWidth: true 0149 } 0150 PC3.ToolButton { 0151 id: getWidgetsButton 0152 icon.name: "get-hot-new-stuff" 0153 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Get New Widgets…") 0154 0155 KeyNavigation.right: closeButton 0156 KeyNavigation.down: searchInput 0157 0158 onClicked: { 0159 getWidgetsDialog.model = widgetExplorer.widgetsMenuActions 0160 getWidgetsDialog.openRelative() 0161 } 0162 } 0163 PC3.ToolButton { 0164 id: closeButton 0165 icon.name: "window-close" 0166 0167 KeyNavigation.down: categoryButton 0168 0169 onClicked: main.closed() 0170 } 0171 } 0172 0173 RowLayout { 0174 spacing: Kirigami.Units.smallSpacing 0175 0176 PlasmaExtras.SearchField { 0177 id: searchInput 0178 Layout.fillWidth: true 0179 0180 KeyNavigation.down: list 0181 KeyNavigation.right: categoryButton 0182 0183 onTextChanged: { 0184 list.positionViewAtBeginning() 0185 list.currentIndex = -1 0186 widgetExplorer.widgetsModel.searchTerm = text 0187 } 0188 0189 Component.onCompleted: if (!Kirigami.InputMethod.willShowOnActive) { forceActiveFocus() } 0190 } 0191 PC3.ToolButton { 0192 id: categoryButton 0193 text: i18nd("plasma_shell_org.kde.plasma.desktop", "All Widgets") 0194 icon.name: "view-filter" 0195 0196 KeyNavigation.down: list 0197 0198 onClicked: { 0199 categoriesDialog.model = widgetExplorer.filterModel 0200 categoriesDialog.open(0, categoryButton.height) 0201 } 0202 0203 PC3.ToolTip { 0204 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Categories") 0205 } 0206 } 0207 } 0208 } 0209 } 0210 0211 footer: PlasmaExtras.PlasmoidHeading { 0212 position: PC3.ToolBar.Footer 0213 visible: pendingUninstallTimer.applets.length > 0 0214 contentItem: PC3.Button { 0215 text: i18ndp("plasma_shell_org.kde.plasma.desktop", "Confirm Removal Of One Widget", "Confirm Removal Of %1 Widgets", pendingUninstallTimer.applets.length) 0216 onClicked: pendingUninstallTimer.uninstall() 0217 } 0218 } 0219 0220 Timer { 0221 id: setModelTimer 0222 interval: 20 0223 running: true 0224 onTriggered: list.model = widgetExplorer.widgetsModel 0225 } 0226 0227 PC3.ScrollView { 0228 anchors.fill: parent 0229 anchors.rightMargin: - main.sidePanel.margins.right 0230 0231 // hide the flickering by fading in nicely 0232 opacity: setModelTimer.running ? 0 : 1 0233 Behavior on opacity { 0234 OpacityAnimator { 0235 duration: Kirigami.Units.longDuration 0236 easing.type: Easing.InOutQuad 0237 } 0238 } 0239 0240 GridView { 0241 id: list 0242 0243 // model set delayed by Timer above 0244 0245 activeFocusOnTab: true 0246 cellWidth: Math.floor(width / 3) 0247 cellHeight: cellWidth + Kirigami.Units.gridUnit * 4 + Kirigami.Units.smallSpacing * 2 0248 0249 delegate: AppletDelegate {} 0250 highlight: PlasmaExtras.Highlight { 0251 pressed: list.currentItem && list.currentItem.pressed 0252 } 0253 highlightMoveDuration: 0 0254 //highlightResizeDuration: 0 0255 0256 //slide in to view from the left 0257 add: Transition { 0258 NumberAnimation { 0259 properties: "x" 0260 from: -list.width 0261 duration: Kirigami.Units.shortDuration 0262 } 0263 } 0264 0265 //slide out of view to the right 0266 remove: Transition { 0267 NumberAnimation { 0268 properties: "x" 0269 to: list.width 0270 duration: Kirigami.Units.shortDuration 0271 } 0272 } 0273 0274 //if we are adding other items into the view use the same animation as normal adding 0275 //this makes everything slide in together 0276 //if we make it move everything ends up weird 0277 addDisplaced: list.add 0278 0279 //moved due to filtering 0280 displaced: Transition { 0281 NumberAnimation { 0282 properties: "x,y" 0283 duration: Kirigami.Units.shortDuration 0284 } 0285 } 0286 0287 KeyNavigation.up: searchInput 0288 } 0289 } 0290 0291 PlasmaExtras.PlaceholderMessage { 0292 anchors.centerIn: parent 0293 width: parent.width - (Kirigami.Units.gridUnit * 4) 0294 iconName: "edit-none" 0295 text: searchInput.text.length > 0 ? i18nd("plasma_shell_org.kde.plasma.desktop", "No widgets matched the search terms") : i18nd("plasma_shell_org.kde.plasma.desktop", "No widgets available") 0296 visible: list.count == 0 && !setModelTimer.running 0297 } 0298 }