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

Keyboard UX/UI: Access to caps lock - clearer icons #34362

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
37 changes: 28 additions & 9 deletions selfdrive/ui/qt/widgets/keyboard.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "selfdrive/ui/qt/widgets/keyboard.h"

#include <vector>
#include <QDateTime>

#include <QButtonGroup>
#include <QHBoxLayout>
Expand All @@ -10,10 +11,12 @@

const QString BACKSPACE_KEY = "⌫";
const QString ENTER_KEY = "→";
const QString SHIFT_KEY = "⇧";
const QString CAPS_LOCK_KEY = "⇪";

const QMap<QString, int> KEY_STRETCH = {{" ", 3}, {ENTER_KEY, 2}};

const QStringList CONTROL_BUTTONS = {"↑", "↓", "ABC", "#+=", "123", BACKSPACE_KEY, ENTER_KEY};
const QStringList CONTROL_BUTTONS = {SHIFT_KEY, CAPS_LOCK_KEY, "ABC", "#+=", "123", BACKSPACE_KEY, ENTER_KEY};

const float key_spacing_vertical = 20;
const float key_spacing_horizontal = 15;
Expand Down Expand Up @@ -106,7 +109,7 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) {
std::vector<QVector<QString>> lowercase = {
{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"},
{"a", "s", "d", "f", "g", "h", "j", "k", "l"},
{"↑", "z", "x", "c", "v", "b", "n", "m", BACKSPACE_KEY},
{SHIFT_KEY, "z", "x", "c", "v", "b", "n", "m", BACKSPACE_KEY},
{"123", "/", "-", " ", ".", ENTER_KEY},
};
main_layout->addWidget(new KeyboardLayout(this, lowercase));
Expand All @@ -115,8 +118,8 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) {
std::vector<QVector<QString>> uppercase = {
{"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"},
{"A", "S", "D", "F", "G", "H", "J", "K", "L"},
{"↓", "Z", "X", "C", "V", "B", "N", "M", BACKSPACE_KEY},
{"123", " ", ".", ENTER_KEY},
{SHIFT_KEY, "Z", "X", "C", "V", "B", "N", "M", BACKSPACE_KEY},
{"123", "/", "-", " ", ".", ENTER_KEY},
};
main_layout->addWidget(new KeyboardLayout(this, uppercase));

Expand All @@ -141,25 +144,41 @@ Keyboard::Keyboard(QWidget *parent) : QFrame(parent) {
main_layout->setCurrentIndex(0);
}

void Keyboard::handleCapsPress() {
bool is_double_tap = (QDateTime::currentMSecsSinceEpoch() - last_shift_key_press) <= DOUBLE_TAP_THRESHOLD_MS;
last_shift_key_press = QDateTime::currentMSecsSinceEpoch();

bool was_locked = caps_lock_on;
caps_lock_on = !was_locked && is_double_tap;
main_layout->setCurrentIndex(caps_lock_on || (!was_locked && main_layout->currentIndex() == 0));

for (KeyButton* btn : main_layout->currentWidget()->findChildren<KeyButton*>()) {
if (btn->text() == SHIFT_KEY || btn->text() == CAPS_LOCK_KEY) {
btn->setText(caps_lock_on ? CAPS_LOCK_KEY : SHIFT_KEY);
btn->setStyleSheet(main_layout->currentIndex() == 1 ? "background-color: #465BEA;" : "");
}
}
}

ugtthis marked this conversation as resolved.
Show resolved Hide resolved
void Keyboard::handleButton(QAbstractButton* btn) {
const QString &key = btn->text();
if (CONTROL_BUTTONS.contains(key)) {
if (key == "↓" || key == "ABC") {
if (key == "ABC") {
caps_lock_on = false;
main_layout->setCurrentIndex(0);
} else if (key == "↑") {
main_layout->setCurrentIndex(1);
} else if (key == SHIFT_KEY || key == CAPS_LOCK_KEY) {
handleCapsPress();
} else if (key == "123") {
main_layout->setCurrentIndex(2);
} else if (key == "#+=") {
main_layout->setCurrentIndex(3);
} else if (key == ENTER_KEY) {
main_layout->setCurrentIndex(0);
emit emitEnter();
} else if (key == BACKSPACE_KEY) {
emit emitBackspace();
}
} else {
if ("A" <= key && key <= "Z") {
if (!caps_lock_on && "A" <= key && key <= "Z") {
main_layout->setCurrentIndex(0);
}
emit emitKey(key);
Expand Down
4 changes: 4 additions & 0 deletions selfdrive/ui/qt/widgets/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ class Keyboard : public QFrame {

private:
QStackedLayout* main_layout;
bool caps_lock_on = false;
qint64 last_shift_key_press = 0;
static const int DOUBLE_TAP_THRESHOLD_MS = 250;

private slots:
void handleButton(QAbstractButton* m_button);
void handleCapsPress();

signals:
void emitKey(const QString &s);
Expand Down
Loading