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 <QCoreApplication> |
18 | #include <QShortcutEvent> |
19 | |
20 | #include <KLocalizedString> |
21 | #include <KMessageBox> |
22 | |
23 | class KActionConflictDetector : public QObject |
24 | { |
25 | Q_OBJECT |
26 | public: |
27 | explicit KActionConflictDetector(QObject *parent = nullptr) |
28 | : QObject(parent) |
29 | { |
30 | } |
31 | |
32 | bool eventFilter(QObject *watched, QEvent *event) override |
33 | { |
34 | if (event->type() == QEvent::Shortcut && qobject_cast<QAction *>(object: watched)) { |
35 | QShortcutEvent *se = static_cast<QShortcutEvent *>(event); |
36 | if (se->isAmbiguous()) { |
37 | KMessageBox::information(parent: nullptr, // No widget to be seen around here |
38 | i18n("The key sequence '%1' is ambiguous. Use 'Configure Keyboard Shortcuts'\n" |
39 | "from the 'Settings' menu to solve the ambiguity.\n" |
40 | "No action will be triggered." , |
41 | se->key().toString(QKeySequence::NativeText)), |
42 | i18nc("@title:window" , "Ambiguous shortcut detected" )); |
43 | return true; |
44 | } |
45 | } |
46 | |
47 | return QObject::eventFilter(watched, event); |
48 | } |
49 | }; |
50 | |
51 | void _k_installConflictDetector() |
52 | { |
53 | QCoreApplication *app = QCoreApplication::instance(); |
54 | app->installEventFilter(filterObj: new KActionConflictDetector(app)); |
55 | } |
56 | |
57 | Q_COREAPP_STARTUP_FUNCTION(_k_installConflictDetector) |
58 | |
59 | #include "kactionconflictdetector.moc" |
60 | |