Warning, /plasma/plasma-desktop/applets/kickoff/package/contents/ui/KickoffDropArea.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  */
0005 
0006 import QtQuick 2.15
0007 import QtQml 2.15
0008 import org.kde.plasma.core as PlasmaCore
0009 import org.kde.plasma.plasmoid 2.0
0010 
0011 DropArea {
0012     id: root
0013     required property Flickable targetView
0014     readonly property bool enableAutoScroll: targetView.height < targetView.contentHeight
0015     property real scrollUpMargin: 0
0016     property real scrollDownMargin: 0
0017     enabled: Plasmoid.immutability !== PlasmaCore.Types.SystemImmutable
0018     onPositionChanged: if (drag.source instanceof KickoffGridDelegate || drag.source instanceof KickoffListDelegate) {
0019         const source = drag.source
0020         const view = drag.source.view
0021         if (source.view === root.targetView && !view.move.running && !view.moveDisplaced.running) {
0022             const pos = mapToItem(view.contentItem, drag.x, drag.y)
0023             const targetIndex = view.indexAt(pos.x, pos.y)
0024             if (targetIndex >= 0 && targetIndex !== source.index) {
0025                 view.model.moveRow(source.index, targetIndex)
0026                 // itemIndex changes directly after moving,
0027                 // we can just set the currentIndex to it then.
0028                 view.currentIndex = source.index
0029             }
0030         }
0031     }
0032 
0033     function moveRow(targetIndex) {
0034         if (targetIndex < 0 || targetIndex >= targetView.count) {
0035             return;
0036         }
0037 
0038         targetView.model.moveRow(targetView.currentIndex, targetIndex);
0039         targetView.currentIndex = targetIndex;
0040     }
0041 
0042     Shortcut {
0043         enabled: (targetView instanceof GridView && targetView.currentIndex >= targetView.columns)
0044               || (targetView instanceof ListView && targetView.currentIndex > 0)
0045         sequence: "Ctrl+Shift+Up"
0046         onActivated: moveRow(targetView.currentIndex - (targetView instanceof GridView ? targetView.columns : 1))
0047     }
0048 
0049     Shortcut {
0050         enabled: (targetView instanceof GridView && targetView.currentIndex < targetView.count - targetView.columns)
0051               || (targetView instanceof ListView && targetView.currentIndex + 1 < targetView.count)
0052         sequence: "Ctrl+Shift+Down"
0053         onActivated: moveRow(targetView.currentIndex + (targetView instanceof GridView ? targetView.columns : 1))
0054     }
0055 
0056     Shortcut {
0057         enabled: targetView instanceof GridView && targetView.currentIndex % targetView.columns > 0
0058         sequence: "Ctrl+Shift+Left"
0059         onActivated: moveRow(targetView.currentIndex - 1)
0060     }
0061 
0062     Shortcut {
0063         enabled: targetView instanceof GridView && targetView.currentIndex % targetView.columns !== targetView.columns - 1
0064         sequence: "Ctrl+Shift+Right"
0065         onActivated: moveRow(targetView.currentIndex + 1)
0066     }
0067 
0068     SmoothedAnimation {
0069         target: root.targetView
0070         property: "contentY"
0071         to: 0
0072         velocity: 200
0073         running: root.enableAutoScroll && root.containsDrag && root.drag.y <= root.scrollUpMargin
0074     }
0075     SmoothedAnimation {
0076         target: root.targetView
0077         property: "contentY"
0078         to: root.targetView.contentHeight - root.targetView.height
0079         velocity: 200
0080         running: root.enableAutoScroll && root.containsDrag && root.drag.y >= root.height - root.scrollDownMargin
0081     }
0082 }
0083