Warning, /plasma/plasma-desktop/desktoppackage/contents/configuration/shellcontainmentconfiguration/Delegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2021 Cyril Rossi <cyril.rossi@enioka.com> 0003 SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 2.15 0009 import QtQuick.Controls 2.4 as QQC2 0010 import QtQuick.Layouts 1.3 0011 import QtQuick.Window 2.15 0012 0013 import org.kde.kirigami 2.13 as Kirigami 0014 0015 QQC2.Control { 0016 id: delegate 0017 property Item viewPort 0018 readonly property string screenName: model.screenName 0019 readonly property int screenId: model.screenId 0020 property bool containsDrag 0021 property alias contentsLayout: contentsLayout 0022 0023 width: Math.min(Kirigami.Units.gridUnit * 25, Math.floor(viewPort.width / Math.min(repeater.count, Math.floor(viewPort.width / (Kirigami.Units.gridUnit * 12))))) 0024 0025 contentItem: ColumnLayout { 0026 id: contentsLayout 0027 width: Math.min(parent.width, Kirigami.Units.gridUnit * 15) 0028 0029 Rectangle { 0030 id: screenRect 0031 Layout.fillWidth: true 0032 Layout.preferredHeight: width / 1.6 0033 color: Kirigami.Theme.backgroundColor 0034 border.color: Kirigami.Theme.textColor 0035 Rectangle { 0036 anchors.fill: parent 0037 z: 9 0038 color: "black" 0039 opacity: delegate.containsDrag ? 0.3 : 0 0040 Behavior on opacity { 0041 OpacityAnimator { 0042 duration: Kirigami.Units.longDuration 0043 easing.type: Easing.InOutQuad 0044 } 0045 } 0046 } 0047 0048 Repeater { 0049 id: containmentRepeater 0050 model: containments 0051 0052 Rectangle { 0053 id: contRect 0054 property real homeX 0055 property real homeY 0056 property string oldState 0057 readonly property int edgeDistance: { 0058 return (state === "left" || state === "right" ? width : height) * model.edgePosition; 0059 } 0060 0061 width: moveButton.width 0062 height: moveButton.height 0063 border.color: Kirigami.Theme.textColor 0064 color: Kirigami.Theme.backgroundColor 0065 state: model.edge 0066 z: state === "floating" ? 0 : 1 0067 visible: !model.isDestroyed 0068 0069 HoverHandler { 0070 cursorShape: Qt.OpenHandCursor 0071 } 0072 DragHandler { 0073 id: dragHandler 0074 property QQC2.Control targetDelegate 0075 0076 cursorShape: Qt.ClosedHandCursor 0077 onActiveChanged: { 0078 if (active) { 0079 delegate.z = 1; 0080 } else { 0081 if (targetDelegate) { 0082 resetAnim.restart(); 0083 containmentRepeater.model.moveContainementToScreen(model.containmentId, targetDelegate.screenId) 0084 targetDelegate.containsDrag = false; 0085 targetDelegate = null; 0086 } else { 0087 resetAnim.restart(); 0088 } 0089 } 0090 } 0091 onTranslationChanged: { 0092 if (!active) { 0093 if (targetDelegate) { 0094 targetDelegate.containsDrag = false; 0095 targetDelegate = null; 0096 } 0097 return; 0098 } 0099 let pos = contRect.mapToItem(delegate.parent, dragHandler.centroid.position.x, dragHandler.centroid.position.y); 0100 let otherDelegate = delegate.parent.childAt(pos.x, pos.y); 0101 if (targetDelegate && targetDelegate !== otherDelegate) { 0102 targetDelegate.containsDrag = false; 0103 } 0104 if (!otherDelegate || otherDelegate === delegate) { 0105 targetDelegate = null; 0106 } else if (otherDelegate && otherDelegate !== delegate 0107 && otherDelegate.hasOwnProperty("screenId") 0108 && otherDelegate.hasOwnProperty("containsDrag")) { 0109 targetDelegate = otherDelegate; 0110 targetDelegate.containsDrag = true; 0111 } 0112 } 0113 } 0114 SequentialAnimation { 0115 id: resetAnim 0116 property var targetDelegatePos: dragHandler.targetDelegate 0117 ? dragHandler.targetDelegate.contentsLayout.mapToItem(delegate.contentsLayout, 0, 0) 0118 : Qt.point(0, 0) 0119 ParallelAnimation { 0120 XAnimator { 0121 target: contRect 0122 from: contRect.x 0123 to: contRect.homeX + resetAnim.targetDelegatePos.x 0124 duration: Kirigami.Units.longDuration 0125 easing.type: Easing.InOutQuad 0126 } 0127 YAnimator { 0128 target: contRect 0129 from: contRect.y 0130 to: contRect.homeY + resetAnim.targetDelegatePos.y 0131 duration: Kirigami.Units.longDuration 0132 easing.type: Easing.InOutQuad 0133 } 0134 } 0135 PropertyAction { 0136 target: delegate 0137 property: "z" 0138 value: 0 0139 } 0140 } 0141 0142 Image { 0143 id: containmentImage 0144 anchors { 0145 fill: parent 0146 margins: 1 0147 } 0148 // It needs to reload the image from disk when the file changes 0149 cache: false 0150 source: model.imageSource 0151 fillMode: model.edge == "floating" ? Image.PreserveAspectCrop : Image.PreserveAspectFit 0152 } 0153 0154 QQC2.Button { 0155 id: moveButton 0156 icon.name: "open-menu-symbolic" 0157 checked: contextMenu.visible 0158 anchors { 0159 right: parent.right 0160 top: parent.top 0161 topMargin: model.edge == "floating" 0162 ? model.panelCountAtTop * moveButton.height + Kirigami.Units.largeSpacing 0163 : 0 0164 rightMargin: model.edge == "floating" 0165 ? (moveButton.LayoutMirroring.enabled ? model.panelCountAtLeft : model.panelCountAtRight) * moveButton.height + Kirigami.Units.largeSpacing 0166 : 0 0167 } 0168 onClicked: { 0169 contextMenu.open() 0170 } 0171 0172 QQC2.Menu { 0173 id: contextMenu 0174 y: moveButton.height 0175 Repeater { 0176 model: ShellContainmentModel 0177 QQC2.MenuItem { 0178 text: edge == "floating" 0179 ? i18nd("plasma_shell_org.kde.plasma.desktop", "Swap with Desktop on Screen %1", model.screenName) 0180 : i18nd("plasma_shell_org.kde.plasma.desktop", "Move to Screen %1", model.screenName) 0181 visible: model.screenName !== delegate.screenName 0182 height: visible ? implicitHeight : 0 0183 onTriggered: { 0184 containmentRepeater.model.moveContainementToScreen(containmentId, screenId) 0185 } 0186 } 0187 } 0188 QQC2.MenuSeparator { 0189 visible: removeItem.visible 0190 } 0191 QQC2.MenuItem { 0192 id: removeItem 0193 text: contRect.state === "floating" 0194 ? i18nd("plasma_shell_org.kde.plasma.desktop", "Remove Desktop") 0195 : i18nd("plasma_shell_org.kde.plasma.desktop", "Remove Panel") 0196 icon.name: "edit-delete" 0197 onTriggered: { 0198 if (contRect.state === "floating") { 0199 ShellContainmentModel.remove(screenId); 0200 } else { 0201 containments.remove(containmentId); 0202 } 0203 } 0204 visible: contRect.state !== "floating" || !model.active 0205 } 0206 } 0207 } 0208 0209 states: [ 0210 State { 0211 name: "floating" 0212 PropertyChanges { 0213 target: contRect; 0214 width: screenRect.width 0215 height: screenRect.height 0216 color: "transparent" 0217 } 0218 }, 0219 State { 0220 name: "top" 0221 PropertyChanges { 0222 target: contRect; 0223 width: screenRect.width 0224 y: homeY 0225 homeX: 0 0226 homeY: contRect.edgeDistance 0227 } 0228 }, 0229 State { 0230 name: "right" 0231 PropertyChanges { 0232 target: contRect; 0233 x: homeX 0234 homeX: screenRect.width - contRect.width - contRect.edgeDistance; 0235 height: screenRect.height 0236 homeY: 0 0237 } 0238 }, 0239 State { 0240 name: "bottom" 0241 PropertyChanges { 0242 target: contRect; 0243 y: homeY 0244 homeX: 0 0245 homeY: screenRect.height - contRect.height - contRect.edgeDistance; 0246 width: screenRect.width 0247 } 0248 }, 0249 State { 0250 name: "left" 0251 PropertyChanges { 0252 target: contRect; 0253 height: screenRect.height 0254 x: homeX 0255 homeX: contRect.edgeDistance 0256 homeY: 0 0257 } 0258 } 0259 ] 0260 } 0261 } 0262 } 0263 QQC2.Label { 0264 Layout.fillWidth: true 0265 horizontalAlignment: Text.AlignHCenter 0266 wrapMode: Text.WordWrap 0267 text: model.isPrimary 0268 ? i18nd("plasma_shell_org.kde.plasma.desktop", "%1 (primary)", model.screenName) 0269 : model.screenName 0270 textFormat: Text.PlainText 0271 } 0272 } 0273 }