From 67b80787ef7ef20f17aae77fba68a931b72219f6 Mon Sep 17 00:00:00 2001 From: vojtapl Date: Fri, 6 Sep 2024 16:30:44 +0200 Subject: [PATCH] Add support for more keys --- qml/keys/CapsLockKey.qml | 57 +++++++++++++++++++++++++++++++++ qml/keys/DownKey.qml | 23 +++++++++++++ qml/keys/EndKey.qml | 23 +++++++++++++ qml/keys/EscapeKey.qml | 23 +++++++++++++ qml/keys/HomeKey.qml | 23 +++++++++++++ qml/keys/LeftKey.qml | 23 +++++++++++++ qml/keys/PageDownKey.qml | 23 +++++++++++++ qml/keys/PageUpKey.qml | 23 +++++++++++++ qml/keys/RightKey.qml | 23 +++++++++++++ qml/keys/TabKey.qml | 23 +++++++++++++ qml/keys/UpKey.qml | 23 +++++++++++++ qml/keys/qmldir | 11 +++++++ src/lib/models/key.h | 3 ++ src/view/abstracttexteditor.cpp | 20 ++++++++++-- 14 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 qml/keys/CapsLockKey.qml create mode 100644 qml/keys/DownKey.qml create mode 100644 qml/keys/EndKey.qml create mode 100644 qml/keys/EscapeKey.qml create mode 100644 qml/keys/HomeKey.qml create mode 100644 qml/keys/LeftKey.qml create mode 100644 qml/keys/PageDownKey.qml create mode 100644 qml/keys/PageUpKey.qml create mode 100644 qml/keys/RightKey.qml create mode 100644 qml/keys/TabKey.qml create mode 100644 qml/keys/UpKey.qml diff --git a/qml/keys/CapsLockKey.qml b/qml/keys/CapsLockKey.qml new file mode 100644 index 00000000..fe5a3218 --- /dev/null +++ b/qml/keys/CapsLockKey.qml @@ -0,0 +1,57 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +import QtQuick.Controls 2.12 +import QtQuick.Window 2.12 +import MaliitKeyboard 2.0 + +ActionKey { + overridePressArea: true + + Rectangle { + anchors.margins: 8 + anchors.fill: parent + color: "#888888" + radius: 8 / Screen.devicePixelRatio + opacity: panel.activeKeypadState == "CAPSLOCK" ? 0.0 : 0.25 + } + + Label { + anchors.centerIn: parent + font.weight: Font.Light + opacity: 0.6 + font.pixelSize: parent.fontSize * 0.6 + text: "caps lock" + horizontalAlignment: Text.AlignHCenter + } + + MouseArea { + anchors.fill: parent + + onPressed: { + Feedback.keyPressed(); + + if (panel.activeKeypadState == "NORMAL") + panel.activeKeypadState = "CAPSLOCK"; + else if (panel.activeKeypadState == "SHIFTED") + panel.activeKeypadState = "CAPSLOCK" + else if (panel.activeKeypadState == "CAPSLOCK") + panel.activeKeypadState = "NORMAL" + } + } +} diff --git a/qml/keys/DownKey.qml b/qml/keys/DownKey.qml new file mode 100644 index 00000000..2b942b04 --- /dev/null +++ b/qml/keys/DownKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "↓" + shifted: "↓" + action: "down"; +} diff --git a/qml/keys/EndKey.qml b/qml/keys/EndKey.qml new file mode 100644 index 00000000..e8c10ce5 --- /dev/null +++ b/qml/keys/EndKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "end" + shifted: "end" + action: "end"; +} diff --git a/qml/keys/EscapeKey.qml b/qml/keys/EscapeKey.qml new file mode 100644 index 00000000..311c192b --- /dev/null +++ b/qml/keys/EscapeKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "esc" + shifted: "esc" + action: "escape"; +} diff --git a/qml/keys/HomeKey.qml b/qml/keys/HomeKey.qml new file mode 100644 index 00000000..44288017 --- /dev/null +++ b/qml/keys/HomeKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "home" + shifted: "home" + action: "home"; +} diff --git a/qml/keys/LeftKey.qml b/qml/keys/LeftKey.qml new file mode 100644 index 00000000..3140b4d2 --- /dev/null +++ b/qml/keys/LeftKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "←" + shifted: "←" + action: "left"; +} diff --git a/qml/keys/PageDownKey.qml b/qml/keys/PageDownKey.qml new file mode 100644 index 00000000..4f7c665a --- /dev/null +++ b/qml/keys/PageDownKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "page down" + shifted: "page down" + action: "pagedown"; +} diff --git a/qml/keys/PageUpKey.qml b/qml/keys/PageUpKey.qml new file mode 100644 index 00000000..189d44c5 --- /dev/null +++ b/qml/keys/PageUpKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "page up" + shifted: "page up" + action: "pageup"; +} diff --git a/qml/keys/RightKey.qml b/qml/keys/RightKey.qml new file mode 100644 index 00000000..c1db5145 --- /dev/null +++ b/qml/keys/RightKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "→" + shifted: "→" + action: "right"; +} diff --git a/qml/keys/TabKey.qml b/qml/keys/TabKey.qml new file mode 100644 index 00000000..f8fb3674 --- /dev/null +++ b/qml/keys/TabKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "↹" + shifted: "↹" + action: "tab"; +} diff --git a/qml/keys/UpKey.qml b/qml/keys/UpKey.qml new file mode 100644 index 00000000..a3d683c6 --- /dev/null +++ b/qml/keys/UpKey.qml @@ -0,0 +1,23 @@ +/* + * Copyright 2024 Vojtěch Pluskal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 + +ActionKey { + label: "↑" + shifted: "↑" + action: "up"; +} diff --git a/qml/keys/qmldir b/qml/keys/qmldir index 97a3beaf..83f5a39e 100644 --- a/qml/keys/qmldir +++ b/qml/keys/qmldir @@ -18,3 +18,14 @@ PressArea 1.0 PressArea.qml SpaceKey 1.0 SpaceKey.qml UrlKey 1.0 UrlKey.qml CategoryKey 1.0 CategoryKey.qml +UpKey 1.0 UpKey.qml +DownKey 1.0 DownKey.qml +LeftKey 1.0 LeftKey.qml +RightKey 1.0 RightKey.qml +EscapeKey 1.0 EscapeKey.qml +TabKey 1.0 TabKey.qml +HomeKey 1.0 HomeKey.qml +EndKey 1.0 EndKey.qml +PageUpKey 1.0 PageUpKey.qml +PageDownKey 1.0 PageDownKey.qml +CapsLockKey 1.0 CapsLockKey.qml diff --git a/src/lib/models/key.h b/src/lib/models/key.h index 5695cc1c..ae0cf832 100644 --- a/src/lib/models/key.h +++ b/src/lib/models/key.h @@ -72,6 +72,9 @@ class Key ActionRightLayout, //!< Switch to right/next language layout. ActionHome, //!< Key moves cursor to beginning of text. ActionEnd, //!< Key moves cursor to end of text. + ActionEscape, //!< Key sends Escape + ActionPageUp, //!< Key sends PageUp + ActionPageDown, //!< Key sends PageDown NumActions }; diff --git a/src/view/abstracttexteditor.cpp b/src/view/abstracttexteditor.cpp index bf7a69e1..c549d228 100644 --- a/src/view/abstracttexteditor.cpp +++ b/src/view/abstracttexteditor.cpp @@ -617,11 +617,11 @@ void AbstractTextEditor::onKeyReleased(const Key &key) case Key::ActionDown: event_key = Qt::Key_Down; break; - + case Key::ActionKeySequence: sendKeySequence(text, QKeySequence::fromString(key.commandSequence())); break; - + case Key::ActionCommand: invokeAction(text, QKeySequence::fromString(key.commandSequence())); break; @@ -642,6 +642,22 @@ void AbstractTextEditor::onKeyReleased(const Key &key) event_key = Qt::Key_End; break; + case Key::ActionEscape: + event_key = Qt::Key_Escape; + break; + + case Key::ActionPageUp: + event_key = Qt::Key_PageUp; + break; + + case Key::ActionPageDown: + event_key = Qt::Key_PageDown; + break; + + case Key::ActionTab: + event_key = Qt::Key_Tab; + break; + default: break; }