Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more keys #230

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one especially, seems superfluous, as the Shift key already supports a lock state.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caps lock key is only for completeness of a classical desktop layout.

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these buttons are to be included (is there a point, if nothing is using them?), they will definitely need better labels and icons. While esc might fit on a single key, most of the things added here do not, and should probably have icons instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned, I wanted to use a icon for the tab key, but could not find any list of supported icon names. The names of page up/down keys can be shortened to pg up and pg dn. I also found out, that there exist symbols for home and end keys, but I have not seen them used yet. There would just be an issue with caps lock, as its symbol is already used with locked shift key. I am unsure how to solve this other than just having a wider key :).

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