KXmlGui

kactionconflictdetector.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
5  SPDX-FileCopyrightText: 2000 Nicolas Hadacek <[email protected]>
6  SPDX-FileCopyrightText: 2000 Kurt Granroth <[email protected]>
7  SPDX-FileCopyrightText: 2000 Michael Koch <[email protected]>
8  SPDX-FileCopyrightText: 2001 Holger Freyther <[email protected]>
9  SPDX-FileCopyrightText: 2002 Ellis Whitehead <[email protected]>
10  SPDX-FileCopyrightText: 2002 Joseph Wenninger <[email protected]>
11  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
12 
13  SPDX-License-Identifier: LGPL-2.0-only
14 */
15 
16 #include <QAction>
17 #include <QCoreApplication>
18 #include <QShortcutEvent>
19 
20 #include <klocalizedstring.h>
21 #include <kmessagebox.h>
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 *>(watched)) {
35  QShortcutEvent *se = static_cast<QShortcutEvent *>(event);
36  if (se->isAmbiguous()) {
38  nullptr, // No widget to be seen around here
39  i18n("The key sequence '%1' is ambiguous. Use 'Configure Shortcuts'\n"
40  "from the 'Settings' menu to solve the ambiguity.\n"
41  "No action will be triggered.",
43  i18nc("@title:window", "Ambiguous shortcut detected"));
44  return true;
45  }
46  }
47 
48  return QObject::eventFilter(watched, event);
49  }
50 };
51 
52 void _k_installConflictDetector()
53 {
55  app->installEventFilter(new KActionConflictDetector(app));
56 }
57 
58 Q_COREAPP_STARTUP_FUNCTION(_k_installConflictDetector)
59 
60 #include "kactionconflictdetector.moc"
QEvent::Type type() const const
virtual bool event(QEvent *e)
void installEventFilter(QObject *filterObj)
Q_OBJECTQ_OBJECT
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isAmbiguous() const const
const QKeySequence & key() const const
virtual bool eventFilter(QObject *watched, QEvent *event)
QCoreApplication * instance()
QString i18n(const char *text, const TYPE &arg...)
QString toString(QKeySequence::SequenceFormat format) const const
void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
T qobject_cast(QObject *object)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:50:46 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.