Skip to content

Commit

Permalink
Add support for more keys
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtapl committed Sep 6, 2024
1 parent cbb0bbf commit 67b8078
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 2 deletions.
57 changes: 57 additions & 0 deletions qml/keys/CapsLockKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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"
}
}
}
23 changes: 23 additions & 0 deletions qml/keys/DownKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: ""
shifted: ""
action: "down";
}
23 changes: 23 additions & 0 deletions qml/keys/EndKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: "end"
shifted: "end"
action: "end";
}
23 changes: 23 additions & 0 deletions qml/keys/EscapeKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: "esc"
shifted: "esc"
action: "escape";
}
23 changes: 23 additions & 0 deletions qml/keys/HomeKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: "home"
shifted: "home"
action: "home";
}
23 changes: 23 additions & 0 deletions qml/keys/LeftKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: ""
shifted: ""
action: "left";
}
23 changes: 23 additions & 0 deletions qml/keys/PageDownKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: "page down"
shifted: "page down"
action: "pagedown";
}
23 changes: 23 additions & 0 deletions qml/keys/PageUpKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: "page up"
shifted: "page up"
action: "pageup";
}
23 changes: 23 additions & 0 deletions qml/keys/RightKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: ""
shifted: ""
action: "right";
}
23 changes: 23 additions & 0 deletions qml/keys/TabKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: ""
shifted: ""
action: "tab";
}
23 changes: 23 additions & 0 deletions qml/keys/UpKey.qml
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.4

ActionKey {
label: ""
shifted: ""
action: "up";
}
11 changes: 11 additions & 0 deletions qml/keys/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/lib/models/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
20 changes: 18 additions & 2 deletions src/view/abstracttexteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 67b8078

Please sign in to comment.