KXmlGui

kactionconflictdetector.cpp
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
23class KActionConflictDetector : public QObject
24{
26public:
27 explicit KActionConflictDetector(QObject *parent = nullptr)
29 {
30 }
31
32 bool eventFilter(QObject *watched, QEvent *event) override
33 {
34 if (event->type() == QEvent::Shortcut && qobject_cast<QAction *>(watched)) {
35 QShortcutEvent *se = static_cast<QShortcutEvent *>(event);
36 if (se->isAmbiguous()) {
37 KMessageBox::information(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.",
42 i18nc("@title:window", "Ambiguous shortcut detected"));
43 return true;
44 }
45 }
46
47 return QObject::eventFilter(watched, event);
48 }
49};
50
51void _k_installConflictDetector()
52{
54 app->installEventFilter(new KActionConflictDetector(app));
55}
56
57Q_COREAPP_STARTUP_FUNCTION(_k_installConflictDetector)
58
59#include "kactionconflictdetector.moc"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void information(QWidget *parent, const QString &text, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
QCoreApplication * instance()
QString toString(SequenceFormat format) const const
Q_OBJECTQ_OBJECT
virtual bool event(QEvent *e)
virtual bool eventFilter(QObject *watched, QEvent *event)
void installEventFilter(QObject *filterObj)
QObject * parent() const const
T qobject_cast(QObject *object)
bool isAmbiguous() const const
const QKeySequence & key() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.