22 #define INCLUDE_MENUITEM_DEF
28 #include <QApplication>
31 #include <QShortcutEvent>
32 #include <QMouseEvent>
35 #include <QMetaObject>
36 #include <QPushButton>
61 if( !sKey.isEmpty() ) {
66 bool autoCheck = cg.
readEntry(
"AutoCheckAccelerators",
true );
67 bool copyWidgetText = cg.
readEntry(
"CopyWidgetText",
false );
69 if (!copyWidgetText && key==0 && !autoCheck)
75 KCheckAccelerators::KCheckAccelerators(
QObject* parent,
int key_,
bool autoCheck_,
bool copyWidgetText_)
79 , autoCheck(autoCheck_)
80 , copyWidgetText(copyWidgetText_)
83 setObjectName(
"kapp_accel_filter" );
86 alwaysShow = cg.readEntry(
"AlwaysShowCheckAccelerators",
false );
87 copyWidgetTextCommand = cg.readEntry(
"CopyWidgetTextCommand",
"" );
89 parent->installEventFilter(
this );
90 connect( &autoCheckTimer, SIGNAL(
timeout()), SLOT(autoCheckSlot()));
98 switch ( e->type() ) {
99 case QEvent::ShortcutOverride:
100 if ( key && (static_cast<QKeyEvent*>(e)->key() == key) ) {
102 checkAccelerators(
false );
108 case QEvent::ChildAdded:
109 case QEvent::ChildRemoved:
111 if ( !static_cast<QChildEvent *>(e)->child()->isWidgetType() )
115 case QEvent::LayoutRequest:
116 case QEvent::WindowActivate:
117 case QEvent::WindowDeactivate:
119 autoCheckTimer.setSingleShot(
true );
120 autoCheckTimer.start( 20 );
124 case QEvent::MouseButtonPress:
125 if ( copyWidgetText && static_cast<QMouseEvent*>(e)->button() == Qt::MidButton ) {
127 QWidget* w=
static_cast<QWidget*
>(obj)->childAt(static_cast<QMouseEvent*>(e)->pos());
134 if (qobject_cast<QLabel*>(w))
135 text=static_cast<QLabel*>(w)->text();
136 else if (qobject_cast<QAbstractButton*>(w))
137 text=
static_cast<QAbstractButton*
>(w)->text();
138 else if (qobject_cast<QComboBox*>(w))
139 text=static_cast<QComboBox*>(w)->currentText();
140 else if (qobject_cast<QTabBar*>(w))
141 text=
static_cast<QTabBar*
>(w)->tabText( static_cast<QTabBar*>(w)->tabAt(static_cast<QMouseEvent*>(e)->pos()) );
142 else if (qobject_cast<QGroupBox*>(w))
143 text=static_cast<QGroupBox*>(w)->title();
144 else if (qobject_cast<QMenu*>(obj))
146 QAction* a=
static_cast<QMenu*
>(obj)->actionAt(static_cast<QMouseEvent*>(e)->pos());
156 if (static_cast<QMouseEvent*>(e)->modifiers() == Qt::ControlModifier)
160 if (copyWidgetTextCommand.isEmpty())
162 QClipboard *clipboard = QApplication::clipboard();
163 clipboard->setText(text);
169 connect(script,SIGNAL(finished(
int,QProcess::ExitStatus)),script,SLOT(deleteLater()));
178 case QEvent::MouseMove:
188 void KCheckAccelerators::autoCheckSlot()
192 autoCheckTimer.setSingleShot(
true );
193 autoCheckTimer.start( 20 );
197 checkAccelerators( !alwaysShow );
201 void KCheckAccelerators::createDialog(
QWidget *actWin,
bool automatic)
206 drklash =
new QDialog( actWin );
207 drklash->setAttribute( Qt::WA_DeleteOnClose );
208 drklash->setObjectName(
"kapp_accel_check_dlg" );
209 drklash->setWindowTitle(
i18nc(
"@title:window",
"Dr. Klash' Accelerator Diagnosis" ));
210 drklash->resize( 500, 460 );
211 QVBoxLayout* layout =
new QVBoxLayout( drklash );
213 layout->addWidget( drklash_view);
214 QCheckBox* disableAutoCheck = NULL;
216 disableAutoCheck =
new QCheckBox(
i18nc(
"@option:check",
"Disable automatic checking" ), drklash );
217 connect(disableAutoCheck, SIGNAL(toggled(
bool)), SLOT(slotDisableCheck(
bool)));
218 layout->addWidget( disableAutoCheck );
221 btnClose->setDefault(
true );
222 layout->addWidget( btnClose );
223 connect( btnClose, SIGNAL(clicked()), drklash, SLOT(
close()) );
224 if (disableAutoCheck)
225 disableAutoCheck->setFocus();
227 drklash_view->setFocus();
230 void KCheckAccelerators::slotDisableCheck(
bool on)
237 void KCheckAccelerators::checkAccelerators(
bool automatic )
239 QWidget* actWin = qApp->activeWindow();
250 if (c.isEmpty() && r.isEmpty() && (automatic || a.isEmpty()))
255 if ( ! c.isEmpty() ) {
256 s +=
i18n(
"<h2>Accelerators changed</h2>");
257 s +=
"<table border><tr><th><b>Old Text</b></th><th><b>New Text</b></th></tr>"
261 if ( ! r.isEmpty() ) {
262 s +=
i18n(
"<h2>Accelerators removed</h2>");
263 s +=
"<table border><tr><th><b>Old Text</b></th></tr>" + r +
"</table>";
266 if ( ! a.isEmpty() ) {
267 s +=
i18n(
"<h2>Accelerators added (just for your info)</h2>");
268 s +=
"<table border><tr><th><b>New Text</b></th></tr>" + a +
"</table>";
271 createDialog(actWin, automatic);
272 drklash_view->setHtml(s);
279 #include "kcheckaccelerators.moc"
QString i18n(const char *text)
Defines platform-independent classes for keyboard shortcut handling.
QString i18nc(const char *ctxt, const char *text)
KSharedConfigPtr config()
Represents a keyboard shortcut.
static void last_manage(QString &added, QString &changed, QString &removed)
bool isEmpty() const
Returns whether this shortcut contains any nonempty key sequences.
KComponentData activeComponent()
bool eventFilter(QObject *, QEvent *e)
Re-implemented to filter the parent's events.
static void initiateIfNeeded(QObject *parent)
Creates a KCheckAccelerators instance for the given object if this feature is enabled in kdeglobals...
QKeySequence primary() const
Returns the primary key sequence of this shortcut.
T readEntry(const QString &key, const T &aDefault) const
static void manage(QWidget *widget, bool programmers_mode=false)
Manages the accelerators of a widget.
KAction * close(const QObject *recvr, const char *slot, QObject *parent)
Close the current document.