• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kcheckaccelerators.cpp
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
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21// $Id$
22
23#define INCLUDE_MENUITEM_DEF
24#include <tqmenudata.h>
25
26#include "config.h"
27
28#include "kcheckaccelerators.h"
29#include "tdeaccelmanager.h"
30#include <tqpopupmenu.h>
31#include <tqapplication.h>
32#include <tqdialog.h>
33#include <tqlayout.h>
34#include <tqtextview.h>
35#include <tqobjectlist.h>
36#include <tqmenubar.h>
37#include <tqtabbar.h>
38#include <tqpushbutton.h>
39#include <tqmetaobject.h>
40#include <tqcheckbox.h>
41
42#include <tdeconfig.h>
43#include <kdebug.h>
44#include <tdeglobal.h>
45#include <tdeshortcut.h>
46#include <tdelocale.h>
47
48/*
49
50 HOWTO:
51
52 This class allows translators (and application developers) to check for accelerator
53 conflicts in menu and widgets. Put the following in your kdeglobals (or the config
54 file for the application you're testing):
55
56 [Development]
57 CheckAccelerators=F12
58 AutoCheckAccelerators=false
59 AlwaysShowCheckAccelerators=false
60
61 The checking can be either manual or automatic. To perform manual check, press
62 the keyboard shortcut set to 'CheckAccelerators' (here F12). If automatic checking
63 is enabled by setting 'AutoCheckAccelerators' to true, check will be performed every
64 time the GUI changes. It's possible that in certain cases the check will be
65 done also when no visible changes in the GUI happen or the check won't be done
66 even if the GUI changed (in the latter case, use manual check ). Automatic
67 checks can be anytime disabled by the checkbox in the dialog presenting
68 the results of the check. If you set 'AlwaysShowCheckAccelerators' to true,
69 the dialog will be shown even if the automatic check didn't find any conflicts,
70 and all submenus will be shown, even those without conflicts.
71
72 The dialog first lists the name of the window, then all results for all menus
73 (if the window has a menubar) and then result for all controls in the active
74 window (if there are any checkboxes etc.). For every submenu and all controls
75 there are shown all conflicts grouped by accelerator, and a list of all used
76 accelerators.
77*/
78
79KCheckAccelerators::KCheckAccelerators( TQObject* parent )
80 : TQObject( parent, "kapp_accel_filter" ), key(0), block( false ), drklash(0)
81{
82 parent->installEventFilter( this );
83 TDEConfigGroupSaver saver( TDEGlobal::config(), "Development" );
84 TQString sKey = TDEGlobal::config()->readEntry( "CheckAccelerators" ).stripWhiteSpace();
85 if( !sKey.isEmpty() ) {
86 TDEShortcut cuts( sKey );
87 if( cuts.count() > 0 )
88 key = int(cuts.seq(0).qt());
89 }
90 alwaysShow = TDEGlobal::config()->readBoolEntry( "AlwaysShowCheckAccelerators", false );
91 autoCheck = TDEGlobal::config()->readBoolEntry( "AutoCheckAccelerators", true );
92 connect( &autoCheckTimer, TQ_SIGNAL( timeout()), TQ_SLOT( autoCheckSlot()));
93}
94
95bool KCheckAccelerators::eventFilter( TQObject * , TQEvent * e)
96{
97 if ( block )
98 return false;
99
100 switch ( e->type() ) { // just simplify debuggin
101 case TQEvent::Accel:
102 if ( key && (static_cast<TQKeyEvent*>(e)->key() == key) ) {
103 block = true;
104 checkAccelerators( false );
105 block = false;
106 static_cast<TQKeyEvent*>(e)->accept();
107 return true;
108 }
109 break;
110 case TQEvent::ChildInserted:
111 case TQEvent::ChildRemoved:
112 case TQEvent::Resize:
113 case TQEvent::LayoutHint:
114 case TQEvent::WindowActivate:
115 case TQEvent::WindowDeactivate:
116 if( autoCheck )
117 autoCheckTimer.start( 20, true ); // 20 ms
118 break;
119 case TQEvent::Timer:
120 case TQEvent::MouseMove:
121 case TQEvent::Paint:
122 return false;
123 default:
124 // kdDebug(125) << "KCheckAccelerators::eventFilter " << e->type() << " " << autoCheck << endl;
125 break;
126 }
127 return false;
128}
129
130void KCheckAccelerators::autoCheckSlot()
131{
132 if( block )
133 {
134 autoCheckTimer.start( 20, true );
135 return;
136 }
137 block = true;
138 checkAccelerators( !alwaysShow );
139 block = false;
140}
141
142void KCheckAccelerators::createDialog(TQWidget *actWin, bool automatic)
143{
144 if ( drklash )
145 return;
146
147 drklash = new TQDialog( actWin, "kapp_accel_check_dlg", false, (WFlags)TQt::WDestructiveClose);
148 drklash->setCaption( i18n( "Dr. Klash' Accelerator Diagnosis" ));
149 drklash->resize( 500, 460 );
150 TQVBoxLayout* layout = new TQVBoxLayout( drklash, 11, 6 );
151 layout->setAutoAdd( true );
152 drklash_view = new TQTextView( drklash );
153 TQCheckBox* disableAutoCheck = NULL;
154 if( automatic ) {
155 disableAutoCheck = new TQCheckBox( i18n( "&Disable automatic checking" ), drklash );
156 connect(disableAutoCheck, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotDisableCheck(bool)));
157 }
158 TQPushButton* btnClose = new TQPushButton( i18n( "&Close" ), drklash );
159 btnClose->setDefault( true );
160 connect( btnClose, TQ_SIGNAL( clicked() ), drklash, TQ_SLOT( close() ) );
161 if (disableAutoCheck)
162 disableAutoCheck->setFocus();
163 else
164 drklash_view->setFocus();
165}
166
167void KCheckAccelerators::slotDisableCheck(bool on)
168{
169 autoCheck = !on;
170 if (!on)
171 autoCheckSlot();
172}
173
174void KCheckAccelerators::checkAccelerators( bool automatic )
175{
176 TQWidget* actWin = tqApp->activeWindow();
177 if ( !actWin )
178 return;
179
180 TDEAcceleratorManager::manage(actWin);
181 TQString a, c, r;
182 TDEAcceleratorManager::last_manage(a, c, r);
183
184 if (automatic) // for now we only show dialogs on F12 checks
185 return;
186
187 if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty()))
188 return;
189
190 TQString s;
191
192 if ( ! c.isEmpty() ) {
193 s += i18n("<h2>Accelerators changed</h2>");
194 s += "<table border><tr><th><b>Old Text</b></th><th><b>New Text</b></th></tr>"
195 + c + "</table>";
196 }
197
198 if ( ! r.isEmpty() ) {
199 s += i18n("<h2>Accelerators removed</h2>");
200 s += "<table border><tr><th><b>Old Text</b></th></tr>" + r + "</table>";
201 }
202
203 if ( ! a.isEmpty() ) {
204 s += i18n("<h2>Accelerators added (just for your info)</h2>");
205 s += "<table border><tr><th><b>New Text</b></th></tr>" + a + "</table>";
206 }
207
208 createDialog(actWin, automatic);
209 drklash_view->setText(s);
210 drklash->show();
211 drklash->raise();
212
213 // dlg will be destroyed before returning
214}
215
216#include "kcheckaccelerators.moc"
TDEAcceleratorManager::manage
static void manage(TQWidget *widget)
Manages the accelerators of a widget.
Definition: tdeaccelmanager.cpp:449
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
Definition: tdeconfigbase.cpp:221
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
Definition: tdeconfigbase.cpp:748
TDEConfigGroupSaver
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Definition: tdeconfigbase.h:2083
TDEGlobal::config
static TDEConfig * config()
Returns the general config object.
Definition: tdeglobal.cpp:65
TDELocale::i18n
TQString i18n(const char *text)
i18n is the function that does everything you need to translate a string.
Definition: tdelocale.cpp:1976
TDEShortcut
The TDEShortcut class is used to represent a keyboard shortcut to an action.
Definition: tdeshortcut.h:544
KStdAction::close
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEStdAccel::key
int key(StdAccel id)
Definition: tdestdaccel.cpp:383
tdelocale.h

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.