Reader: make 3 keyboard shortcuts work with non-Latin layouts

MainWindowViewer::keyPressEvent()'s custom matching of these shortcuts
does not leverage all the features of standard Qt shortcut matching. As
a result, the corresponding actions cannot be triggered when their
assigned shortcuts consist of a single Latin letter without modifiers
and e.g. Ukrainian keyboard layout is active.

Furthermore, some key presses (e.g. Scroll Lock in my customized
keyboard layout) set QKeyEvent::key() to 0, which the custom matching
considers equal to an unassigned shortcut. So an action without shortcut
is triggered by such a key press.

Adding these 3 actions to MainWindowViewer and connecting the
corresponding slots to their triggered() signals allows to remove the
custom matching code and thus eliminates both of its issues.
This commit is contained in:
Igor Kushnir
2021-01-30 20:35:36 +02:00
parent 77c96de0ea
commit 88e0f5513a
2 changed files with 6 additions and 34 deletions

View File

@ -1046,36 +1046,6 @@ void MainWindowViewer::disableActions()
showFlowAction->setDisabled(true);
}
void MainWindowViewer::keyPressEvent(QKeyEvent *event)
{
// TODO remove unused keys
int _key = event->key();
Qt::KeyboardModifiers modifiers = event->modifiers();
if (modifiers & Qt::ShiftModifier)
_key |= Qt::SHIFT;
if (modifiers & Qt::ControlModifier)
_key |= Qt::CTRL;
if (modifiers & Qt::MetaModifier)
_key |= Qt::META;
if (modifiers & Qt::AltModifier)
_key |= Qt::ALT;
QKeySequence key(_key);
if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y)) {
toggleFullScreen();
event->accept();
} else if (key == ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y)) {
toggleToolBars();
event->accept();
} else if (key == ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y)) {
toggleWidthHeight();
event->accept();
} else
QWidget::keyPressEvent(event);
}
void MainWindowViewer::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
@ -1269,14 +1239,17 @@ void MainWindowViewer::setUpShortcutsManagement()
allActions << tmpList;
// keys without actions (General)
QAction *toggleFullScreenAction = new QAction(tr("Toggle fullscreen mode"), orphanActions);
toggleFullScreenAction->setData(TOGGLE_FULL_SCREEN_ACTION_Y);
toggleFullScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_FULL_SCREEN_ACTION_Y));
addAction(toggleFullScreenAction);
connect(toggleFullScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleFullScreen);
QAction *toggleToolbarsAction = new QAction(tr("Hide/show toolbar"), orphanActions);
toggleToolbarsAction->setData(TOGGLE_TOOL_BARS_ACTION_Y);
toggleToolbarsAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(TOGGLE_TOOL_BARS_ACTION_Y));
addAction(toggleToolbarsAction);
connect(toggleToolbarsAction, &QAction::triggered, this, &MainWindowViewer::toggleToolBars);
editShortcutsDialog->addActionsGroup(tr("General"), QIcon(":/images/shortcuts_group_general.png"),
tmpList = QList<QAction *>()
@ -1324,10 +1297,11 @@ void MainWindowViewer::setUpShortcutsManagement()
allActions << tmpList;
// keys without actions
auto toggleFitToScreenAction = new QAction(tr("Toggle between fit to width and fit to height"), orphanActions);
toggleFitToScreenAction->setData(CHANGE_FIT_ACTION_Y);
toggleFitToScreenAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(CHANGE_FIT_ACTION_Y));
addAction(toggleFitToScreenAction);
connect(toggleFitToScreenAction, &QAction::triggered, this, &MainWindowViewer::toggleWidthHeight);
editShortcutsDialog->addActionsGroup(tr("Page adjustement"), QIcon(":/images/shortcuts_group_page.png"),
tmpList = QList<QAction *>()