20 #include "tdeshortcutdialog.h"
22 #include <tqvariant.h>
28 #include <X11/keysymdef.h>
31 const int XKeyPress = KeyPress;
32 const int XKeyRelease = KeyRelease;
33 const int XFocusOut = FocusOut;
34 const int XFocusIn = FocusIn;
40 #elif defined(TQ_WS_WIN)
41 # include <kkeyserver.h>
44 #include <tdeshortcutdialog_simple.h>
45 #include <tdeshortcutdialog_advanced.h>
47 #include <tqbuttongroup.h>
48 #include <tqcheckbox.h>
51 #include <tqradiobutton.h>
55 #include <tdeapplication.h>
56 #include <tdeconfig.h>
58 #include <tdeglobal.h>
59 #include <kiconloader.h>
60 #include <kkeynative.h>
62 #include <kstdguiitem.h>
63 #include <kpushbutton.h>
65 bool TDEShortcutDialog::s_showMore =
false;
67 TDEShortcutDialog::TDEShortcutDialog(
const TDEShortcut& shortcut,
bool bQtShortcut, TQWidget* parent,
const char* name )
71 setButtonText(Details, i18n(
"Advanced"));
72 m_stack =
new TQVBox(
this);
73 m_stack->setMinimumWidth(360);
74 m_stack->setSpacing(0);
75 m_stack->setMargin(0);
76 setMainWidget(m_stack);
78 m_simple =
new TDEShortcutDialogSimple(m_stack);
80 m_adv =
new TDEShortcutDialogAdvanced(m_stack);
83 m_bQtShortcut = bQtShortcut;
91 m_simple->m_btnClearShortcut->setPixmap( SmallIcon(
"locationbar_erase" ) );
92 m_adv->m_btnClearPrimary->setPixmap( SmallIcon(
"locationbar_erase" ) );
93 m_adv->m_btnClearAlternate->setPixmap( SmallIcon(
"locationbar_erase" ) );
94 connect(m_simple->m_btnClearShortcut, TQ_SIGNAL(clicked()),
95 this, TQ_SLOT(slotClearShortcut()));
96 connect(m_adv->m_btnClearPrimary, TQ_SIGNAL(clicked()),
97 this, TQ_SLOT(slotClearPrimary()));
98 connect(m_adv->m_btnClearAlternate, TQ_SIGNAL(clicked()),
99 this, TQ_SLOT(slotClearAlternate()));
101 connect(m_adv->m_txtPrimary, TQ_SIGNAL(clicked()),
102 m_adv->m_btnPrimary, TQ_SLOT(animateClick()));
103 connect(m_adv->m_txtAlternate, TQ_SIGNAL(clicked()),
104 m_adv->m_btnAlternate, TQ_SLOT(animateClick()));
105 connect(m_adv->m_btnPrimary, TQ_SIGNAL(clicked()),
106 this, TQ_SLOT(slotSelectPrimary()));
107 connect(m_adv->m_btnAlternate, TQ_SIGNAL(clicked()),
108 this, TQ_SLOT(slotSelectAlternate()));
111 ok.setText( i18n(
"OK" ) );
114 KGuiItem cancel = KStdGuiItem::cancel();
115 cancel.setText( i18n(
"Cancel" ) );
116 setButtonCancel( cancel );
118 setShortcut( shortcut );
125 kapp->installX11EventFilter(
this );
129 TDEShortcutDialog::~TDEShortcutDialog()
132 group.writeEntry(
"ShowAlternativeShortcutConfig", s_showMore);
135 void TDEShortcutDialog::setShortcut(
const TDEShortcut & shortcut )
138 updateShortcutDisplay();
141 void TDEShortcutDialog::updateShortcutDisplay()
146 m_ptxtCurrent->setDefault(
true );
147 m_ptxtCurrent->setFocus();
157 s[m_iSeq] = keyModStr;
166 m_adv->m_txtPrimary->setDefault(
false );
167 m_adv->m_txtAlternate->setDefault(
false );
171 s[0].replace(
'&', TQString::fromLatin1(
"&&"));
172 s[1].replace(
'&', TQString::fromLatin1(
"&&"));
174 m_simple->m_txtShortcut->setText( s[0] );
175 m_adv->m_txtPrimary->setText( s[0] );
176 m_adv->m_txtAlternate->setText( s[1] );
181 if( m_shortcut.
count() == 0 )
184 else if( m_shortcut.
count() == 1 && m_shortcut.
seq(0).
count() <= 1 )
192 void TDEShortcutDialog::slotDetails()
194 s_showMore = (m_adv->isHidden());
198 void TDEShortcutDialog::updateDetails()
200 bool showAdvanced = s_showMore || (m_shortcut.
count() > 1);
202 m_bRecording =
false;
210 m_adv->m_btnPrimary->setChecked(
true );
215 m_ptxtCurrent = m_simple->m_txtShortcut;
218 m_simple->m_txtShortcut->setDefault(
true );
219 m_simple->m_txtShortcut->setFocus();
220 m_adv->m_btnMultiKey->setChecked(
false );
222 kapp->processEvents();
226 void TDEShortcutDialog::slotSelectPrimary()
228 m_bRecording =
false;
231 m_ptxtCurrent = m_adv->m_txtPrimary;
232 m_ptxtCurrent->setDefault(
true);
233 m_ptxtCurrent->setFocus();
234 updateShortcutDisplay();
237 void TDEShortcutDialog::slotSelectAlternate()
239 m_bRecording =
false;
242 m_ptxtCurrent = m_adv->m_txtAlternate;
243 m_ptxtCurrent->setDefault(
true);
244 m_ptxtCurrent->setFocus();
245 updateShortcutDisplay();
248 void TDEShortcutDialog::slotClearShortcut()
251 updateShortcutDisplay();
254 void TDEShortcutDialog::slotClearPrimary()
257 m_adv->m_btnPrimary->setChecked(
true );
261 void TDEShortcutDialog::slotClearAlternate()
263 if( m_shortcut.
count() == 2 )
264 m_shortcut.
init( m_shortcut.
seq(0) );
265 m_adv->m_btnAlternate->setChecked(
true );
266 slotSelectAlternate();
269 void TDEShortcutDialog::slotMultiKeyMode(
bool bOn )
272 if( !bOn && m_bRecording ) {
273 m_bRecording =
false;
275 updateShortcutDisplay();
283 bool TDEShortcutDialog::x11Event( XEvent *pEvent )
285 switch( pEvent->type ) {
287 x11KeyPressEvent( pEvent );
290 x11KeyReleaseEvent( pEvent );
294 XFocusInEvent *fie = (XFocusInEvent*)pEvent;
295 if (fie->mode != NotifyGrab && fie->mode != NotifyUngrab) {
302 XFocusOutEvent *foe = (XFocusOutEvent*)pEvent;
303 if (foe->mode != NotifyGrab && foe->mode != NotifyUngrab) {
312 return KDialogBase::x11Event( pEvent );
315 static uint getModsFromModX( uint keyModX )
318 if( keyModX & KKeyNative::modX(KKey::SHIFT) ) mod += KKey::SHIFT;
319 if( keyModX & KKeyNative::modX(KKey::CTRL) ) mod += KKey::CTRL;
320 if( keyModX & KKeyNative::modX(KKey::ALT) ) mod += KKey::ALT;
321 if( keyModX & KKeyNative::modX(KKey::WIN) ) mod += KKey::WIN;
325 static bool convertSymXToMod( uint keySymX, uint* pmod )
331 case XK_Shift_L:
case XK_Shift_R: *pmod = KKey::SHIFT;
break;
332 case XK_Control_L:
case XK_Control_R: *pmod = KKey::CTRL;
break;
333 case XK_Alt_L:
case XK_Alt_R: *pmod = KKey::ALT;
break;
335 case XK_Meta_L:
case XK_Meta_R:
336 case XK_Super_L:
case XK_Super_R: *pmod = KKey::WIN;
break;
337 case XK_Hyper_L:
case XK_Hyper_R:
348 void TDEShortcutDialog::x11KeyPressEvent( XEvent* pEvent )
351 uint keyModX = keyNative.mod();
352 uint keySymX = keyNative.sym();
354 m_mod = getModsFromModX( keyModX );
360 if( convertSymXToMod( keySymX, &mod ) ) {
365 keyPressed(
KKey(keyNative) );
367 updateShortcutDisplay();
370 void TDEShortcutDialog::x11KeyReleaseEvent( XEvent* pEvent )
374 if( m_bRecording && m_iKey == 0 ) {
376 uint keyModX = keyNative.mod();
377 uint keySymX = keyNative.sym();
379 m_mod = getModsFromModX( keyModX );
382 if( convertSymXToMod( keySymX, &mod ) && mod ) {
385 m_bRecording =
false;
387 updateShortcutDisplay();
390 #elif defined(TQ_WS_WIN)
393 kdDebug() << e->text() <<
" " << (int)e->text()[0].latin1()<<
" " << (int)e->ascii() <<
endl;
395 int keyQt = TQChar( e->key() & 0xff ).isLetter() ?
396 (TQChar( e->key() & 0xff ).lower().latin1() | (e->key() & 0xffff00) )
400 m_mod = keyNative.mod();
401 uint keySym = keyNative.sym();
405 m_mod |= KKey::SHIFT;
420 if( keyNative.sym() == Key_Return && m_iKey > 0 ) {
425 if (keyNative.sym()) {
432 seq = m_shortcut.
seq( m_iSeq );
433 seq.
setKey( m_iKey, key );
435 m_shortcut.
setSeq( m_iSeq, seq );
437 if(m_adv->m_btnMultiKey->isChecked())
442 updateShortcutDisplay();
444 if( !m_adv->m_btnMultiKey->isChecked() )
445 TQTimer::singleShot(500,
this, TQ_SLOT(accept()));
453 updateShortcutDisplay();
457 bool TDEShortcutDialog::event ( TQEvent * e )
459 if (e->type()==TQEvent::KeyRelease) {
462 uint keySym = keyNative.sym();
467 if (m_mod & KKey::SHIFT)
468 m_mod ^= KKey::SHIFT;
471 if (m_mod & KKey::CTRL)
475 if (m_mod & KKey::ALT)
482 updateShortcutDisplay();
484 return KDialogBase::event(e);
488 void TDEShortcutDialog::keyPressed(
KKey key )
493 if( m_bQtShortcut ) {
506 seq = m_shortcut.
seq( m_iSeq );
507 seq.
setKey( m_iKey, key );
510 m_shortcut.
setSeq( m_iSeq, seq );
513 if( m_adv->m_btnMultiKey->isChecked() && m_iKey < KKeySequence::MAX_KEYS - 1 )
517 m_bRecording =
false;
520 updateShortcutDisplay();
522 if( !m_adv->m_btnMultiKey->isChecked() )
523 TQTimer::singleShot(500,
this, TQ_SLOT(accept()));
526 #include "tdeshortcutdialog.moc"
A dialog base class with standard buttons and predefined layouts.
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
@ Details
Show Details button.
void setDetails(bool showDetails)
Sets the status of the Details button.
virtual void adjustSize()
Adjust the size of the dialog to fit the contents just before TQDialog::exec() or TQDialog::show() is...
virtual void keyPressEvent(TQKeyEvent *e)
Maps some keys to the actions buttons.
An abstract class for GUI data such as ToolTip and Icon.
bool setKey(uint i, const KKey &key)
TQString toString() const
static TQString modFlagLabel(ModFlag f)
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
static TDEConfig * config()
const KKeySequence & seq(uint i) const
bool setSeq(uint i, const KKeySequence &keySeq)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
int qtButtonStateToMod(TQt::ButtonState s)
TQString name(StdAccel id)
const TDEShortcut & shortcut(StdAccel id)