Warning, /plasma/latte-dock/shell/package/contents/views/WidgetExplorer.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 2.7 0009 import QtQuick.Controls 2.5 as QQC2 0010 0011 import org.kde.plasma.components 2.0 as PC2 // for DialogStatus, ModelCOntextMenu, and Highlight 0012 import org.kde.plasma.components 3.0 as PC3 0013 import org.kde.plasma.core 2.0 as PlasmaCore 0014 import org.kde.plasma.extras 2.0 as PlasmaExtras 0015 import org.kde.kquickcontrolsaddons 2.0 0016 import org.kde.kwindowsystem 1.0 0017 import org.kde.kirigami 2.19 as Kirigami 0018 0019 import QtQuick.Window 2.1 0020 import QtQuick.Layouts 1.1 0021 0022 import org.kde.plasma.private.shell 2.0 as PlasmaShell 0023 0024 PC3.Page { 0025 id: main 0026 width: Math.max(heading.paintedWidth, PlasmaCore.Units.iconSizes.enormous * 3 + PlasmaCore.Units.smallSpacing * 4 + PlasmaCore.Units.gridUnit * 2) 0027 // height: 800//Screen.height 0028 opacity: draggingWidget ? 0.3 : 1 0029 visible: viewConfig.visible 0030 0031 //property QtObject containment 0032 0033 property PlasmaCore.Dialog sidePanel 0034 0035 //external drop events can cause a raise event causing us to lose focus and 0036 //therefore get deleted whilst we are still in a drag exec() 0037 //this is a clue to the owning dialog that hideOnWindowDeactivate should be deleted 0038 //See https://bugs.kde.org/show_bug.cgi?id=332733 0039 property bool preventWindowHide: draggingWidget || categoriesDialog.status !== PC2.DialogStatus.Closed 0040 || getWidgetsDialog.status !== PC2.DialogStatus.Closed 0041 0042 property bool outputOnly: draggingWidget 0043 0044 property Item categoryButton 0045 0046 property bool draggingWidget: false 0047 0048 property QtObject widgetExplorer: widgetExplorerLoader.active ? widgetExplorerLoader.item : null 0049 0050 signal closed(); 0051 0052 onClosed: { 0053 if (main.preventWindowHide) { 0054 return; 0055 } 0056 0057 viewConfig.hideConfigWindow(); 0058 } 0059 0060 onVisibleChanged: { 0061 if (!visible) { 0062 kwindowsystem.showingDesktop = false; 0063 } 0064 } 0065 0066 onWidgetExplorerChanged: { 0067 if (widgetExplorer) { 0068 setModelTimer.start(); 0069 } 0070 } 0071 0072 Component.onDestruction: { 0073 if (pendingUninstallTimer.running) { 0074 // we're not being destroyed so at least reset the filters 0075 widgetExplorer.widgetsModel.filterQuery = "" 0076 widgetExplorer.widgetsModel.filterType = "" 0077 widgetExplorer.widgetsModel.searchTerm = "" 0078 } 0079 } 0080 0081 function addCurrentApplet() { 0082 var pluginName = list.currentItem ? list.currentItem.pluginName : "" 0083 if (pluginName) { 0084 widgetExplorer.addApplet(pluginName); 0085 latteView.extendedInterface.appletCreated(pluginName); 0086 } 0087 } 0088 0089 KWindowSystem { 0090 id: kwindowsystem 0091 } 0092 0093 QQC2.Action { 0094 shortcut: "Escape" 0095 onTriggered: { 0096 if (searchInput.length > 0) { 0097 searchInput.text = "" 0098 } else { 0099 main.closed(); 0100 } 0101 } 0102 } 0103 0104 QQC2.Action { 0105 shortcut: "Enter" 0106 onTriggered: addCurrentApplet() 0107 } 0108 QQC2.Action { 0109 shortcut: "Return" 0110 onTriggered: addCurrentApplet() 0111 } 0112 0113 PlasmaCore.FrameSvgItem{ 0114 id: backgroundFrameSvgItem 0115 anchors.top: parent.top 0116 anchors.topMargin: -headerMargin 0117 width: parent.width 0118 height: parent.height + headerMargin 0119 imagePath: "dialogs/background" 0120 enabledBorders: viewConfig.enabledBorders 0121 0122 readonly property int headerMargin: header.height + 50 /*magical number in order to fill the top gap*/ 0123 0124 onEnabledBordersChanged: viewConfig.updateEffects() 0125 Component.onCompleted: viewConfig.updateEffects() 0126 } 0127 0128 Loader { 0129 id: widgetExplorerLoader 0130 active: main.visible 0131 sourceComponent: PlasmaShell.WidgetExplorer { 0132 //id:widgetExplorer 0133 //view: desktop 0134 containment: containmentFromView 0135 onShouldClose: main.closed(); 0136 } 0137 } 0138 0139 PC2.ModelContextMenu { 0140 id: categoriesDialog 0141 visualParent: categoryButton 0142 // model set on first invocation 0143 0144 onClicked: { 0145 list.contentX = 0 0146 list.contentY = 0 0147 categoryButton.text = (model.filterData ? model.display : i18nd("plasma_shell_org.kde.plasma.desktop", "All Widgets")) 0148 widgetExplorer.widgetsModel.filterQuery = model.filterData 0149 widgetExplorer.widgetsModel.filterType = model.filterType 0150 } 0151 } 0152 0153 PC2.ModelContextMenu { 0154 id: getWidgetsDialog 0155 visualParent: getWidgetsButton 0156 placement: PlasmaCore.Types.TopPosedLeftAlignedPopup 0157 // model set on first invocation 0158 onClicked: model.trigger() 0159 } 0160 /* 0161 PlasmaCore.Dialog { 0162 id: tooltipDialog 0163 property Item appletDelegate 0164 location: PlasmaCore.Types.RightEdge //actually we want this to be the opposite location of the explorer itself 0165 type: PlasmaCore.Dialog.Tooltip 0166 flags:Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint 0167 onAppletDelegateChanged: { 0168 if (!appletDelegate) { 0169 toolTipHideTimer.restart() 0170 toolTipShowTimer.running = false 0171 } else if (tooltipDialog.visible) { 0172 tooltipDialog.visualParent = appletDelegate 0173 } else { 0174 tooltipDialog.visualParent = appletDelegate 0175 toolTipShowTimer.restart() 0176 toolTipHideTimer.running = false 0177 } 0178 } 0179 mainItem: Tooltip { id: tooltipWidget } 0180 Behavior on y { 0181 NumberAnimation { duration: PlasmaCore.Units.longDuration } 0182 } 0183 } 0184 Timer { 0185 id: toolTipShowTimer 0186 interval: 500 0187 repeat: false 0188 onTriggered: { 0189 tooltipDialog.visible = true 0190 } 0191 } 0192 Timer { 0193 id: toolTipHideTimer 0194 interval: 1000 0195 repeat: false 0196 onTriggered: tooltipDialog.visible = false 0197 } 0198 */ 0199 0200 0201 header: PlasmaExtras.PlasmoidHeading { 0202 ColumnLayout { 0203 id: header 0204 anchors.fill: parent 0205 0206 RowLayout { 0207 PlasmaExtras.Heading { 0208 id: heading 0209 level: 1 0210 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Widgets") 0211 elide: Text.ElideRight 0212 0213 Layout.fillWidth: true 0214 } 0215 PC3.ToolButton { 0216 id: getWidgetsButton 0217 icon.name: "get-hot-new-stuff" 0218 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Get New Widgets…") 0219 onClicked: { 0220 getWidgetsDialog.model = widgetExplorer.widgetsMenuActions 0221 getWidgetsDialog.openRelative() 0222 } 0223 } 0224 PC3.ToolButton { 0225 id: closeButton 0226 icon.name: "window-close" 0227 onClicked: main.closed() 0228 } 0229 } 0230 0231 RowLayout { 0232 PC3.TextField { 0233 id: searchInput 0234 Layout.fillWidth: true 0235 clearButtonShown: true 0236 placeholderText: i18nd("plasma_shell_org.kde.plasma.desktop", "Search…") 0237 0238 inputMethodHints: Qt.ImhNoPredictiveText 0239 0240 onTextChanged: { 0241 list.positionViewAtBeginning() 0242 list.currentIndex = -1 0243 widgetExplorer.widgetsModel.searchTerm = text 0244 } 0245 0246 Component.onCompleted: if (Kirigami.InputMethod && !Kirigami.InputMethod.willShowOnActive) { forceActiveFocus() } 0247 } 0248 PC3.ToolButton { 0249 id: categoryButton 0250 text: i18nd("plasma_shell_org.kde.plasma.desktop", "All Widgets") 0251 icon.name: "view-filter" 0252 onClicked: { 0253 categoriesDialog.model = widgetExplorer.filterModel 0254 categoriesDialog.open(0, categoryButton.height) 0255 } 0256 0257 PC3.ToolTip { 0258 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Categories") 0259 } 0260 } 0261 } 0262 } 0263 } 0264 0265 Timer { 0266 id: setModelTimer 0267 interval: 20 0268 running: true 0269 onTriggered: { 0270 if (widgetExplorer) { 0271 list.model = widgetExplorer.widgetsModel 0272 } 0273 } 0274 } 0275 0276 PC3.ScrollView { 0277 anchors.fill: parent 0278 //anchors.rightMargin: - main.sidePanel.margins.right 0279 0280 // HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890 0281 PC3.ScrollBar.horizontal.policy: PC3.ScrollBar.AlwaysOff 0282 0283 // hide the flickering by fading in nicely 0284 opacity: setModelTimer.running ? 0 : 1 0285 Behavior on opacity { 0286 OpacityAnimator { 0287 duration: PlasmaCore.Units.longDuration 0288 easing.type: Easing.InOutQuad 0289 } 0290 } 0291 0292 GridView { 0293 id: list 0294 0295 // model set delayed by Timer above 0296 0297 activeFocusOnTab: true 0298 keyNavigationWraps: true 0299 cellWidth: Math.floor(width / 3) 0300 cellHeight: cellWidth + PlasmaCore.Units.gridUnit * 4 + PlasmaCore.Units.smallSpacing * 2 0301 0302 delegate: AppletDelegate {} 0303 highlight: PC2.Highlight {} 0304 highlightMoveDuration: 0 0305 //highlightResizeDuration: 0 0306 0307 //slide in to view from the left 0308 add: Transition { 0309 NumberAnimation { 0310 properties: "x" 0311 from: -list.width 0312 duration: PlasmaCore.Units.shortDuration 0313 } 0314 } 0315 0316 //slide out of view to the right 0317 remove: Transition { 0318 NumberAnimation { 0319 properties: "x" 0320 to: list.width 0321 duration: PlasmaCore.Units.shortDuration 0322 } 0323 } 0324 0325 //if we are adding other items into the view use the same animation as normal adding 0326 //this makes everything slide in together 0327 //if we make it move everything ends up weird 0328 addDisplaced: list.add 0329 0330 //moved due to filtering 0331 displaced: Transition { 0332 NumberAnimation { 0333 properties: "x,y" 0334 duration: PlasmaCore.Units.shortDuration 0335 } 0336 } 0337 } 0338 } 0339 0340 PlasmaExtras.PlaceholderMessage { 0341 anchors.centerIn: parent 0342 width: parent.width - (PlasmaCore.Units.largeSpacing * 4) 0343 text: searchInput.text.length > 0 ? i18n("No widgets matched the search terms") : i18n("No widgets available") 0344 visible: list.count == 0 0345 } 0346 0347 //! Bindings 0348 Binding{ 0349 target: viewConfig 0350 property: "hideOnWindowDeactivate" 0351 value: !main.preventWindowHide 0352 } 0353 0354 //! Timers 0355 Timer { 0356 id: pendingUninstallTimer 0357 // keeps track of the applets the user wants to uninstall 0358 property var applets: [] 0359 0360 interval: 200 0361 onTriggered: { 0362 for (var i = 0, length = applets.length; i < length; ++i) { 0363 widgetExplorer.uninstall(applets[i]) 0364 } 0365 applets = [] 0366 0367 /*if (sidePanelStack.state !== "widgetExplorer" && widgetExplorer) { 0368 widgetExplorer.destroy() 0369 widgetExplorer = null 0370 }*/ 0371 } 0372 } 0373 }