Skip to content

Commit

Permalink
Support various action keys in shortcuts
Browse files Browse the repository at this point in the history
This adds support for the Help, Open, Close,
Save, New, Cut, Copy, Paste, Undo, Redo, Back,
Forward, Refresh, ZoomIn, ZoomOut, Find,
Settings, Exit, and Cancel keys to the default
keyboard shortcuts.

These keys can be found on old and unusual
keyboards, but also in custom layouts for
standard keyboards.

Task-number: QTBUG-93269
Change-Id: Id349cad977800589ded14456e99c6b20a0263592
Reviewed-by: Shawn Rutledge <[email protected]>
  • Loading branch information
Jules-Bertholet committed Jan 10, 2025
1 parent 9d4b5fa commit 1a82056
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/gui/kernel/qplatformtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,48 +176,63 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
// StandardKey Priority Key Sequence Platforms
{QKeySequence::HelpContents, 1, Qt::CTRL | Qt::Key_Question, KB_Mac},
{QKeySequence::HelpContents, 0, Qt::Key_F1, KB_Win | KB_X11},
{QKeySequence::HelpContents, 0, Qt::Key_Help, KB_All},
{QKeySequence::WhatsThis, 1, Qt::SHIFT | Qt::Key_F1, KB_All},
{QKeySequence::Open, 1, Qt::CTRL | Qt::Key_O, KB_All},
{QKeySequence::Open, 0, Qt::Key_Open, KB_All},
{QKeySequence::Close, 0, Qt::CTRL | Qt::Key_F4, KB_Mac},
{QKeySequence::Close, 1, Qt::CTRL | Qt::Key_F4, KB_Win},
{QKeySequence::Close, 1, Qt::CTRL | Qt::Key_W, KB_Mac},
{QKeySequence::Close, 0, Qt::CTRL | Qt::Key_W, KB_Win | KB_X11},
{QKeySequence::Close, 0, Qt::Key_Close, KB_All},
{QKeySequence::Save, 1, Qt::CTRL | Qt::Key_S, KB_All},
{QKeySequence::Save, 0, Qt::Key_Save, KB_All},
{QKeySequence::New, 1, Qt::CTRL | Qt::Key_N, KB_All},
{QKeySequence::New, 0, Qt::Key_New, KB_All},
{QKeySequence::Delete, 0, Qt::CTRL | Qt::Key_D, KB_X11}, //emacs (line edit only)
{QKeySequence::Delete, 1, Qt::Key_Delete, KB_All},
{QKeySequence::Delete, 0, Qt::META | Qt::Key_D, KB_Mac},
{QKeySequence::Cut, 1, Qt::CTRL | Qt::Key_X, KB_All},
{QKeySequence::Cut, 0, Qt::SHIFT | Qt::Key_Delete, KB_Win | KB_X11}, //## Check if this should work on mac
{QKeySequence::Cut, 0, Qt::Key_F20, KB_X11}, //Cut on sun keyboards
{QKeySequence::Cut, 0, Qt::META | Qt::Key_K, KB_Mac},
{QKeySequence::Cut, 0, Qt::Key_Cut, KB_All},
{QKeySequence::Copy, 0, Qt::CTRL | Qt::Key_Insert, KB_X11 | KB_Win},
{QKeySequence::Copy, 1, Qt::CTRL | Qt::Key_C, KB_All},
{QKeySequence::Copy, 0, Qt::Key_F16, KB_X11}, //Copy on sun keyboards
{QKeySequence::Copy, 0, Qt::Key_Copy, KB_All},
{QKeySequence::Paste, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Insert, KB_X11},
{QKeySequence::Paste, 1, Qt::CTRL | Qt::Key_V, KB_All},
{QKeySequence::Paste, 0, Qt::SHIFT | Qt::Key_Insert, KB_Win | KB_X11},
{QKeySequence::Paste, 0, Qt::Key_F18, KB_X11}, //Paste on sun keyboards
{QKeySequence::Paste, 0, Qt::META | Qt::Key_Y, KB_Mac},
{QKeySequence::Paste, 0, Qt::Key_Paste, KB_All},
{QKeySequence::Undo, 0, Qt::ALT | Qt::Key_Backspace, KB_Win},
{QKeySequence::Undo, 1, Qt::CTRL | Qt::Key_Z, KB_All},
{QKeySequence::Undo, 0, Qt::Key_F14, KB_X11}, //Undo on sun keyboards
{QKeySequence::Undo, 0, Qt::Key_Undo, KB_All},
{QKeySequence::Redo, 0, Qt::ALT | Qt::SHIFT | Qt::Key_Backspace,KB_Win},
{QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Mac},
{QKeySequence::Redo, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Z, KB_Win | KB_X11},
{QKeySequence::Redo, 1, Qt::CTRL | Qt::Key_Y, KB_Win},
{QKeySequence::Redo, 0, Qt::Key_Redo, KB_All},
{QKeySequence::Back, 1, Qt::ALT | Qt::Key_Left, KB_Win | KB_X11},
{QKeySequence::Back, 0, Qt::CTRL | Qt::Key_Left, KB_Mac},
{QKeySequence::Back, 1, Qt::CTRL | Qt::Key_BracketLeft, KB_Mac},
{QKeySequence::Back, 0, Qt::Key_Backspace, KB_Win},
{QKeySequence::Back, 0, Qt::Key_Back, KB_All},
{QKeySequence::Forward, 1, Qt::ALT | Qt::Key_Right, KB_Win | KB_X11},
{QKeySequence::Forward, 0, Qt::CTRL | Qt::Key_Right, KB_Mac},
{QKeySequence::Forward, 1, Qt::CTRL | Qt::Key_BracketRight, KB_Mac},
{QKeySequence::Forward, 0, Qt::SHIFT | Qt::Key_Backspace, KB_Win},
{QKeySequence::Forward, 0, Qt::Key_Forward, KB_All},
{QKeySequence::Refresh, 1, Qt::CTRL | Qt::Key_R, KB_Gnome | KB_Mac},
{QKeySequence::Refresh, 0, Qt::Key_F5, KB_Win | KB_X11},
{QKeySequence::Refresh, 0, Qt::Key_Refresh, KB_All},
{QKeySequence::ZoomIn, 1, Qt::CTRL | Qt::Key_Plus, KB_All},
{QKeySequence::ZoomIn, 0, Qt::Key_ZoomIn, KB_All},
{QKeySequence::ZoomOut, 1, Qt::CTRL | Qt::Key_Minus, KB_All},
{QKeySequence::ZoomOut, 0, Qt::Key_ZoomOut, KB_All},
{QKeySequence::Print, 1, Qt::CTRL | Qt::Key_P, KB_All},
{QKeySequence::AddTab, 1, Qt::CTRL | Qt::SHIFT | Qt::Key_N, KB_KDE},
{QKeySequence::AddTab, 0, Qt::CTRL | Qt::Key_T, KB_All},
Expand All @@ -234,6 +249,7 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
{QKeySequence::PreviousChild, 0, Qt::CTRL | Qt::Key_Period, KB_KDE},
{QKeySequence::PreviousChild, 0, Qt::Key_Back, KB_All},
{QKeySequence::Find, 0, Qt::CTRL | Qt::Key_F, KB_All},
{QKeySequence::Find, 0, Qt::Key_Find, KB_All},
{QKeySequence::FindNext, 0, Qt::CTRL | Qt::Key_G, KB_Win},
{QKeySequence::FindNext, 1, Qt::CTRL | Qt::Key_G, KB_Gnome | KB_Mac},
{QKeySequence::FindNext, 1, Qt::Key_F3, KB_Win},
Expand Down Expand Up @@ -326,9 +342,12 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
{QKeySequence::InsertLineSeparator, 0, Qt::SHIFT | Qt::Key_Return, KB_All},
{QKeySequence::InsertLineSeparator, 0, Qt::META | Qt::Key_O, KB_Mac},
{QKeySequence::SaveAs, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_S, KB_All},
{QKeySequence::SaveAs, 0, Qt::SHIFT | Qt::Key_Save, KB_All},
{QKeySequence::Preferences, 0, Qt::CTRL | Qt::Key_Comma, KB_Mac},
{QKeySequence::Preferences, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_Comma, KB_KDE},
{QKeySequence::Preferences, 0, Qt::Key_Settings, KB_All},
{QKeySequence::Quit, 0, Qt::CTRL | Qt::Key_Q, KB_X11 | KB_Gnome | KB_KDE | KB_Mac},
{QKeySequence::Quit, 0, Qt::Key_Exit, KB_All},
{QKeySequence::FullScreen, 1, Qt::META | Qt::CTRL | Qt::Key_F, KB_Mac},
{QKeySequence::FullScreen, 0, Qt::ALT | Qt::Key_Enter, KB_Win},
{QKeySequence::FullScreen, 0, Qt::CTRL | Qt::SHIFT | Qt::Key_F, KB_KDE},
Expand All @@ -339,7 +358,8 @@ const QKeyBinding QPlatformThemePrivate::keyBindings[] = {
{QKeySequence::Backspace, 1, Qt::Key_Backspace, KB_Mac},
{QKeySequence::Backspace, 0, Qt::META | Qt::Key_H, KB_Mac},
{QKeySequence::Cancel, 0, Qt::Key_Escape, KB_All},
{QKeySequence::Cancel, 0, Qt::CTRL | Qt::Key_Period, KB_Mac}
{QKeySequence::Cancel, 0, Qt::CTRL | Qt::Key_Period, KB_Mac},
{QKeySequence::Cancel, 0, Qt::Key_Cancel, KB_All}
};

const uint QPlatformThemePrivate::numberOfKeyBindings = sizeof(QPlatformThemePrivate::keyBindings)/(sizeof(QKeyBinding));
Expand Down
7 changes: 4 additions & 3 deletions tests/auto/gui/kernel/qaction/tst_qaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,18 @@ void tst_QAction::setStandardKeys()
QCOMPARE(act.shortcut(), act.shortcuts().constFirst());

QList<QKeySequence> expected;
const QKeySequence copy = QKeySequence(QStringLiteral("Copy"));
const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT"));
switch (m_keyboardScheme) {
case QPlatformTheme::MacKeyboardScheme:
expected << ctrlC;
expected << ctrlC << copy;
break;
case QPlatformTheme::WindowsKeyboardScheme:
expected << ctrlC << ctrlInsert;
expected << ctrlC<< ctrlInsert << copy ;
break;
default: // X11
expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16"));
expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16")) << copy;
break;
}

Expand Down
7 changes: 4 additions & 3 deletions tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,18 @@ void tst_QKeySequence::keyBindings()
QKeySequence::keyBindings(QKeySequence::Copy);

QList<QKeySequence> expected;
const QKeySequence copy = QKeySequence(QStringLiteral("Copy"));
const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT"));
switch (m_keyboardScheme) {
case QPlatformTheme::MacKeyboardScheme:
expected << ctrlC;
expected << ctrlC << copy;
break;
case QPlatformTheme::WindowsKeyboardScheme:
expected << ctrlC << ctrlInsert;
expected << ctrlC << ctrlInsert << copy;
break;
default: // X11
expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16"));
expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16")) << copy;
break;
}
QCOMPARE(bindings, expected);
Expand Down

0 comments on commit 1a82056

Please sign in to comment.