2015-07-22 02:19:29 +01:00
|
|
|
/*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2015 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2015-07-22 02:19:29 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2015-07-22 02:19:29 +01:00
|
|
|
*/
|
|
|
|
|
2021-07-23 19:28:22 +01:00
|
|
|
import QtQuick 2.15
|
2018-06-08 00:58:50 +01:00
|
|
|
import QtQuick.Controls 2.2
|
2015-07-22 11:05:16 +01:00
|
|
|
import QtQuick.Layouts 1.1
|
2020-06-16 16:59:36 +01:00
|
|
|
import org.kde.kirigami 2.7 as Kirigami
|
2018-11-08 01:21:49 +00:00
|
|
|
import org.kde.kdeconnect 1.0
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
Kirigami.Page
|
2015-07-22 02:19:29 +01:00
|
|
|
{
|
|
|
|
id: mousepad
|
2019-12-21 07:59:36 +00:00
|
|
|
title: i18nd("kdeconnect-app", "Remote Control")
|
2016-08-21 12:05:43 +01:00
|
|
|
property QtObject pluginInterface
|
2018-11-08 01:21:49 +00:00
|
|
|
property QtObject device
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2020-06-16 16:59:36 +01:00
|
|
|
// Otherwise swiping on the MouseArea might trigger changing the page
|
|
|
|
Kirigami.ColumnView.preventStealing: true
|
|
|
|
|
2021-07-23 19:28:22 +01:00
|
|
|
Component.onCompleted: {
|
|
|
|
PointerLocker.window = applicationWindow()
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
ColumnLayout
|
|
|
|
{
|
|
|
|
anchors.fill: parent
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
MouseArea {
|
|
|
|
id: area
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
property var lastPos: Qt.point(-1, -1)
|
2021-07-15 21:19:49 +01:00
|
|
|
property var pressedPos: Qt.point(-1, -1)
|
|
|
|
property var releasedPos: Qt.point(-1, -1)
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2021-07-13 16:47:29 +01:00
|
|
|
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
|
|
|
|
2021-07-23 19:28:22 +01:00
|
|
|
Button {
|
|
|
|
id: lockButton
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text: i18n("Lock")
|
|
|
|
visible: !Kirigami.Settings.tabletMode && !PointerLocker.isLocked
|
|
|
|
onClicked: {
|
|
|
|
PointerLocker.isLocked = true
|
|
|
|
area.pressedPos = Qt.point(-1, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Label {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: PointerLocker.isLocked
|
2021-08-04 18:49:32 +01:00
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
2023-05-11 23:43:42 +01:00
|
|
|
text: i18n("Press %1 or the left and right mouse buttons at the same time to unlock", unlockShortcut.nativeText)
|
2021-07-23 19:28:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: PointerLocker
|
2023-05-11 22:50:42 +01:00
|
|
|
function onPointerMoved(delta) {
|
2022-09-20 23:14:37 +01:00
|
|
|
if (!PointerLocker.isLocked) {
|
2021-07-23 19:28:22 +01:00
|
|
|
return;
|
2022-09-20 23:14:37 +01:00
|
|
|
}
|
2021-07-23 19:28:22 +01:00
|
|
|
mousepad.pluginInterface.moveCursor(Qt.point(delta.x, delta.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to see the lock button when using a touchscreen
|
|
|
|
TapHandler {
|
|
|
|
acceptedDevices: PointerDevice.TouchScreen
|
|
|
|
onTapped: lockButton.visible = false
|
|
|
|
}
|
|
|
|
|
2023-05-11 23:43:42 +01:00
|
|
|
Shortcut {
|
|
|
|
id: unlockShortcut
|
|
|
|
sequence: "Alt+X"
|
|
|
|
onActivated: {
|
|
|
|
console.log("shortcut triggered, unlocking")
|
|
|
|
PointerLocker.isLocked = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 16:47:29 +01:00
|
|
|
onClicked: {
|
|
|
|
var clickType = "";
|
|
|
|
var packet = {};
|
|
|
|
switch (mouse.button) {
|
|
|
|
case Qt.LeftButton:
|
2021-08-04 18:49:32 +01:00
|
|
|
if (PointerLocker.isLocked) // we directly send singleclick and singlehold to emulate all mouse actions inc. drag and drop
|
|
|
|
return;
|
2021-07-15 21:19:49 +01:00
|
|
|
if (pressedPos == releasedPos) {
|
|
|
|
clickType = "singleclick";
|
|
|
|
}
|
2021-07-13 16:47:29 +01:00
|
|
|
break;
|
|
|
|
case Qt.RightButton:
|
|
|
|
clickType = "rightclick";
|
|
|
|
break;
|
|
|
|
case Qt.MiddleButton:
|
|
|
|
clickType = "middleclick";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("This click input is not handled yet!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clickType) {
|
|
|
|
packet[clickType] = true;
|
|
|
|
mousepad.pluginInterface.sendCommand(packet);
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2021-08-04 18:49:32 +01:00
|
|
|
onPressAndHold: {
|
|
|
|
if (PointerLocker.isLocked)
|
|
|
|
return; // we send singlehold and singlerelease twice instead through onPressed and onReleased
|
2021-07-15 21:19:49 +01:00
|
|
|
var clickType = "";
|
|
|
|
var packet = {};
|
|
|
|
switch (mouse.button) {
|
|
|
|
case Qt.LeftButton:
|
|
|
|
clickType = "singlehold";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("This click input is not handled yet!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clickType) {
|
|
|
|
packet[clickType] = true;
|
|
|
|
mousepad.pluginInterface.sendCommand(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
onPositionChanged: {
|
|
|
|
if (lastPos.x > -1) {
|
|
|
|
// console.log("move", mouse.x, mouse.y, lastPos)
|
|
|
|
var delta = Qt.point(mouse.x-lastPos.x, mouse.y-lastPos.y);
|
2015-07-22 02:19:29 +01:00
|
|
|
|
2016-08-21 12:05:43 +01:00
|
|
|
pluginInterface.moveCursor(delta);
|
2016-06-05 21:42:19 +01:00
|
|
|
}
|
|
|
|
lastPos = Qt.point(mouse.x, mouse.y);
|
|
|
|
}
|
2021-07-13 16:47:29 +01:00
|
|
|
|
2021-07-23 19:28:22 +01:00
|
|
|
Keys.onPressed: {
|
|
|
|
if (event.key == Qt.Key_X) {
|
|
|
|
PointerLocker.isLocked = false
|
|
|
|
event.accepted = true;
|
|
|
|
}
|
|
|
|
}
|
2021-07-15 21:19:49 +01:00
|
|
|
onPressed: {
|
2021-07-23 19:28:22 +01:00
|
|
|
if (PointerLocker.isLocked) {
|
|
|
|
if (pressedButtons === (Qt.LeftButton | Qt.RightButton)) {
|
|
|
|
PointerLocker.isLocked = false
|
|
|
|
}
|
2021-08-04 18:49:32 +01:00
|
|
|
var pressType = "";
|
|
|
|
var packet = {};
|
|
|
|
switch (mouse.buttons) {
|
|
|
|
case Qt.LeftButton:
|
|
|
|
pressType = "singlehold";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log("This click input is not handled yet!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pressType) {
|
|
|
|
packet[pressType] = true;
|
|
|
|
mousepad.pluginInterface.sendCommand(packet);
|
|
|
|
}
|
2021-07-23 19:28:22 +01:00
|
|
|
} else {
|
|
|
|
pressedPos = Qt.point(mouse.x, mouse.y);
|
|
|
|
}
|
2021-07-15 21:19:49 +01:00
|
|
|
}
|
|
|
|
|
2021-07-13 16:47:29 +01:00
|
|
|
onWheel: {
|
|
|
|
var packet = {};
|
|
|
|
packet["scroll"] = true;
|
|
|
|
packet["dy"] = wheel.angleDelta.y;
|
|
|
|
packet["dx"] = wheel.angleDelta.x;
|
|
|
|
mousepad.pluginInterface.sendCommand(packet);
|
|
|
|
}
|
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
onReleased: {
|
2021-08-04 18:49:32 +01:00
|
|
|
if (!PointerLocker.isLocked) {
|
|
|
|
lastPos = Qt.point(-1,-1);
|
|
|
|
releasedPos = Qt.point(mouse.x, mouse.y);
|
|
|
|
}
|
|
|
|
mousepad.pluginInterface.sendCommand({"singlerelease" : true});
|
2016-06-05 21:42:19 +01:00
|
|
|
}
|
2015-07-22 02:19:29 +01:00
|
|
|
}
|
2018-11-08 01:21:49 +00:00
|
|
|
|
|
|
|
RemoteKeyboard {
|
|
|
|
device: mousepad.device
|
|
|
|
Layout.fillWidth: true
|
|
|
|
visible: remoteState
|
2021-08-04 18:49:32 +01:00
|
|
|
focus: !lockButton.visible
|
2018-11-08 01:21:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 21:42:19 +01:00
|
|
|
RowLayout {
|
2015-07-22 02:19:29 +01:00
|
|
|
Layout.fillWidth: true
|
2016-06-05 21:42:19 +01:00
|
|
|
|
|
|
|
Button {
|
|
|
|
Layout.fillWidth: true
|
2018-11-22 00:26:17 +00:00
|
|
|
icon.name: "input-mouse-click-left"
|
2021-07-13 16:41:34 +01:00
|
|
|
onClicked: mousepad.pluginInterface.sendCommand({"singleclick": true});
|
2016-06-05 21:42:19 +01:00
|
|
|
}
|
|
|
|
Button {
|
|
|
|
Layout.fillWidth: true
|
2018-11-22 00:26:17 +00:00
|
|
|
icon.name: "input-mouse-click-middle"
|
2021-07-13 16:41:34 +01:00
|
|
|
onClicked: mousepad.pluginInterface.sendCommand({"middleclick": true});
|
2016-06-05 21:42:19 +01:00
|
|
|
}
|
|
|
|
Button {
|
|
|
|
Layout.fillWidth: true
|
2018-11-22 00:26:17 +00:00
|
|
|
icon.name: "input-mouse-click-right"
|
2021-07-13 16:41:34 +01:00
|
|
|
onClicked: mousepad.pluginInterface.sendCommand({"rightclick": true});
|
2016-06-05 21:42:19 +01:00
|
|
|
}
|
2015-07-22 02:19:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|