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(Q_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 )
68 :
KDialogBase( parent, name, true, i18n(
"Configure Shortcut"),
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;
92 m_simple->m_btnClearShortcut->setPixmap( SmallIcon(
"locationbar_erase" ) );
93 m_adv->m_btnClearPrimary->setPixmap( SmallIcon(
"locationbar_erase" ) );
94 m_adv->m_btnClearAlternate->setPixmap( SmallIcon(
"locationbar_erase" ) );
95 connect(m_simple->m_btnClearShortcut, TQT_SIGNAL(clicked()),
96 this, TQT_SLOT(slotClearShortcut()));
97 connect(m_adv->m_btnClearPrimary, TQT_SIGNAL(clicked()),
98 this, TQT_SLOT(slotClearPrimary()));
99 connect(m_adv->m_btnClearAlternate, TQT_SIGNAL(clicked()),
100 this, TQT_SLOT(slotClearAlternate()));
102 connect(m_adv->m_txtPrimary, TQT_SIGNAL(clicked()),
103 m_adv->m_btnPrimary, TQT_SLOT(animateClick()));
104 connect(m_adv->m_txtAlternate, TQT_SIGNAL(clicked()),
105 m_adv->m_btnAlternate, TQT_SLOT(animateClick()));
106 connect(m_adv->m_btnPrimary, TQT_SIGNAL(clicked()),
107 this, TQT_SLOT(slotSelectPrimary()));
108 connect(m_adv->m_btnAlternate, TQT_SIGNAL(clicked()),
109 this, TQT_SLOT(slotSelectAlternate()));
112 ok.setText( i18n(
"OK" ) );
115 KGuiItem cancel = KStdGuiItem::cancel();
116 cancel.setText( i18n(
"Cancel" ) );
117 setButtonCancel( cancel );
119 setShortcut( shortcut );
126 kapp->installX11EventFilter(
this );
130 TDEShortcutDialog::~TDEShortcutDialog()
133 group.writeEntry(
"ShowAlternativeShortcutConfig", s_showMore);
136 void TDEShortcutDialog::setShortcut(
const TDEShortcut & shortcut )
138 m_shortcut = shortcut;
139 updateShortcutDisplay();
142 void TDEShortcutDialog::updateShortcutDisplay()
147 m_ptxtCurrent->setDefault(
true );
148 m_ptxtCurrent->setFocus();
158 s[m_iSeq] = keyModStr;
167 m_adv->m_txtPrimary->setDefault(
false );
168 m_adv->m_txtAlternate->setDefault(
false );
172 s[0].replace(
'&', TQString::fromLatin1(
"&&"));
173 s[1].replace(
'&', TQString::fromLatin1(
"&&"));
175 m_simple->m_txtShortcut->setText( s[0] );
176 m_adv->m_txtPrimary->setText( s[0] );
177 m_adv->m_txtAlternate->setText( s[1] );
182 if( m_shortcut.
count() == 0 )
185 else if( m_shortcut.
count() == 1 && m_shortcut.
seq(0).
count() <= 1 )
193 void TDEShortcutDialog::slotDetails()
195 s_showMore = (m_adv->isHidden());
199 void TDEShortcutDialog::updateDetails()
201 bool showAdvanced = s_showMore || (m_shortcut.
count() > 1);
203 m_bRecording =
false;
211 m_adv->m_btnPrimary->setChecked(
true );
216 m_ptxtCurrent = m_simple->m_txtShortcut;
219 m_simple->m_txtShortcut->setDefault(
true );
220 m_simple->m_txtShortcut->setFocus();
221 m_adv->m_btnMultiKey->setChecked(
false );
223 kapp->processEvents();
227 void TDEShortcutDialog::slotSelectPrimary()
229 m_bRecording =
false;
232 m_ptxtCurrent = m_adv->m_txtPrimary;
233 m_ptxtCurrent->setDefault(
true);
234 m_ptxtCurrent->setFocus();
235 updateShortcutDisplay();
238 void TDEShortcutDialog::slotSelectAlternate()
240 m_bRecording =
false;
243 m_ptxtCurrent = m_adv->m_txtAlternate;
244 m_ptxtCurrent->setDefault(
true);
245 m_ptxtCurrent->setFocus();
246 updateShortcutDisplay();
249 void TDEShortcutDialog::slotClearShortcut()
252 updateShortcutDisplay();
255 void TDEShortcutDialog::slotClearPrimary()
258 m_adv->m_btnPrimary->setChecked(
true );
262 void TDEShortcutDialog::slotClearAlternate()
264 if( m_shortcut.
count() == 2 )
265 m_shortcut.
init( m_shortcut.
seq(0) );
266 m_adv->m_btnAlternate->setChecked(
true );
267 slotSelectAlternate();
270 void TDEShortcutDialog::slotMultiKeyMode(
bool bOn )
273 if( !bOn && m_bRecording ) {
274 m_bRecording =
false;
276 updateShortcutDisplay();
284 bool TDEShortcutDialog::x11Event( XEvent *pEvent )
286 switch( pEvent->type ) {
288 x11KeyPressEvent( pEvent );
291 x11KeyReleaseEvent( pEvent );
315 return KDialogBase::x11Event( pEvent );
318 static uint getModsFromModX( uint keyModX )
321 if( keyModX & KKeyNative::modX(KKey::SHIFT) ) mod += KKey::SHIFT;
322 if( keyModX & KKeyNative::modX(KKey::CTRL) ) mod += KKey::CTRL;
323 if( keyModX & KKeyNative::modX(KKey::ALT) ) mod += KKey::ALT;
324 if( keyModX & KKeyNative::modX(KKey::WIN) ) mod += KKey::WIN;
328 static bool convertSymXToMod( uint keySymX, uint* pmod )
334 case XK_Shift_L:
case XK_Shift_R: *pmod = KKey::SHIFT;
break;
335 case XK_Control_L:
case XK_Control_R: *pmod = KKey::CTRL;
break;
336 case XK_Alt_L:
case XK_Alt_R: *pmod = KKey::ALT;
break;
338 case XK_Meta_L:
case XK_Meta_R:
339 case XK_Super_L:
case XK_Super_R: *pmod = KKey::WIN;
break;
340 case XK_Hyper_L:
case XK_Hyper_R:
351 void TDEShortcutDialog::x11KeyPressEvent( XEvent* pEvent )
354 uint keyModX = keyNative.mod();
355 uint keySymX = keyNative.sym();
357 m_mod = getModsFromModX( keyModX );
363 if( convertSymXToMod( keySymX, &mod ) ) {
368 keyPressed(
KKey(keyNative) );
370 updateShortcutDisplay();
373 void TDEShortcutDialog::x11KeyReleaseEvent( XEvent* pEvent )
377 if( m_bRecording && m_iKey == 0 ) {
379 uint keyModX = keyNative.mod();
380 uint keySymX = keyNative.sym();
382 m_mod = getModsFromModX( keyModX );
385 if( convertSymXToMod( keySymX, &mod ) && mod ) {
388 m_bRecording =
false;
390 updateShortcutDisplay();
393 #elif defined(Q_WS_WIN)
396 kdDebug() << e->text() <<
" " << (int)e->text()[0].latin1()<<
" " << (int)e->ascii() <<
endl;
398 int keyQt = TQChar( e->key() & 0xff ).isLetter() ?
399 (TQChar( e->key() & 0xff ).lower().latin1() | (e->key() & 0xffff00) )
403 m_mod = keyNative.mod();
404 uint keySym = keyNative.sym();
408 m_mod |= KKey::SHIFT;
423 if( keyNative.sym() == Key_Return && m_iKey > 0 ) {
428 if (keyNative.sym()) {
435 seq = m_shortcut.
seq( m_iSeq );
436 seq.
setKey( m_iKey, key );
438 m_shortcut.
setSeq( m_iSeq, seq );
440 if(m_adv->m_btnMultiKey->isChecked())
445 updateShortcutDisplay();
447 if( !m_adv->m_btnMultiKey->isChecked() )
448 TQTimer::singleShot(500,
this, TQT_SLOT(accept()));
456 updateShortcutDisplay();
460 bool TDEShortcutDialog::event ( TQEvent * e )
462 if (e->type()==TQEvent::KeyRelease) {
464 KKeyNative keyNative(
KKey(static_cast<TQKeyEvent*>(e)->key(), modQt) );
465 uint keySym = keyNative.sym();
470 if (m_mod & KKey::SHIFT)
471 m_mod ^= KKey::SHIFT;
474 if (m_mod & KKey::CTRL)
478 if (m_mod & KKey::ALT)
485 updateShortcutDisplay();
487 return KDialogBase::event(e);
491 void TDEShortcutDialog::keyPressed(
KKey key )
496 if( m_bQtShortcut ) {
508 key.
init( key.sym(), 0 );
509 seq = m_shortcut.
seq( m_iSeq );
510 seq.
setKey( m_iKey, key );
513 m_shortcut.
setSeq( m_iSeq, seq );
516 if( m_adv->m_btnMultiKey->isChecked() && m_iKey < KKeySequence::MAX_KEYS - 1 )
520 m_bRecording =
false;
523 updateShortcutDisplay();
525 if( !m_adv->m_btnMultiKey->isChecked() )
526 TQTimer::singleShot(500,
this, TQT_SLOT(accept()));
529 #include "tdeshortcutdialog.moc"
const KKeySequence & seq(uint i) const
int key(StdAccel) KDE_DEPRECATED
bool setKey(uint i, const KKey &key)
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
kdbgstream kdDebug(int area=0)
TQString toString() const
A dialog base class with standard buttons and predefined layouts.
An abstract class for GUI data such as ToolTip and Icon.
void setDetails(bool showDetails)
Sets the status of the Details button.
TQString toString() const
int qtButtonStateToMod(TQ_ButtonState s)
virtual void keyPressEvent(TQKeyEvent *e)
Maps some keys to the actions buttons.
bool setSeq(uint i, const KKeySequence &keySeq)
static TQString modFlagLabel(ModFlag f)
static TDEConfig * config()
kndbgstream & endl(kndbgstream &s)
virtual void adjustSize()
Adjust the size of the dialog to fit the contents just before TQDialog::exec() or TQDialog::show() is...