File indexing completed on 2024-10-06 06:44:55
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> 0004 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0005 SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> 0006 SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> 0007 SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> 0008 SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> 0009 SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> 0010 SPDX-FileCopyrightText: 2002 Joseph Wenninger <jowenn@kde.org> 0011 SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> 0012 0013 SPDX-License-Identifier: LGPL-2.0-only 0014 */ 0015 0016 #include <QAction> 0017 #include <QCoreApplication> 0018 #include <QShortcutEvent> 0019 0020 #include <KLocalizedString> 0021 #include <KMessageBox> 0022 0023 class KActionConflictDetector : public QObject 0024 { 0025 Q_OBJECT 0026 public: 0027 explicit KActionConflictDetector(QObject *parent = nullptr) 0028 : QObject(parent) 0029 { 0030 } 0031 0032 bool eventFilter(QObject *watched, QEvent *event) override 0033 { 0034 if (event->type() == QEvent::Shortcut && qobject_cast<QAction *>(watched)) { 0035 QShortcutEvent *se = static_cast<QShortcutEvent *>(event); 0036 if (se->isAmbiguous()) { 0037 KMessageBox::information(nullptr, // No widget to be seen around here 0038 i18n("The key sequence '%1' is ambiguous. Use 'Configure Keyboard Shortcuts'\n" 0039 "from the 'Settings' menu to solve the ambiguity.\n" 0040 "No action will be triggered.", 0041 se->key().toString(QKeySequence::NativeText)), 0042 i18nc("@title:window", "Ambiguous shortcut detected")); 0043 return true; 0044 } 0045 } 0046 0047 return QObject::eventFilter(watched, event); 0048 } 0049 }; 0050 0051 void _k_installConflictDetector() 0052 { 0053 QCoreApplication *app = QCoreApplication::instance(); 0054 app->installEventFilter(new KActionConflictDetector(app)); 0055 } 0056 0057 Q_COREAPP_STARTUP_FUNCTION(_k_installConflictDetector) 0058 0059 #include "kactionconflictdetector.moc"