Warning, /plasma/kwin/src/plugins/tileseditor/qml/TileDelegate.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import org.kde.kwin as KWinComponents
0010 import org.kde.kwin.private.effects
0011 import org.kde.kirigami 2.20 as Kirigami
0012 import org.kde.plasma.components 3.0 as PlasmaComponents
0013 
0014 Item {
0015     id: delegate
0016     required property KWinComponents.Tile tile
0017 
0018     x: Math.round(tile.absoluteGeometryInScreen.x)
0019     y: Math.round(tile.absoluteGeometryInScreen.y)
0020     z: focus ? 1000 : 0
0021     //onZChanged: print(delegate + " "+z)
0022     width: Math.round(tile.absoluteGeometryInScreen.width)
0023     height: Math.round(tile.absoluteGeometryInScreen.height)
0024     Connections {
0025         target: tile
0026         function onTilesChanged() {
0027             if (tile.layoutDirection === KWinComponents.Tile.Floating && tile.tiles.length === 0) {
0028                 tile.layoutDirection = tile.parent.layoutDirection;
0029             }
0030         }
0031     }
0032     ResizeHandle {
0033         anchors {
0034             horizontalCenter: parent.left
0035             top: parent.top
0036             bottom: parent.bottom
0037         }
0038         tile: delegate.tile
0039         edge: Qt.LeftEdge
0040     }
0041     ResizeHandle {
0042         anchors {
0043             verticalCenter: parent.top
0044             left: parent.left
0045             right: parent.right
0046         }
0047         tile: delegate.tile
0048         edge: Qt.TopEdge
0049     }
0050     ResizeHandle {
0051         anchors {
0052             horizontalCenter: parent.right
0053             top: parent.top
0054             bottom: parent.bottom
0055         }
0056         tile: delegate.tile
0057         edge: Qt.RightEdge
0058         visible: tile.layoutDirection === KWinComponents.Tile.Floating
0059     }
0060     ResizeHandle {
0061         anchors {
0062             verticalCenter: parent.bottom
0063             left: parent.left
0064             right: parent.right
0065         }
0066         tile: delegate.tile
0067         edge: Qt.BottomEdge
0068         visible: tile.layoutDirection === KWinComponents.Tile.Floating
0069     }
0070 
0071     ResizeCorner {
0072         anchors {
0073             top: parent.top
0074             left: parent.left
0075         }
0076         tile: delegate.tile
0077         corner: Qt.TopLeftCorner
0078     }
0079     ResizeCorner {
0080         anchors {
0081             top: parent.top
0082             right: parent.right
0083         }
0084         tile: delegate.tile
0085         corner: Qt.TopRightCorner
0086     }
0087     ResizeCorner {
0088         anchors {
0089             left: parent.left
0090             bottom: parent.bottom
0091         }
0092         tile: delegate.tile
0093         corner: Qt.BottomLeftCorner
0094     }
0095     ResizeCorner {
0096         anchors {
0097             right: parent.right
0098             bottom: parent.bottom
0099         }
0100         tile: delegate.tile
0101         corner: Qt.BottomRightCorner
0102     }
0103 
0104     Item {
0105         anchors.fill: parent
0106 
0107         Rectangle {
0108             anchors {
0109                 fill: parent
0110                 margins: Kirigami.Units.smallSpacing
0111             }
0112             visible: tile.tiles.length === 0
0113             radius: 3
0114             opacity: tile.layoutDirection === KWinComponents.Tile.Floating ? 0.6 : 0.3
0115             color: tile.layoutDirection === KWinComponents.Tile.Floating ? Kirigami.Theme.backgroundColor : "transparent"
0116             border.color: Kirigami.Theme.textColor
0117             Rectangle {
0118                 anchors {
0119                     fill: parent
0120                     margins: 1
0121                 }
0122                 radius: 3
0123                 color: "transparent"
0124                 border.color: Kirigami.Theme.backgroundColor
0125             }
0126             MouseArea {
0127                 anchors.fill: parent
0128                 hoverEnabled: true
0129                 propagateComposedEvents: true
0130                 property point lastPos
0131                 onClicked: {
0132                     delegate.focus = true;
0133                     if (tile.layoutDirection !== KWinComponents.Tile.Floating) {
0134                         mouse.accepted = false;
0135                     }
0136                 }
0137                 onPressed: {
0138                     lastPos = mapToItem(null, mouse.x, mouse.y);
0139                 }
0140                 onPositionChanged: {
0141                     if (!pressed || tile.layoutDirection !== KWinComponents.Tile.Floating) {
0142                         return;
0143                     }
0144                     let pos = mapToItem(null, mouse.x, mouse.y);
0145                     let deltaPoint = Qt.point(pos.x - lastPos.x, pos.y - lastPos.y);
0146                     deltaPoint.x = Math.max(deltaPoint.x, tile.parent.absoluteGeometryInScreen.x - tile.absoluteGeometryInScreen.x);
0147                     deltaPoint.x = Math.min(deltaPoint.x, (tile.parent.absoluteGeometryInScreen.x + tile.parent.absoluteGeometryInScreen.width) - (tile.absoluteGeometryInScreen.x + tile.absoluteGeometryInScreen.width));
0148 
0149                     deltaPoint.y = Math.max(deltaPoint.y, tile.parent.absoluteGeometryInScreen.y - tile.absoluteGeometryInScreen.y);
0150                     deltaPoint.y = Math.min(deltaPoint.y, (tile.parent.absoluteGeometryInScreen.y + tile.parent.absoluteGeometryInScreen.height) - (tile.absoluteGeometryInScreen.y + tile.absoluteGeometryInScreen.height));
0151 
0152                     tile.moveByPixels(deltaPoint);
0153                     lastPos = pos;
0154                 }
0155             }
0156         }
0157         GridLayout {
0158             anchors.centerIn: parent
0159             visible: tile.tiles.length === 0
0160             readonly property bool compact: delegate.width < Kirigami.Units.gridUnit * 10 || delegate.height < splitButton.implicitHeight * visibleChildren.length + rowSpacing * visibleChildren.length + Kirigami.Units.gridUnit
0161             rows: compact ? 1 : -1
0162             columns: compact ? -1 : 1
0163             PlasmaComponents.Button {
0164                 id: splitButton
0165                 Layout.fillWidth: true
0166                 icon.name: "view-split-left-right"
0167                 text: i18nd("kwin","Split Horizontally")
0168                 display: parent.compact ? PlasmaComponents.Button.IconOnly : PlasmaComponents.Button.TextBesideIcon
0169                 onClicked: tile.split(KWinComponents.Tile.Horizontal)
0170             }
0171             PlasmaComponents.Button {
0172                 Layout.fillWidth: true
0173                 icon.name: "view-split-top-bottom"
0174                 text: i18nd("kwin","Split Vertically")
0175                 display: parent.compact ? PlasmaComponents.Button.IconOnly : PlasmaComponents.Button.TextBesideIcon
0176                 onClicked: tile.split(KWinComponents.Tile.Vertical)
0177             }
0178             PlasmaComponents.Button {
0179                 Layout.fillWidth: true
0180                 visible: tile.layoutDirection !== KWinComponents.Tile.Floating
0181                 icon.name: "window-duplicate"
0182                 text: i18nd("kwin","Add Floating Tile")
0183                 display: parent.compact ? PlasmaComponents.Button.IconOnly : PlasmaComponents.Button.TextBesideIcon
0184                 onClicked: tile.split(KWinComponents.Tile.Floating)
0185             }
0186             PlasmaComponents.Button {
0187                 id: deleteButton
0188                 visible: tile.canBeRemoved
0189                 Layout.fillWidth: true
0190                 icon.name: "edit-delete"
0191                 text: i18nd("kwin","Delete")
0192                 display: parent.compact ? PlasmaComponents.Button.IconOnly : PlasmaComponents.Button.TextBesideIcon
0193                 onClicked: {
0194                     tile.remove();
0195                 }
0196             }
0197         }
0198     }
0199     TapHandler {
0200         enabled: tile.layoutDirection === KWinComponents.Tile.Floating && tile.isLayout
0201         onTapped: effect.deactivate(effect.animationDuration);
0202     }
0203     PlasmaComponents.Button {
0204         anchors {
0205             right: parent.right
0206             bottom: parent.bottom
0207             margins: Kirigami.Units.smallSpacing
0208         }
0209         visible: tile.layoutDirection === KWinComponents.Tile.Floating && tile.isLayout
0210         icon.name: "window-duplicate"
0211         text: i18nd("kwin","Add Floating Tile")
0212         onClicked: tile.split(KWinComponents.Tile.Floating)
0213     }
0214 }