Warning, /plasma/kwin/src/plugins/tileseditor/qml/main.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 Qt5Compat.GraphicalEffects
0009 import QtQuick.Layouts
0010 import org.kde.kwin as KWinComponents
0011 import org.kde.kwin.private.effects
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.ksvg 1.0 as KSvg
0014 import org.kde.plasma.components 3.0 as PlasmaComponents
0015 import org.kde.kitemmodels as KitemModels
0016 
0017 FocusScope {
0018     id: root
0019     focus: true
0020 
0021     Keys.onPressed: {
0022         switch(event.key) {
0023         case Qt.Key_Escape:
0024             root.active = false;
0025             effect.deactivate(effect.animationDuration);
0026             break;
0027         case Qt.Key_L:
0028             if (event.modifiers == Qt.AltModifier) {
0029                 loadLayoutDialog.open();
0030             }
0031             break;
0032         default:
0033             break;
0034         }
0035     }
0036 
0037     required property QtObject effect
0038     required property QtObject targetScreen
0039 
0040     property bool active: false
0041 
0042     Component.onCompleted: {
0043         root.active = true;
0044     }
0045 
0046     function stop() {
0047         active = false;
0048     }
0049 
0050     MouseArea {
0051         anchors.fill: parent
0052         onClicked: effect.deactivate(effect.animationDuration);
0053     }
0054 
0055     Item {
0056         id: blurredWindows
0057         anchors.fill: parent
0058 
0059         Repeater {
0060             model: KWinComponents.WindowFilterModel {
0061                 activity: KWinComponents.Workspace.currentActivity
0062                 desktop: KWinComponents.Workspace.currentDesktop
0063                 screenName: targetScreen.name
0064                 windowModel: KWinComponents.WindowModel {}
0065             }
0066 
0067             KWinComponents.WindowThumbnail {
0068                 wId: model.window.internalId
0069                 x: model.window.x - targetScreen.geometry.x
0070                 y: model.window.y - targetScreen.geometry.y
0071                 width: model.window.width
0072                 height: model.window.height
0073                 z: model.window.stackingOrder
0074                 visible: !model.window.minimized
0075             }
0076         }
0077         property real blurRadius: root.active ? 64 : 0
0078 
0079         layer.enabled: true
0080         layer.effect: FastBlur {
0081             radius: blurredWindows.blurRadius
0082             Behavior on radius {
0083                 NumberAnimation {
0084                     duration: effect.animationDuration
0085                     easing.type: Easing.OutCubic
0086                 }
0087             }
0088         }
0089     }
0090 
0091     Rectangle {
0092         anchors.fill: parent
0093         color: Kirigami.Theme.backgroundColor
0094         opacity: root.active ? 0.4 : 0
0095         Behavior on opacity {
0096             OpacityAnimator {
0097                 duration: effect.animationDuration
0098                 easing.type: Easing.OutCubic
0099             }
0100         }
0101     }
0102 
0103     TileDelegate {
0104         tile: KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile
0105         visible: tilesRepeater.count === 0 || tile.layoutDirection === KWinComponents.Tile.Floating
0106     }
0107 
0108     Item {
0109         anchors.fill: parent
0110         opacity: root.active ? 1 : 0
0111         z: 1
0112         Behavior on opacity {
0113             OpacityAnimator {
0114                 duration: effect.animationDuration
0115                 easing.type: Easing.OutCubic
0116             }
0117         }
0118 
0119         Repeater {
0120             id: tilesRepeater
0121             model: KitemModels.KDescendantsProxyModel {
0122                 model: KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).model
0123             }
0124             delegate: TileDelegate {}
0125         }
0126     }
0127 
0128     PlasmaComponents.Control {
0129         z: 2
0130         anchors.right: parent.right
0131         y: root.active ? 0 : -height
0132         leftPadding: background.margins.left
0133         topPadding: Kirigami.Units.smallSpacing
0134         rightPadding: Kirigami.Units.smallSpacing
0135         bottomPadding: background.margins.bottom
0136         opacity: root.active
0137         Behavior on opacity {
0138             OpacityAnimator {
0139                 duration: effect.animationDuration
0140                 easing.type: Easing.OutCubic
0141             }
0142         }
0143         Behavior on y {
0144             YAnimator {
0145                 duration: effect.animationDuration
0146                 easing.type: Easing.OutCubic
0147             }
0148         }
0149         contentItem: RowLayout {
0150             PlasmaComponents.Label {
0151                 text: i18nd("kwin","Padding:")
0152             }
0153             PlasmaComponents.SpinBox {
0154                 from: 0
0155                 to: Kirigami.Units.gridUnit * 2
0156                 value: KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile.padding
0157                 onValueModified: KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile.padding = value
0158             }
0159             PlasmaComponents.Button {
0160                 icon.name: "document-open"
0161                 text: i18nd("kwin","Load Layout...")
0162                 onClicked: loadLayoutDialog.open()
0163                 // This mouse area is for fitts law
0164                 MouseArea {
0165                     anchors {
0166                         fill: parent
0167                         margins: -Kirigami.Units.smallSpacing
0168                     }
0169                     z: -1
0170                     onClicked: parent.clicked()
0171                 }
0172             }
0173         }
0174         background: KSvg.FrameSvgItem {
0175             imagePath: "widgets/background"
0176             enabledBorders: KSvg.FrameSvg.LeftBorder | KSvg.FrameSvg.BottomBorder
0177         }
0178     }
0179     PlasmaComponents.Popup {
0180         id: loadLayoutDialog
0181         x: Math.round(parent.width / 2 - width / 2)
0182         y: Math.round(parent.height / 2 - height / 2)
0183         width: Math.min(root.width - Kirigami.Units.gridUnit * 4, implicitWidth)
0184         height: Math.round(implicitHeight * (width / implicitWidth))
0185 
0186         modal: true
0187         dim: true
0188         onOpened: forceActiveFocus()
0189         onClosed: root.forceActiveFocus()
0190         component LayoutButton: PlasmaComponents.AbstractButton {
0191             id: button
0192             Layout.fillWidth: true
0193             Layout.fillHeight: true
0194             property alias image: svgItem.elementId
0195             contentItem: KSvg.SvgItem {
0196                 id: svgItem
0197                  imagePath: Qt.resolvedUrl("layouts.svg")
0198                 implicitWidth: naturalSize.width
0199                 implicitHeight: naturalSize.height
0200             }
0201             background: KSvg.FrameSvgItem {
0202                 imagePath: "widgets/viewitem"
0203                 prefix: "hover"
0204                 opacity: parent.hovered || parent.focus
0205             }
0206             onClicked: loadLayoutDialog.close()
0207             Keys.onPressed: {
0208                 switch(event.key) {
0209                 case Qt.Key_Escape:
0210                     loadLayoutDialog.close();
0211                     break;
0212                 case Qt.Key_Enter:
0213                 case Qt.Key_Return:
0214                     button.clicked();
0215                     break;
0216                 default:
0217                     break;
0218                 }
0219             }
0220         }
0221         contentItem: ColumnLayout {
0222             RowLayout {
0223                 Layout.fillWidth: true
0224                 Layout.fillHeight: true
0225                 LayoutButton {
0226                     id: apply2Columns
0227                     focus: true
0228                     image: "2columns"
0229                     KeyNavigation.right: apply3Columns
0230                     onClicked: {
0231                         const rootTile = KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile;
0232                         while (rootTile.tiles.length > 0) {
0233                             rootTile.tiles[0].remove();
0234                         }
0235                         rootTile.split(KWinComponents.Tile.Horizontal)
0236                         rootTile.tiles[0].relativeGeometry = Qt.rect(0, 0, 0.5, 1);
0237                     }
0238                 }
0239                 LayoutButton {
0240                     id: apply3Columns
0241                     image: "3columns"
0242                     KeyNavigation.right: apply2ColumnsVerticalSplit
0243                     KeyNavigation.left: apply2Columns
0244                     onClicked: {
0245                         const rootTile = KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile;
0246                         while (rootTile.tiles.length > 0) {
0247                             rootTile.tiles[0].remove();
0248                         }
0249                         rootTile.split(KWinComponents.Tile.Horizontal)
0250                         rootTile.tiles[0].split(KWinComponents.Tile.Horizontal)
0251                         rootTile.tiles[1].relativeGeometry = Qt.rect(0.25, 0, 0.5, 1);
0252                     }
0253                 }
0254                 LayoutButton {
0255                     id: apply2ColumnsVerticalSplit
0256                     image: "2columnsVerticalSplit"
0257                     KeyNavigation.left: apply3Columns
0258                     onClicked: {
0259                         const rootTile = KWinComponents.Workspace.tilingForScreen(root.targetScreen.name).rootTile;
0260                         while (rootTile.tiles.length > 0) {
0261                             rootTile.tiles[0].remove();
0262                         }
0263                         rootTile.split(KWinComponents.Tile.Horizontal)
0264                         rootTile.tiles[0].relativeGeometry = Qt.rect(0, 0, 0.4, 1);
0265                         rootTile.tiles[0].split(KWinComponents.Tile.Vertical)
0266                     }
0267                 }
0268             }
0269             PlasmaComponents.Button {
0270                 Layout.alignment: Qt.AlignRight
0271                 text: i18nd("kwin","Close")
0272                 onClicked: loadLayoutDialog.close()
0273             }
0274         }
0275     }
0276 }