1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> |
4 | SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> |
5 | SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> |
6 | SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> |
7 | SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> |
8 | SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> |
9 | SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> |
10 | SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org> |
11 | SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> |
12 | |
13 | SPDX-License-Identifier: LGPL-2.0-only |
14 | */ |
15 | |
16 | #include <QAction> |
17 | #include <QShortcutEvent> |
18 | |
19 | #include <KLocalizedString> |
20 | #include <KMessageBox> |
21 | |
22 | class KActionConflictDetector : public QObject |
23 | { |
24 | Q_OBJECT |
25 | public: |
26 | explicit KActionConflictDetector(QObject *parent = nullptr) |
27 | : QObject(parent) |
28 | { |
29 | } |
30 | |
31 | bool eventFilter(QObject *watched, QEvent *event) override |
32 | { |
33 | if (event->type() == QEvent::Shortcut && qobject_cast<QAction *>(object: watched)) { |
34 | QShortcutEvent *se = static_cast<QShortcutEvent *>(event); |
35 | if (se->isAmbiguous()) { |
36 | KMessageBox::information(parent: nullptr, // No widget to be seen around here |
37 | i18n("The key sequence '%1' is ambiguous. Use 'Configure Keyboard Shortcuts'\n" |
38 | "from the 'Settings' menu to solve the ambiguity.\n" |
39 | "No action will be triggered." , |
40 | se->key().toString(QKeySequence::NativeText)), |
41 | i18nc("@title:window" , "Ambiguous shortcut detected" )); |
42 | return true; |
43 | } |
44 | } |
45 | |
46 | return QObject::eventFilter(watched, event); |
47 | } |
48 | }; |
49 | |