1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
3 Copyright (C) 1998, 1999, 2000 KDE Team
4 Copyright (C) 2008 Nick Shaforostoff <shaforostoff@kde.ru>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20 */
21
22#ifndef KCHECKACCELERATORS_H_
23#define KCHECKACCELERATORS_H_
24
25#include <kdeui_export.h>
26
27#include <QObject>
28#include <QPointer>
29
30#include <QTimer>
31
32class QDialog;
33class QTextBrowser;
34
35/**
36 @internal
37 This class allows translators (and application developers) to check for accelerator
38 conflicts in menu and widgets. Put the following in your kdeglobals (or the config
39 file for the application you're testing):
40
41 \code
42 [Development]
43 CheckAccelerators=F12
44 AutoCheckAccelerators=false
45 AlwaysShowCheckAccelerators=false
46 \endcode
47
48 The checking can be either manual or automatic. To perform manual check, press
49 the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking
50 is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every
51 time the GUI changes. It's possible that in certain cases the check will be
52 done also when no visible changes in the GUI happen or the check won't be done
53 even if the GUI changed (in the latter case, use manual check ). Automatic
54 checks can be anytime disabled by the checkbox in the dialog presenting
55 the results of the check. If you set 'AlwaysShowCheckAccelerators' to true,
56 the dialog will be shown even if the automatic check didn't find any conflicts,
57 and all submenus will be shown, even those without conflicts.
58
59 The dialog first lists the name of the window, then all results for all menus
60 (if the window has a menubar) and then result for all controls in the active
61 window (if there are any checkboxes etc.). For every submenu and all controls
62 there are shown all conflicts grouped by accelerator, and a list of all used
63 accelerators.
64
65
66
67 COPY WIDGET TEXT:
68
69 You can copy widgets' texts to find them in translation files faster by middle-clicking them.
70 Put the following lines in ~/.kde4/share/config/kdeglobals (or in rc file for specific app):
71
72 \code
73 [Development]
74 CopyWidgetText=true
75 CopyWidgetTextCommand=find_in_po_script "%1" "%2"
76 \endcode
77
78 Where %1 gets replaced with program name and %2 - with text.
79 CopyWidgetTextCommand may be empty, in which case the text gets copied to clipboard.
80 Press Ctrl+MMB to get widget text w/o accelerator mark (&)
81
82*/
83
84class KCheckAccelerators: public QObject
85{
86 Q_OBJECT
87public:
88 /**
89 * Creates a KCheckAccelerators instance for the given object if this feature is enabled in kdeglobals.
90 * @param parent the parent to check
91 */
92 static void initiateIfNeeded(QObject* parent);
93 /**
94 * Re-implemented to filter the parent's events.
95 */
96 bool eventFilter(QObject*, QEvent* e);
97
98private:
99 KCheckAccelerators(QObject* parent, int key, bool autoCheck, bool copyWidgetText);
100
101 void checkAccelerators(bool automatic);
102 int key;
103 bool block;
104 bool alwaysShow;
105 bool autoCheck;
106
107 bool copyWidgetText;
108 QString copyWidgetTextCommand;
109
110 QTimer autoCheckTimer;
111 void createDialog(QWidget *parent, bool automatic);
112 QPointer<QDialog> drklash;
113 QTextBrowser *drklash_view;
114
115private Q_SLOTS:
116 void autoCheckSlot();
117 void slotDisableCheck(bool);
118};
119
120#endif
121