File indexing completed on 2024-04-14 03:57:08

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1997 Matthias Kalle Dalheimer <kalle@kde.org>
0004     SPDX-FileCopyrightText: 1998, 1999, 2000 KDE Team
0005     SPDX-FileCopyrightText: 2008 Nick Shaforostoff <shaforostoff@kde.ru>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #ifndef KCHECKACCELERATORS_H_
0011 #define KCHECKACCELERATORS_H_
0012 
0013 #include <QObject>
0014 #include <QPointer>
0015 
0016 #include <QTimer>
0017 
0018 class QDialog;
0019 class QTextBrowser;
0020 
0021 /**
0022  @internal
0023  This class allows translators (and application developers) to check for accelerator
0024  conflicts in menu and widgets. Put the following in your kdeglobals (or the config
0025  file for the application you're testing):
0026 
0027  \code
0028  [Development]
0029  CheckAccelerators=F12
0030  AutoCheckAccelerators=false
0031  AlwaysShowCheckAccelerators=false
0032  \endcode
0033 
0034  The checking can be either manual or automatic. To perform manual check, press
0035  the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking
0036  is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every
0037  time the GUI changes. It's possible that in certain cases the check will be
0038  done also when no visible changes in the GUI happen or the check won't be done
0039  even if the GUI changed (in the latter case, use manual check ). Automatic
0040  checks can be anytime disabled by the checkbox in the dialog presenting
0041  the results of the check. If you set 'AlwaysShowCheckAccelerators' to true,
0042  the dialog will be shown even if the automatic check didn't find any conflicts,
0043  and all submenus will be shown, even those without conflicts.
0044 
0045  The dialog first lists the name of the window, then all results for all menus
0046  (if the window has a menubar) and then result for all controls in the active
0047  window (if there are any checkboxes etc.). For every submenu and all controls
0048  there are shown all conflicts grouped by accelerator, and a list of all used
0049  accelerators.
0050 */
0051 
0052 class KCheckAccelerators : public QObject
0053 {
0054     Q_OBJECT
0055 public:
0056     KCheckAccelerators(QObject *parent, int key, bool autoCheck);
0057     /**
0058      * Re-implemented to filter the parent's events.
0059      */
0060     bool eventFilter(QObject *, QEvent *e) override;
0061 
0062 private:
0063     void checkAccelerators(bool automatic);
0064     int key;
0065     bool block;
0066     bool alwaysShow;
0067     bool autoCheck;
0068 
0069     QTimer autoCheckTimer;
0070     void createDialog(QWidget *parent, bool automatic);
0071     QPointer<QDialog> drklash;
0072     QTextBrowser *drklash_view;
0073 
0074 private Q_SLOTS:
0075     void autoCheckSlot();
0076     void slotDisableCheck(bool);
0077 };
0078 
0079 #endif