00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define INCLUDE_MENUITEM_DEF
00024 #include <tqmenudata.h>
00025
00026 #include "config.h"
00027
00028 #include "kcheckaccelerators.h"
00029 #include "tdeaccelmanager.h"
00030 #include <tqpopupmenu.h>
00031 #include <tqapplication.h>
00032 #include <tqdialog.h>
00033 #include <tqlayout.h>
00034 #include <tqtextview.h>
00035 #include <tqobjectlist.h>
00036 #include <tqmenubar.h>
00037 #include <tqtabbar.h>
00038 #include <tqpushbutton.h>
00039 #include <tqmetaobject.h>
00040 #include <tqcheckbox.h>
00041
00042 #include <tdeconfig.h>
00043 #include <kdebug.h>
00044 #include <tdeglobal.h>
00045 #include <tdeshortcut.h>
00046 #include <tdelocale.h>
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 KCheckAccelerators::KCheckAccelerators( TQObject* parent )
00080 : TQObject( parent, "kapp_accel_filter" ), key(0), block( false ), drklash(0)
00081 {
00082 parent->installEventFilter( this );
00083 TDEConfigGroupSaver saver( TDEGlobal::config(), "Development" );
00084 TQString sKey = TDEGlobal::config()->readEntry( "CheckAccelerators" ).stripWhiteSpace();
00085 if( !sKey.isEmpty() ) {
00086 TDEShortcut cuts( sKey );
00087 if( cuts.count() > 0 )
00088 key = int(cuts.seq(0).qt());
00089 }
00090 alwaysShow = TDEGlobal::config()->readBoolEntry( "AlwaysShowCheckAccelerators", false );
00091 autoCheck = TDEGlobal::config()->readBoolEntry( "AutoCheckAccelerators", true );
00092 connect( &autoCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( autoCheckSlot()));
00093 }
00094
00095 bool KCheckAccelerators::eventFilter( TQObject * , TQEvent * e)
00096 {
00097 if ( block )
00098 return false;
00099
00100 switch ( e->type() ) {
00101 case TQEvent::Accel:
00102 if ( key && (TQT_TQKEYEVENT(e)->key() == key) ) {
00103 block = true;
00104 checkAccelerators( false );
00105 block = false;
00106 TQT_TQKEYEVENT(e)->accept();
00107 return true;
00108 }
00109 break;
00110 case TQEvent::ChildInserted:
00111 case TQEvent::ChildRemoved:
00112 case TQEvent::Resize:
00113 case TQEvent::LayoutHint:
00114 case TQEvent::WindowActivate:
00115 case TQEvent::WindowDeactivate:
00116 if( autoCheck )
00117 autoCheckTimer.start( 20, true );
00118 break;
00119 case TQEvent::Timer:
00120 case TQEvent::MouseMove:
00121 case TQEvent::Paint:
00122 return false;
00123 default:
00124
00125 break;
00126 }
00127 return false;
00128 }
00129
00130 void KCheckAccelerators::autoCheckSlot()
00131 {
00132 if( block )
00133 {
00134 autoCheckTimer.start( 20, true );
00135 return;
00136 }
00137 block = true;
00138 checkAccelerators( !alwaysShow );
00139 block = false;
00140 }
00141
00142 void KCheckAccelerators::createDialog(TQWidget *actWin, bool automatic)
00143 {
00144 if ( drklash )
00145 return;
00146
00147 drklash = new TQDialog( actWin, "kapp_accel_check_dlg", false, (WFlags)TQt::WDestructiveClose);
00148 drklash->setCaption( i18n( "Dr. Klash' Accelerator Diagnosis" ));
00149 drklash->resize( 500, 460 );
00150 TQVBoxLayout* layout = new TQVBoxLayout( drklash, 11, 6 );
00151 layout->setAutoAdd( true );
00152 drklash_view = new TQTextView( drklash );
00153 TQCheckBox* disableAutoCheck = NULL;
00154 if( automatic ) {
00155 disableAutoCheck = new TQCheckBox( i18n( "&Disable automatic checking" ), drklash );
00156 connect(disableAutoCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotDisableCheck(bool)));
00157 }
00158 TQPushButton* btnClose = new TQPushButton( i18n( "&Close" ), drklash );
00159 btnClose->setDefault( true );
00160 connect( btnClose, TQT_SIGNAL( clicked() ), drklash, TQT_SLOT( close() ) );
00161 if (disableAutoCheck)
00162 disableAutoCheck->setFocus();
00163 else
00164 drklash_view->setFocus();
00165 }
00166
00167 void KCheckAccelerators::slotDisableCheck(bool on)
00168 {
00169 autoCheck = !on;
00170 if (!on)
00171 autoCheckSlot();
00172 }
00173
00174 void KCheckAccelerators::checkAccelerators( bool automatic )
00175 {
00176 TQWidget* actWin = TQT_TQWIDGET(tqApp->activeWindow());
00177 if ( !actWin )
00178 return;
00179
00180 TDEAcceleratorManager::manage(actWin);
00181 TQString a, c, r;
00182 TDEAcceleratorManager::last_manage(a, c, r);
00183
00184 if (automatic)
00185 return;
00186
00187 if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty()))
00188 return;
00189
00190 TQString s;
00191
00192 if ( ! c.isEmpty() ) {
00193 s += i18n("<h2>Accelerators changed</h2>");
00194 s += "<table border><tr><th><b>Old Text</b></th><th><b>New Text</b></th></tr>"
00195 + c + "</table>";
00196 }
00197
00198 if ( ! r.isEmpty() ) {
00199 s += i18n("<h2>Accelerators removed</h2>");
00200 s += "<table border><tr><th><b>Old Text</b></th></tr>" + r + "</table>";
00201 }
00202
00203 if ( ! a.isEmpty() ) {
00204 s += i18n("<h2>Accelerators added (just for your info)</h2>");
00205 s += "<table border><tr><th><b>New Text</b></th></tr>" + a + "</table>";
00206 }
00207
00208 createDialog(actWin, automatic);
00209 drklash_view->setText(s);
00210 drklash->show();
00211 drklash->raise();
00212
00213
00214 }
00215
00216 #include "kcheckaccelerators.moc"