kcheckaccelerators.cpp
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 <qmenudata.h>
00025
00026 #include "config.h"
00027
00028 #include "kcheckaccelerators.h"
00029 #include "kaccelmanager.h"
00030 #include <qpopupmenu.h>
00031 #include <qapplication.h>
00032 #include <qdialog.h>
00033 #include <qlayout.h>
00034 #include <qtextview.h>
00035 #include <qobjectlist.h>
00036 #include <qmenubar.h>
00037 #include <qtabbar.h>
00038 #include <qpushbutton.h>
00039 #include <qmetaobject.h>
00040 #include <qcheckbox.h>
00041
00042 #include <kconfig.h>
00043 #include <kdebug.h>
00044 #include <kglobal.h>
00045 #include <kshortcut.h>
00046 #include <klocale.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( QObject* parent )
00080 : QObject( parent, "kapp_accel_filter" ), block( false ), drklash(0)
00081 {
00082 parent->installEventFilter( this );
00083 KConfigGroupSaver saver( KGlobal::config(), "Development" );
00084 QString sKey = KGlobal::config()->readEntry( "CheckAccelerators", "F12" ).stripWhiteSpace();
00085 if( !sKey.isEmpty() ) {
00086 KShortcut cuts( sKey );
00087 if( cuts.count() > 0 )
00088 key = int(cuts.seq(0).qt());
00089 }
00090 alwaysShow = KGlobal::config()->readBoolEntry( "AlwaysShowCheckAccelerators", true );
00091 autoCheck = KGlobal::config()->readBoolEntry( "AutoCheckAccelerators", true );
00092 connect( &autoCheckTimer, SIGNAL( timeout()), SLOT( autoCheckSlot()));
00093 }
00094
00095 bool KCheckAccelerators::eventFilter( QObject * , QEvent * e) {
00096 if ( block )
00097 return false;
00098 if ( e->type() == QEvent::Accel ) {
00099 if ( static_cast<QKeyEvent *>(e)->key() == key ) {
00100 block = true;
00101 checkAccelerators( false );
00102 block = false;
00103 static_cast<QKeyEvent *>(e)->accept();
00104 return true;
00105 }
00106 }
00107 if( autoCheck
00108 && ( e->type() == QEvent::ChildInserted ||
00109 e->type() == QEvent::ChildRemoved ))
00110 {
00111 autoCheckTimer.start( 100, true );
00112 }
00113 return false;
00114 }
00115
00116 void KCheckAccelerators::autoCheckSlot()
00117 {
00118 if( block || QWidget::mouseGrabber() ||
00119 QWidget::keyboardGrabber() ||
00120 QApplication::activePopupWidget())
00121 {
00122 autoCheckTimer.start( 100, true );
00123 return;
00124 }
00125 block = true;
00126 checkAccelerators( true );
00127 block = false;
00128 }
00129
00130 void KCheckAccelerators::createDialog(QWidget *actWin, bool automatic)
00131 {
00132 if ( drklash )
00133 return;
00134
00135 drklash = new QDialog( actWin, "kapp_accel_check_dlg", false, Qt::WDestructiveClose);
00136 drklash->setCaption( i18n( "Dr. Klash' Accelerator Diagnosis" ));
00137 drklash->resize( 500, 460 );
00138 QVBoxLayout* layout = new QVBoxLayout( drklash, 11, 6 );
00139 layout->setAutoAdd( true );
00140 drklash_view = new QTextView( drklash );
00141 QCheckBox* disableAutoCheck = NULL;
00142 if( automatic ) {
00143 disableAutoCheck = new QCheckBox( i18n( "&Disable automatic checking" ), drklash );
00144 connect(disableAutoCheck, SIGNAL(toggled(bool)), SLOT(slotDisableCheck(bool)));
00145 }
00146 QPushButton* btnClose = new QPushButton( i18n( "&Close" ), drklash );
00147 btnClose->setDefault( true );
00148 connect( btnClose, SIGNAL( clicked() ), drklash, SLOT( close() ) );
00149 if (disableAutoCheck)
00150 disableAutoCheck->setFocus();
00151 else
00152 drklash_view->setFocus();
00153 }
00154
00155 void KCheckAccelerators::slotDisableCheck(bool on)
00156 {
00157 autoCheck = !on;
00158 if (!on)
00159 autoCheckSlot();
00160 }
00161
00162 void KCheckAccelerators::checkAccelerators( bool automatic ) {
00163 QWidget* actWin = qApp->activeWindow();
00164 if ( !actWin )
00165 return;
00166
00167 KAcceleratorManager::manage(actWin);
00168 QString a, c, r;
00169 KAcceleratorManager::last_manage(a, c, r);
00170 if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty()))
00171 return;
00172
00173 QString s;
00174
00175 if ( ! c.isEmpty() ) {
00176 s += i18n("<h2>Accelerators changed</h2>");
00177 s += "<table border><tr><th><b>Old Text</b></th><th><b>New Text</b></th></tr>"
00178 + c + "</table>";
00179 }
00180
00181 if ( ! r.isEmpty() ) {
00182 s += i18n("<h2>Accelerators removed</h2>");
00183 s += "<table border><tr><th><b>Old Text</b></th></tr>" + r + "</table>";
00184 }
00185
00186 if ( ! a.isEmpty() ) {
00187 s += i18n("<h2>Accelerators added (just for your info)</h2>");
00188 s += "<table border><tr><th><b>New Text</b></th></tr>" + a + "</table>";
00189 }
00190
00191 createDialog(actWin, automatic);
00192 drklash_view->setText(s);
00193 drklash->show();
00194 drklash->raise();
00195
00196
00197 }
00198
00199 #include "kcheckaccelerators.moc"
This file is part of the documentation for kdecore Library Version 3.2.2.