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" ),
key(0), block( false ), drklash(0)
00081 {
00082 parent->installEventFilter(
this );
00083
KConfigGroupSaver saver( KGlobal::config(),
"Development" );
00084
QString sKey =
KGlobal::config()->
readEntry(
"CheckAccelerators" ).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",
false );
00091 autoCheck =
KGlobal::config()->
readBoolEntry(
"AutoCheckAccelerators",
true );
00092 connect( &autoCheckTimer, SIGNAL( timeout()), SLOT( autoCheckSlot()));
00093 }
00094
00095
bool KCheckAccelerators::eventFilter(
QObject * ,
QEvent * e)
00096 {
00097
if ( block )
00098
return false;
00099
00100
switch ( e->type() ) {
00101
case QEvent::Accel:
00102
if (
key && (static_cast<QKeyEvent *>(e)->key() ==
key) ) {
00103 block =
true;
00104 checkAccelerators(
false );
00105 block =
false;
00106 static_cast<QKeyEvent *>(e)->accept();
00107
return true;
00108 }
00109
break;
00110
case QEvent::ChildInserted:
00111
case QEvent::ChildRemoved:
00112
case QEvent::Resize:
00113
case QEvent::LayoutHint:
00114
case QEvent::WindowActivate:
00115
case QEvent::WindowDeactivate:
00116
if( autoCheck )
00117 autoCheckTimer.start( 20,
true );
00118
break;
00119
case QEvent::Timer:
00120
case QEvent::MouseMove:
00121
case QEvent::Paint:
00122
return false;
00123
default:
00124
00125
break;
00126 }
00127
return false;
00128 }
00129
00130
void KCheckAccelerators::autoCheckSlot()
00131 {
00132
if( block || QWidget::mouseGrabber() ||
00133 QWidget::keyboardGrabber() ||
00134 QApplication::activePopupWidget())
00135 {
00136 autoCheckTimer.start( 20,
true );
00137
return;
00138 }
00139 block =
true;
00140 checkAccelerators( !alwaysShow );
00141 block =
false;
00142 }
00143
00144
void KCheckAccelerators::createDialog(
QWidget *actWin,
bool automatic)
00145 {
00146
if ( drklash )
00147
return;
00148
00149 drklash =
new QDialog( actWin,
"kapp_accel_check_dlg",
false, Qt::WDestructiveClose);
00150 drklash->setCaption( i18n(
"Dr. Klash' Accelerator Diagnosis" ));
00151 drklash->resize( 500, 460 );
00152
QVBoxLayout* layout =
new QVBoxLayout( drklash, 11, 6 );
00153 layout->setAutoAdd(
true );
00154 drklash_view =
new QTextView( drklash );
00155
QCheckBox* disableAutoCheck = NULL;
00156
if( automatic ) {
00157 disableAutoCheck =
new QCheckBox( i18n(
"&Disable automatic checking" ), drklash );
00158 connect(disableAutoCheck, SIGNAL(toggled(
bool)), SLOT(slotDisableCheck(
bool)));
00159 }
00160
QPushButton* btnClose =
new QPushButton( i18n(
"&Close" ), drklash );
00161 btnClose->setDefault(
true );
00162 connect( btnClose, SIGNAL( clicked() ), drklash, SLOT(
close() ) );
00163
if (disableAutoCheck)
00164 disableAutoCheck->setFocus();
00165
else
00166 drklash_view->setFocus();
00167 }
00168
00169
void KCheckAccelerators::slotDisableCheck(
bool on)
00170 {
00171 autoCheck = !on;
00172
if (!on)
00173 autoCheckSlot();
00174 }
00175
00176
void KCheckAccelerators::checkAccelerators(
bool automatic )
00177 {
00178
QWidget* actWin = qApp->activeWindow();
00179
if ( !actWin )
00180
return;
00181
00182
KAcceleratorManager::manage(actWin);
00183
QString a, c, r;
00184 KAcceleratorManager::last_manage(a, c, r);
00185
00186
if (automatic)
00187
return;
00188
00189
if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty()))
00190
return;
00191
00192
QString s;
00193
00194
if ( ! c.isEmpty() ) {
00195 s += i18n(
"<h2>Accelerators changed</h2>");
00196 s +=
"<table border><tr><th><b>Old Text</b></th><th><b>New Text</b></th></tr>"
00197 + c +
"</table>";
00198 }
00199
00200
if ( ! r.isEmpty() ) {
00201 s += i18n(
"<h2>Accelerators removed</h2>");
00202 s +=
"<table border><tr><th><b>Old Text</b></th></tr>" + r +
"</table>";
00203 }
00204
00205
if ( ! a.isEmpty() ) {
00206 s += i18n(
"<h2>Accelerators added (just for your info)</h2>");
00207 s +=
"<table border><tr><th><b>New Text</b></th></tr>" + a +
"</table>";
00208 }
00209
00210 createDialog(actWin, automatic);
00211 drklash_view->setText(s);
00212 drklash->show();
00213 drklash->raise();
00214
00215
00216 }
00217
00218
#include "kcheckaccelerators.moc"