Warning, /network/kdeconnect-kde/app/qml/mousepad.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick
0008 import QtQuick.Controls
0009 import QtQuick.Layouts
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kdeconnect
0012 
0013 Kirigami.Page
0014 {
0015     id: mousepad
0016     title: i18nd("kdeconnect-app", "Remote Control")
0017     property QtObject pluginInterface
0018     property QtObject device
0019 
0020     // Otherwise swiping on the MouseArea might trigger changing the page
0021     Kirigami.ColumnView.preventStealing: true
0022 
0023     Component.onCompleted: {
0024         PointerLocker.window = applicationWindow()
0025     }
0026 
0027     ColumnLayout
0028     {
0029         anchors.fill: parent
0030 
0031         MouseArea {
0032             id: area
0033             Layout.fillWidth: true
0034             Layout.fillHeight: true
0035             property var lastPos: Qt.point(-1, -1)
0036             property var pressedPos: Qt.point(-1, -1)
0037             property var releasedPos: Qt.point(-1, -1)
0038 
0039             acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
0040 
0041             Button {
0042                 id: lockButton
0043                 anchors.centerIn: parent
0044                 text: i18n("Lock")
0045                 visible: !Kirigami.Settings.tabletMode && !PointerLocker.isLocked
0046                 onClicked: {
0047                     PointerLocker.isLocked = true
0048                     area.pressedPos = Qt.point(-1, -1);
0049                 }
0050             }
0051             Label {
0052                 anchors.centerIn: parent
0053                 visible: PointerLocker.isLocked
0054                 width: parent.width
0055 
0056                 wrapMode: Text.Wrap
0057                 horizontalAlignment: Text.AlignHCenter
0058 
0059                 text: i18n("Press %1 or the left and right mouse buttons at the same time to unlock", unlockShortcut.nativeText)
0060             }
0061 
0062             Connections {
0063                 target: PointerLocker
0064                 function onPointerMoved(delta) {
0065                     if (!PointerLocker.isLocked) {
0066                         return;
0067                     }
0068                     mousepad.pluginInterface.moveCursor(Qt.point(delta.x, delta.y));
0069                 }
0070             }
0071 
0072             // We don't want to see the lock button when using a touchscreen
0073             TapHandler {
0074                 acceptedDevices: PointerDevice.TouchScreen
0075                 onTapped: lockButton.visible = false
0076             }
0077 
0078             Shortcut {
0079                 id: unlockShortcut
0080                 sequence: "Alt+X"
0081                 onActivated: {
0082                     console.log("shortcut triggered, unlocking")
0083                     PointerLocker.isLocked = false
0084                 }
0085             }
0086 
0087             onClicked: {
0088                 var clickType = "";
0089                 var packet = {};
0090                 switch (mouse.button) {
0091                 case Qt.LeftButton:
0092                     if (PointerLocker.isLocked) // we directly send singleclick and singlehold to emulate all mouse actions inc. drag and drop
0093                         return;
0094                     if (pressedPos == releasedPos) {
0095                         clickType = "singleclick";
0096                     }
0097                     break;
0098                 case Qt.RightButton:
0099                     clickType = "rightclick";
0100                     break;
0101                 case Qt.MiddleButton:
0102                     clickType = "middleclick";
0103                     break;
0104                 default:
0105                     console.log("This click input is not handled yet!");
0106                     break;
0107                 }
0108 
0109                 if (clickType) {
0110                     packet[clickType] = true;
0111                     mousepad.pluginInterface.sendCommand(packet);
0112                 }
0113             }
0114 
0115             onPressAndHold: {
0116                 if (PointerLocker.isLocked)
0117                     return;                     // we send singlehold and singlerelease twice instead through onPressed and onReleased
0118                 var clickType = "";
0119                 var packet = {};
0120                 switch (mouse.button) {
0121                 case Qt.LeftButton:
0122                     clickType = "singlehold";
0123                     break;
0124                 default:
0125                     console.log("This click input is not handled yet!");
0126                     break;
0127                 }
0128 
0129                 if (clickType) {
0130                     packet[clickType] = true;
0131                     mousepad.pluginInterface.sendCommand(packet);
0132                 }
0133             }
0134 
0135             onPositionChanged: {
0136                 if (lastPos.x > -1) {
0137     //                 console.log("move", mouse.x, mouse.y, lastPos)
0138                     var delta = Qt.point(mouse.x-lastPos.x, mouse.y-lastPos.y);
0139 
0140                     pluginInterface.moveCursor(delta);
0141                 }
0142                 lastPos = Qt.point(mouse.x, mouse.y);
0143             }
0144 
0145             Keys.onPressed: {
0146                 if (event.key == Qt.Key_X) {
0147                     PointerLocker.isLocked = false
0148                     event.accepted = true;
0149                 }
0150             }
0151             onPressed: {
0152                 if (PointerLocker.isLocked) {
0153                     if (pressedButtons === (Qt.LeftButton | Qt.RightButton)) {
0154                         PointerLocker.isLocked = false
0155                     }
0156                     var pressType = "";
0157                     var packet = {};
0158                     switch (mouse.buttons) {
0159                     case Qt.LeftButton:
0160                         pressType = "singlehold";
0161                         break;
0162                     default:
0163                         console.log("This click input is not handled yet!");
0164                         break;
0165                     }
0166                     if (pressType) {
0167                         packet[pressType] = true;
0168                         mousepad.pluginInterface.sendCommand(packet);
0169                     }
0170                 } else {
0171                     pressedPos = Qt.point(mouse.x, mouse.y);
0172                 }
0173             }
0174 
0175             onWheel: {
0176                 var packet = {};
0177                 packet["scroll"] = true;
0178                 packet["dy"] = wheel.angleDelta.y;
0179                 packet["dx"] = wheel.angleDelta.x;
0180                 mousepad.pluginInterface.sendCommand(packet);
0181             }
0182 
0183             onReleased: {
0184                 if (!PointerLocker.isLocked) {
0185                     lastPos = Qt.point(-1,-1);
0186                     releasedPos = Qt.point(mouse.x, mouse.y);
0187                 }
0188                 mousepad.pluginInterface.sendCommand({"singlerelease" : true});
0189             }
0190         }
0191 
0192         RemoteKeyboard {
0193             device: mousepad.device
0194             Layout.fillWidth: true
0195             visible: remoteState
0196             focus: !lockButton.visible
0197         }
0198 
0199         RowLayout {
0200             Layout.fillWidth: true
0201 
0202             Button {
0203                 Layout.fillWidth: true
0204                 icon.name: "input-mouse-click-left"
0205                 onClicked: mousepad.pluginInterface.sendCommand({"singleclick": true});
0206             }
0207             Button {
0208                 Layout.fillWidth: true
0209                 icon.name: "input-mouse-click-middle"
0210                 onClicked: mousepad.pluginInterface.sendCommand({"middleclick": true});
0211             }
0212             Button {
0213                 Layout.fillWidth: true
0214                 icon.name: "input-mouse-click-right"
0215                 onClicked: mousepad.pluginInterface.sendCommand({"rightclick": true});
0216             }
0217         }
0218     }
0219 }