kkeydialog.cpp
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1998 Mark Donohoe <donohoe@kde.org> 00003 Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org> 00004 Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org> 00005 Copyright (C) 2001 Ellis Whitehead <ellis@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "kkeydialog.h" 00024 #include "kkeybutton.h" 00025 00026 #include <string.h> 00027 00028 #include <tqbuttongroup.h> 00029 #include <tqlabel.h> 00030 #include <tqlayout.h> 00031 #include <tqdrawutil.h> 00032 #include <tqpainter.h> 00033 #include <tqradiobutton.h> 00034 #include <tqregexp.h> 00035 #include <tqtoolbutton.h> 00036 #include <tqwhatsthis.h> 00037 00038 #include <tdeaccel.h> 00039 #include <tdeaction.h> 00040 #include <tdeaccelaction.h> 00041 #include <tdeactionshortcutlist.h> 00042 #include <tdeapplication.h> 00043 #include <tdeconfig.h> 00044 #include <kdebug.h> 00045 #include <tdeglobal.h> 00046 #include <kglobalaccel.h> 00047 #include <kiconloader.h> 00048 #include <tdelistviewsearchline.h> 00049 #include <tdelocale.h> 00050 #include <tdemessagebox.h> 00051 #include <tdeshortcut.h> 00052 #include <tdeshortcutlist.h> 00053 #include <kxmlguifactory.h> 00054 #include <tdeaboutdata.h> 00055 #include <kstaticdeleter.h> 00056 00057 #ifdef Q_WS_X11 00058 #define XK_XKB_KEYS 00059 #define XK_MISCELLANY 00060 #include <X11/Xlib.h> // For x11Event() 00061 #include <X11/keysymdef.h> // For XK_... 00062 #include <tqwhatsthis.h> 00063 00064 #ifdef KeyPress 00065 const int XFocusOut = FocusOut; 00066 const int XFocusIn = FocusIn; 00067 const int XKeyPress = KeyPress; 00068 const int XKeyRelease = KeyRelease; 00069 #undef KeyRelease 00070 #undef KeyPress 00071 #undef FocusOut 00072 #undef FocusIn 00073 #endif // KEYPRESS 00074 #endif // Q_WX_X11 00075 00076 //--------------------------------------------------------------------- 00077 // KKeyChooserItem 00078 //--------------------------------------------------------------------- 00079 00080 class KKeyChooserItem : public TDEListViewItem 00081 { 00082 public: 00083 KKeyChooserItem( TDEListView* parent, TQListViewItem* after, TDEShortcutList* pList, uint iAction ); 00084 KKeyChooserItem( TQListViewItem* parent, TQListViewItem* after, TDEShortcutList* pList, uint iAction ); 00085 00086 TQString actionName() const; 00087 const TDEShortcut& shortcut() const; 00088 bool isConfigurable() const 00089 { return m_pList->isConfigurable( m_iAction ); } 00090 const TDEShortcut& shortcutDefault() const 00091 { return m_pList->shortcutDefault( m_iAction ); } 00092 TQString whatsThis() const 00093 { return m_pList->whatsThis( m_iAction ); } 00094 00095 void setShortcut( const TDEShortcut& cut ); 00096 void commitChanges(); 00097 00098 virtual TQString text( int iCol ) const; 00099 virtual int compare( TQListViewItem*, int iCol, bool bAscending ) const; 00100 00101 protected: 00102 TDEShortcutList* m_pList; 00103 uint m_iAction; 00104 bool m_bModified; 00105 TDEShortcut m_cut; 00106 }; 00107 00108 // WhatsThis on KKeyChooserItems 00109 class KKeyChooserWhatsThis : public TQWhatsThis 00110 { 00111 public: 00112 KKeyChooserWhatsThis( TQListView* listview ) 00113 : TQWhatsThis( listview->viewport() ), m_listView( listview ) {} 00114 00115 protected: 00116 virtual TQString text( const TQPoint& p ); 00117 00118 private: 00119 TQListView* m_listView; 00120 }; 00121 00122 //--------------------------------------------------------------------- 00123 // KKeyChooserPrivate 00124 //--------------------------------------------------------------------- 00125 00126 class KKeyChooserPrivate 00127 { 00128 public: 00129 TQValueList<TDEShortcutList*> rgpLists; 00130 TQValueList<TDEShortcutList*> rgpListsAllocated; 00131 00132 TDEListView *pList; 00133 TQLabel *lInfo; 00134 KKeyButton *pbtnShortcut; 00135 TQGroupBox *fCArea; 00136 TQButtonGroup *kbGroup; 00137 00138 TQMap<TQString, TDEShortcut> mapGlobals; 00139 00140 // If this is set, then shortcuts require a modifier: 00141 // so 'A' would not be valid, whereas 'Ctrl+A' would be. 00142 // Note, however, that this only applies to printable characters. 00143 // 'F1', 'Insert', etc., could still be used. 00144 bool bAllowLetterShortcuts; 00145 // When set, pressing the 'Default' button will select the aDefaultKeycode4, 00146 // otherwise aDefaultKeycode. 00147 bool bPreferFourModifierKeys; 00148 }; 00149 00150 //--------------------------------------------------------------------- 00151 // KKeyChooser 00152 //--------------------------------------------------------------------- 00153 00154 KKeyChooser::KKeyChooser( TQWidget* parent, ActionType type, bool bAllowLetterShortcuts ) 00155 : TQWidget( parent ) 00156 { 00157 initGUI( type, bAllowLetterShortcuts ); 00158 } 00159 00160 KKeyChooser::KKeyChooser( TDEActionCollection* coll, TQWidget* parent, bool bAllowLetterShortcuts ) 00161 : TQWidget( parent ) 00162 { 00163 initGUI( Application, bAllowLetterShortcuts ); 00164 insert( coll ); 00165 } 00166 00167 KKeyChooser::KKeyChooser( TDEAccel* pAccel, TQWidget* parent, bool bAllowLetterShortcuts ) 00168 : TQWidget( parent ) 00169 { 00170 initGUI( Application, bAllowLetterShortcuts ); 00171 insert( pAccel ); 00172 } 00173 00174 KKeyChooser::KKeyChooser( TDEGlobalAccel* pAccel, TQWidget* parent ) 00175 : TQWidget( parent ) 00176 { 00177 initGUI( ApplicationGlobal, false ); 00178 insert( pAccel ); 00179 } 00180 00181 KKeyChooser::KKeyChooser( TDEShortcutList* pList, TQWidget* parent, ActionType type, bool bAllowLetterShortcuts ) 00182 : TQWidget( parent ) 00183 { 00184 initGUI( type, bAllowLetterShortcuts ); 00185 insert( pList ); 00186 } 00187 00188 KKeyChooser::KKeyChooser( TDEAccel* actions, TQWidget* parent, 00189 bool bCheckAgainstStdKeys, 00190 bool bAllowLetterShortcuts, 00191 bool bAllowWinKey ) 00192 : TQWidget( parent ) 00193 { 00194 ActionType type; 00195 if( bAllowWinKey ) 00196 type = (bCheckAgainstStdKeys) ? ApplicationGlobal : Global; 00197 else 00198 type = Application; 00199 00200 initGUI( type, bAllowLetterShortcuts ); 00201 insert( actions ); 00202 } 00203 00204 KKeyChooser::KKeyChooser( TDEGlobalAccel* actions, TQWidget* parent, 00205 bool bCheckAgainstStdKeys, 00206 bool bAllowLetterShortcuts, 00207 bool /*bAllowWinKey*/ ) 00208 : TQWidget( parent ) 00209 { 00210 ActionType type = (bCheckAgainstStdKeys) ? ApplicationGlobal : Global; 00211 00212 initGUI( type, bAllowLetterShortcuts ); 00213 insert( actions ); 00214 } 00215 00216 // list of all existing KKeyChooser's 00217 // Used when checking global shortcut for a possible conflict 00218 // (just checking against kdeglobals isn't enough, the shortcuts 00219 // might have changed in KKeyChooser and not being saved yet). 00220 // Also used when reassigning a shortcut from one chooser to another. 00221 static TQValueList< KKeyChooser* >* allChoosers = NULL; 00222 static KStaticDeleter< TQValueList< KKeyChooser* > > allChoosersDeleter; 00223 00224 KKeyChooser::~KKeyChooser() 00225 { 00226 allChoosers->remove( this ); 00227 // Delete allocated TDEShortcutLists 00228 for( uint i = 0; i < d->rgpListsAllocated.count(); i++ ) 00229 delete d->rgpListsAllocated[i]; 00230 delete d; 00231 } 00232 00233 bool KKeyChooser::insert( TDEActionCollection *pColl) 00234 { 00235 return insert(pColl, TQString::null); 00236 } 00237 00238 bool KKeyChooser::insert( TDEActionCollection* pColl, const TQString &title ) 00239 { 00240 TQString str = title; 00241 if ( title.isEmpty() && pColl->instance() 00242 && pColl->instance()->aboutData() ) 00243 str = pColl->instance()->aboutData()->programName(); 00244 00245 TDEShortcutList* pList = new TDEActionShortcutList( pColl ); 00246 d->rgpListsAllocated.append( pList ); 00247 d->rgpLists.append( pList ); 00248 buildListView(d->rgpLists.count() - 1, str); 00249 return true; 00250 } 00251 00252 bool KKeyChooser::insert( TDEAccel* pAccel ) 00253 { 00254 TDEShortcutList* pList = new TDEAccelShortcutList( pAccel ); 00255 d->rgpListsAllocated.append( pList ); 00256 return insert( pList ); 00257 } 00258 00259 bool KKeyChooser::insert( TDEGlobalAccel* pAccel ) 00260 { 00261 TDEShortcutList* pList = new TDEAccelShortcutList( pAccel ); 00262 d->rgpListsAllocated.append( pList ); 00263 return insert( pList ); 00264 } 00265 00266 bool KKeyChooser::insert( TDEShortcutList* pList ) 00267 { 00268 d->rgpLists.append( pList ); 00269 buildListView( d->rgpLists.count() - 1, TQString::null ); 00270 return true; 00271 } 00272 00273 void KKeyChooser::commitChanges() 00274 { 00275 kdDebug(125) << "KKeyChooser::commitChanges()" << endl; 00276 00277 TQListViewItemIterator it( d->pList ); 00278 for( ; it.current(); ++it ) { 00279 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>(it.current()); 00280 if( pItem ) 00281 pItem->commitChanges(); 00282 } 00283 } 00284 00285 void KKeyChooser::save() 00286 { 00287 commitChanges(); 00288 for( uint i = 0; i < d->rgpLists.count(); i++ ) 00289 d->rgpLists[i]->save(); 00290 } 00291 00292 void KKeyChooser::initGUI( ActionType type, bool bAllowLetterShortcuts ) 00293 { 00294 d = new KKeyChooserPrivate(); 00295 00296 m_type = type; 00297 d->bAllowLetterShortcuts = bAllowLetterShortcuts; 00298 00299 d->bPreferFourModifierKeys = TDEGlobalAccel::useFourModifierKeys(); 00300 00301 // 00302 // TOP LAYOUT MANAGER 00303 // 00304 // The following layout is used for the dialog 00305 // LIST LABELS LAYOUT 00306 // SPLIT LIST BOX WIDGET 00307 // CHOOSE KEY GROUP BOX WIDGET 00308 // BUTTONS LAYOUT 00309 // Items are added to topLayout as they are created. 00310 // 00311 00312 TQBoxLayout *topLayout = new TQVBoxLayout( this, 0, KDialog::spacingHint() ); 00313 00314 // 00315 // ADD SEARCHLINE 00316 // 00317 TQHBoxLayout* searchLayout = new TQHBoxLayout(0, 0, KDialog::spacingHint()); 00318 topLayout->addLayout(searchLayout, 10); 00319 00320 TQToolButton *clearSearch = new TQToolButton(this); 00321 clearSearch->setTextLabel(i18n("Clear Search"), true); 00322 clearSearch->setIconSet(SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase")); 00323 searchLayout->addWidget(clearSearch); 00324 TQLabel* slbl = new TQLabel(i18n("&Search:"), this); 00325 searchLayout->addWidget(slbl); 00326 TDEListViewSearchLine* listViewSearch = new TDEListViewSearchLine(this); 00327 searchLayout->addWidget(listViewSearch); 00328 slbl->setBuddy(listViewSearch); 00329 connect(clearSearch, TQT_SIGNAL(pressed()), listViewSearch, TQT_SLOT(clear())); 00330 00331 TQString wtstr = i18n("Search interactively for shortcut names (e.g. Copy) " 00332 "or combination of keys (e.g. Ctrl+C) by typing them here."); 00333 00334 TQWhatsThis::add(slbl, wtstr); 00335 TQWhatsThis::add(listViewSearch, wtstr); 00336 00337 // 00338 // CREATE SPLIT LIST BOX 00339 // 00340 // fill up the split list box with the action/key pairs. 00341 // 00342 TQGridLayout *stackLayout = new TQGridLayout(2, 2, 2); 00343 topLayout->addLayout( TQT_TQLAYOUT(stackLayout), 10 ); 00344 stackLayout->setRowStretch( 1, 10 ); // Only list will stretch 00345 00346 d->pList = new TDEListView( this ); 00347 listViewSearch->setListView(d->pList); // Plug into search line 00348 TQValueList<int> columns; 00349 columns.append(0); 00350 listViewSearch->setSearchColumns(columns); 00351 00352 stackLayout->addMultiCellWidget( d->pList, 1, 1, 0, 1 ); 00353 00354 wtstr = i18n("Here you can see a list of key bindings, " 00355 "i.e. associations between actions (e.g. 'Copy') " 00356 "shown in the left column and keys or combination " 00357 "of keys (e.g. Ctrl+V) shown in the right column."); 00358 00359 TQWhatsThis::add( d->pList, wtstr ); 00360 new KKeyChooserWhatsThis( d->pList ); 00361 00362 d->pList->setAllColumnsShowFocus( true ); 00363 d->pList->addColumn(i18n("Action")); 00364 d->pList->addColumn(i18n("Shortcut")); 00365 d->pList->addColumn(i18n("Alternate")); 00366 00367 connect( d->pList, TQT_SIGNAL(currentChanged(TQListViewItem*)), 00368 TQT_SLOT(slotListItemSelected(TQListViewItem*)) ); 00369 00370 // handle double clicking an item 00371 connect ( d->pList, TQT_SIGNAL ( doubleClicked ( TQListViewItem *, const TQPoint &, int ) ), 00372 TQT_SLOT ( captureCurrentItem()) ); 00373 connect ( d->pList, TQT_SIGNAL ( spacePressed( TQListViewItem* )), TQT_SLOT( captureCurrentItem())); 00374 // 00375 // CREATE CHOOSE KEY GROUP 00376 // 00377 d->fCArea = new TQGroupBox( this ); 00378 topLayout->addWidget( d->fCArea, 1 ); 00379 00380 d->fCArea->setTitle( i18n("Shortcut for Selected Action") ); 00381 d->fCArea->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain ); 00382 00383 // 00384 // CHOOSE KEY GROUP LAYOUT MANAGER 00385 // 00386 TQGridLayout *grid = new TQGridLayout( d->fCArea, 3, 4, KDialog::spacingHint() ); 00387 grid->addRowSpacing( 0, fontMetrics().lineSpacing() ); 00388 00389 d->kbGroup = new TQButtonGroup( d->fCArea ); 00390 d->kbGroup->hide(); 00391 d->kbGroup->setExclusive( true ); 00392 00393 m_prbNone = new TQRadioButton( i18n("no key", "&None"), d->fCArea ); 00394 d->kbGroup->insert( m_prbNone, NoKey ); 00395 m_prbNone->setEnabled( false ); 00396 //grid->addMultiCellWidget( rb, 1, 1, 1, 2 ); 00397 grid->addWidget( m_prbNone, 1, 0 ); 00398 TQWhatsThis::add( m_prbNone, i18n("The selected action will not be associated with any key.") ); 00399 connect( m_prbNone, TQT_SIGNAL(clicked()), TQT_SLOT(slotNoKey()) ); 00400 00401 m_prbDef = new TQRadioButton( i18n("default key", "De&fault"), d->fCArea ); 00402 d->kbGroup->insert( m_prbDef, DefaultKey ); 00403 m_prbDef->setEnabled( false ); 00404 //grid->addMultiCellWidget( rb, 2, 2, 1, 2 ); 00405 grid->addWidget( m_prbDef, 1, 1 ); 00406 TQWhatsThis::add( m_prbDef, i18n("This will bind the default key to the selected action. Usually a reasonable choice.") ); 00407 connect( m_prbDef, TQT_SIGNAL(clicked()), TQT_SLOT(slotDefaultKey()) ); 00408 00409 m_prbCustom = new TQRadioButton( i18n("C&ustom"), d->fCArea ); 00410 d->kbGroup->insert( m_prbCustom, CustomKey ); 00411 m_prbCustom->setEnabled( false ); 00412 //grid->addMultiCellWidget( rb, 3, 3, 1, 2 ); 00413 grid->addWidget( m_prbCustom, 1, 2 ); 00414 TQWhatsThis::add( m_prbCustom, i18n("If this option is selected you can create a customized key binding for the" 00415 " selected action using the buttons below.") ); 00416 connect( m_prbCustom, TQT_SIGNAL(clicked()), TQT_SLOT(slotCustomKey()) ); 00417 00418 //connect( d->kbGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( keyMode( int ) ) ); 00419 00420 TQBoxLayout *pushLayout = new TQHBoxLayout( KDialog::spacingHint() ); 00421 grid->addLayout( pushLayout, 1, 3 ); 00422 00423 d->pbtnShortcut = new KKeyButton(d->fCArea, "key"); 00424 d->pbtnShortcut->setEnabled( false ); 00425 connect( d->pbtnShortcut, TQT_SIGNAL(capturedShortcut(const TDEShortcut&)), TQT_SLOT(capturedShortcut(const TDEShortcut&)) ); 00426 grid->addRowSpacing( 1, d->pbtnShortcut->sizeHint().height() + 5 ); 00427 00428 wtstr = i18n("Use this button to choose a new shortcut key. Once you click it, " 00429 "you can press the key-combination which you would like to be assigned " 00430 "to the currently selected action."); 00431 TQWhatsThis::add( d->pbtnShortcut, wtstr ); 00432 00433 // 00434 // Add widgets to the geometry manager 00435 // 00436 pushLayout->addSpacing( KDialog::spacingHint()*2 ); 00437 pushLayout->addWidget( d->pbtnShortcut ); 00438 pushLayout->addStretch( 10 ); 00439 00440 d->lInfo = new TQLabel(d->fCArea); 00441 //resize(0,0); 00442 //d->lInfo->setAlignment( AlignCenter ); 00443 //d->lInfo->setEnabled( false ); 00444 //d->lInfo->hide(); 00445 grid->addMultiCellWidget( d->lInfo, 2, 2, 0, 3 ); 00446 00447 //d->globalDict = new TQDict<int> ( 100, false ); 00448 //d->globalDict->setAutoDelete( true ); 00449 readGlobalKeys(); 00450 //d->stdDict = new TQDict<int> ( 100, false ); 00451 //d->stdDict->setAutoDelete( true ); 00452 //if (type == Application || type == ApplicationGlobal) 00453 // readStdKeys(); 00454 connect( kapp, TQT_SIGNAL( settingsChanged( int )), TQT_SLOT( slotSettingsChanged( int ))); 00455 if( allChoosers == NULL ) 00456 allChoosers = allChoosersDeleter.setObject( allChoosers, new TQValueList< KKeyChooser* > ); 00457 allChoosers->append( this ); 00458 } 00459 00460 // Add all shortcuts to the list 00461 void KKeyChooser::buildListView( uint iList, const TQString &title ) 00462 { 00463 TDEShortcutList* pList = d->rgpLists[iList]; 00464 TDEActionShortcutList *pAList = dynamic_cast<TDEActionShortcutList*>(pList); 00465 00466 if( m_type == Global || m_type == ApplicationGlobal ) 00467 d->pList->setSorting( -1 ); 00468 TDEListViewItem *pProgramItem, *pGroupItem = 0, *pParentItem, *pItem; 00469 00470 TQString str = (title.isEmpty() ? i18n("Shortcuts") : title); 00471 pParentItem = pProgramItem = pItem = new TDEListViewItem( d->pList, str ); 00472 pParentItem->setExpandable( true ); 00473 pParentItem->setOpen( true ); 00474 pParentItem->setSelectable( false ); 00475 uint nSize = pList->count(); 00476 for( uint iAction = 0; iAction < nSize; iAction++ ) { 00477 TQString sName = pList->name(iAction); 00478 kdDebug(125) << "Key: " << sName << endl; 00479 if( sName.startsWith( "Program:" ) ) { 00480 pItem = new TDEListViewItem( d->pList, pProgramItem, pList->label(iAction) ); 00481 pItem->setSelectable( false ); 00482 pItem->setExpandable( true ); 00483 pItem->setOpen( true ); 00484 if( !pProgramItem->firstChild() ) 00485 delete pProgramItem; 00486 pProgramItem = pParentItem = pItem; 00487 } else if( sName.startsWith( "Group:" ) ) { 00488 pItem = new TDEListViewItem( pProgramItem, pParentItem, pList->label(iAction) ); 00489 pItem->setSelectable( false ); 00490 pItem->setExpandable( true ); 00491 pItem->setOpen( true ); 00492 if( pGroupItem && !pGroupItem->firstChild() ) 00493 delete pGroupItem; 00494 pGroupItem = pParentItem = pItem; 00495 } else if( !sName.isEmpty() && sName != "unnamed" && pList->isConfigurable(iAction) ) { 00496 pItem = new KKeyChooserItem( pParentItem, pItem, pList, iAction ); 00497 if(pAList) 00498 pItem->setPixmap(0,pAList->action(iAction)->iconSet().pixmap(TQIconSet::Small,TQIconSet::Normal)); 00499 } 00500 } 00501 if( !pProgramItem->firstChild() ) 00502 delete pProgramItem; 00503 if( pGroupItem && !pGroupItem->firstChild() ) 00504 delete pGroupItem; 00505 } 00506 00507 00508 void KKeyChooser::updateButtons() 00509 { 00510 // Hack: Do this incase we still have changeKey() running. 00511 // Better would be to capture the mouse pointer so that we can't click 00512 // around while we're supposed to be entering a key. 00513 // Better yet would be a modal dialog for changeKey()! 00514 releaseKeyboard(); 00515 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>( d->pList->currentItem() ); 00516 00517 if ( !pItem ) { 00518 // if nothing is selected -> disable radio boxes 00519 m_prbNone->setEnabled( false ); 00520 m_prbDef->setEnabled( false ); 00521 m_prbCustom->setEnabled( false ); 00522 d->pbtnShortcut->setEnabled( false ); 00523 d->pbtnShortcut->setShortcut( TDEShortcut(), false ); 00524 } else { 00525 bool bConfigurable = pItem->isConfigurable(); 00526 bool bQtShortcut = (m_type == Application || m_type == Standard); 00527 const TDEShortcut& cutDef = pItem->shortcutDefault(); 00528 00529 // Set key strings 00530 TQString keyStrCfg = pItem->shortcut().toString(); 00531 TQString keyStrDef = cutDef.toString(); 00532 00533 d->pbtnShortcut->setShortcut( pItem->shortcut(), bQtShortcut ); 00534 //item->setText( 1, keyStrCfg ); 00535 pItem->repaint(); 00536 d->lInfo->setText( i18n("Default key:") + TQString(" %1").arg(keyStrDef.isEmpty() ? i18n("None") : keyStrDef) ); 00537 00538 // Select the appropriate radio button. 00539 int index = (pItem->shortcut().isNull()) ? NoKey 00540 : (pItem->shortcut() == cutDef) ? DefaultKey 00541 : CustomKey; 00542 m_prbNone->setChecked( index == NoKey ); 00543 m_prbDef->setChecked( index == DefaultKey ); 00544 m_prbCustom->setChecked( index == CustomKey ); 00545 00546 // Enable buttons if this key is configurable. 00547 // The 'Default Key' button must also have a default key. 00548 m_prbNone->setEnabled( bConfigurable ); 00549 m_prbDef->setEnabled( bConfigurable && cutDef.count() != 0 ); 00550 m_prbCustom->setEnabled( bConfigurable ); 00551 d->pbtnShortcut->setEnabled( bConfigurable ); 00552 } 00553 } 00554 00555 void KKeyChooser::slotNoKey() 00556 { 00557 // return if no key is selected 00558 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>( d->pList->currentItem() ); 00559 if( pItem ) { 00560 //kdDebug(125) << "no Key" << d->pList->currentItem()->text(0) << endl; 00561 pItem->setShortcut( TDEShortcut() ); 00562 updateButtons(); 00563 emit keyChange(); 00564 } 00565 } 00566 00567 void KKeyChooser::slotDefaultKey() 00568 { 00569 // return if no key is selected 00570 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>( d->pList->currentItem() ); 00571 if( pItem ) // don't set it directly, check for conflicts 00572 setShortcut( pItem->shortcutDefault() ); 00573 } 00574 00575 void KKeyChooser::slotCustomKey() 00576 { 00577 d->pbtnShortcut->captureShortcut(); 00578 } 00579 00580 void KKeyChooser::readGlobalKeys() 00581 { 00582 d->mapGlobals.clear(); 00583 if( m_type == Global ) 00584 return; // they will be checked normally, because we're configuring them 00585 readGlobalKeys( d->mapGlobals ); 00586 } 00587 00588 void KKeyChooser::readGlobalKeys( TQMap< TQString, TDEShortcut >& map ) 00589 { 00590 TQMap<TQString, TQString> mapEntry = TDEGlobal::config()->entryMap( "Global Shortcuts" ); 00591 TQMap<TQString, TQString>::Iterator it( mapEntry.begin() ); 00592 for( uint i = 0; it != mapEntry.end(); ++it, i++ ) 00593 map[it.key()] = TDEShortcut(*it); 00594 } 00595 00596 void KKeyChooser::slotSettingsChanged( int category ) 00597 { 00598 if( category == TDEApplication::SETTINGS_SHORTCUTS ) 00599 readGlobalKeys(); // reread 00600 } 00601 00602 void KKeyChooser::fontChange( const TQFont & ) 00603 { 00604 d->fCArea->setMinimumHeight( 4*d->pbtnShortcut->sizeHint().height() ); 00605 00606 int widget_width = 0; 00607 00608 setMinimumWidth( 20+5*(widget_width+10) ); 00609 } 00610 00611 // KDE4 IMHO this shouldn't be here at all - it cannot check whether the default 00612 // shortcut don't conflict with some already changed ones (e.g. global shortcuts). 00613 // Also, I personally find reseting all shortcuts to default (i.e. hardcoded in the app) 00614 // ones after pressing the 'Default' button rather a misfeature. 00615 void KKeyChooser::allDefault() 00616 { 00617 kdDebug(125) << "KKeyChooser::allDefault()" << endl; 00618 00619 TQListViewItemIterator it( d->pList ); 00620 for( ; it.current(); ++it ) { 00621 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>(it.current()); 00622 if( pItem ) 00623 pItem->setShortcut( pItem->shortcutDefault() ); 00624 } 00625 00626 updateButtons(); 00627 emit keyChange(); 00628 } 00629 00630 void KKeyChooser::slotListItemSelected( TQListViewItem* ) 00631 { 00632 updateButtons(); 00633 } 00634 00635 void KKeyChooser::slotListItemDoubleClicked ( TQListViewItem *, const TQPoint & , int ) 00636 { // KDE4 dump this 00637 captureCurrentItem(); 00638 } 00639 00640 void KKeyChooser::captureCurrentItem() 00641 { 00642 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>( d->pList->currentItem() ); 00643 if( pItem != NULL && pItem->isConfigurable()) 00644 d->pbtnShortcut->captureShortcut ( ); 00645 } 00646 00647 void KKeyChooser::setPreferFourModifierKeys( bool bPreferFourModifierKeys ) 00648 { 00649 d->bPreferFourModifierKeys = bPreferFourModifierKeys; 00650 } 00651 00652 void KKeyChooser::capturedShortcut( const TDEShortcut& cut ) 00653 { 00654 if( cut.isNull() ) 00655 slotNoKey(); 00656 else 00657 setShortcut( cut ); 00658 } 00659 00660 // FIXME: give this functionality again -- I don't think it's ever used, though. -- ellis 00661 // TODO: Check lxr.kde.org to see if it's used anywhere 00662 void KKeyChooser::listSync() 00663 { 00664 /* kdDebug(125) << "KKeyChooser::listSync()" << endl; 00665 00666 if( d->pColl ) { 00667 // TODO: This is very inefficient. Come up with something better. 00668 TDEAccelActions aa; 00669 d->pColl->createKeyMap( aa ); 00670 d->actionsNew.updateShortcuts( aa ); 00671 } else if( d->pActionsOrig ) { 00672 d->actionsNew.updateShortcuts( *d->pActionsOrig ); 00673 update(); 00674 updateButtons(); 00675 }*/ 00676 } 00677 00678 void KKeyChooser::syncToConfig( const TQString& sConfigGroup, TDEConfigBase* pConfig, bool bClearUnset ) 00679 { 00680 kdDebug(125) << "KKeyChooser::syncToConfig( \"" << sConfigGroup << "\", " << pConfig << " ) start" << endl; 00681 if( !pConfig ) 00682 pConfig = TDEGlobal::config(); 00683 TDEConfigGroupSaver cgs( pConfig, sConfigGroup ); 00684 00685 TQListViewItemIterator it( d->pList ); 00686 for( ; it.current(); ++it ) { 00687 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>(it.current()); 00688 if( pItem ) { 00689 TQString sEntry = pConfig->readEntry( pItem->actionName() ); 00690 if( !sEntry.isNull() || bClearUnset ) { 00691 if( sEntry == "none" ) 00692 sEntry = TQString::null; 00693 pItem->setShortcut( sEntry ); 00694 } 00695 kdDebug(125) << pItem->actionName() << " = " << pItem->shortcut().toStringInternal() << endl; 00696 } 00697 } 00698 updateButtons(); 00699 kdDebug(125) << "KKeyChooser::syncToConfig() done" << endl; 00700 } 00701 00702 void KKeyChooser::setShortcut( const TDEShortcut& cut ) 00703 { 00704 kdDebug(125) << "KKeyChooser::setShortcut( " << cut.toString() << " )" << endl; 00705 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>(d->pList->currentItem()); 00706 if( !pItem ) 00707 return; 00708 00709 for( uint i = 0; i < cut.count(); i++ ) { 00710 const KKeySequence& seq = cut.seq(i); 00711 const KKey& key = seq.key(0); 00712 00713 if( !d->bAllowLetterShortcuts && key.modFlags() == 0 00714 && key.sym() < 0x3000 && TQChar(key.sym()).isLetterOrNumber() ) { 00715 TQString s = i18n( "In order to use the '%1' key as a shortcut, " 00716 "it must be combined with the " 00717 "Win, Alt, Ctrl, and/or Shift keys." ).arg(TQChar(key.sym())); 00718 KMessageBox::sorry( this, s, i18n("Invalid Shortcut Key") ); 00719 return; 00720 } 00721 } 00722 00723 // If key isn't already in use, 00724 if( !isKeyPresent( cut ) ) { 00725 // Set new key code 00726 pItem->setShortcut( cut ); 00727 // Update display 00728 updateButtons(); 00729 emit keyChange(); 00730 } 00731 } 00732 00733 // Returns iSeq index if cut2 has a sequence of equal or higher priority to a sequence in cut. 00734 // else -1 00735 static int keyConflict( const TDEShortcut& cut, const TDEShortcut& cut2 ) 00736 { 00737 for( uint iSeq = 0; iSeq < cut.count(); iSeq++ ) { 00738 for( uint iSeq2 = 0; iSeq2 < cut2.count(); iSeq2++ ) { 00739 if( cut.seq(iSeq) == cut2.seq(iSeq2) ) 00740 return iSeq; 00741 } 00742 } 00743 return -1; 00744 } 00745 00746 // Removes the sequences in cut2 from cut1 00747 static void removeFromShortcut( TDEShortcut & cut1, const TDEShortcut &cut2) 00748 { 00749 for( uint iSeq2 = 0; iSeq2 < cut2.count(); iSeq2++ ) 00750 cut1.remove(cut2.seq(iSeq2)); 00751 } 00752 00753 bool KKeyChooser::isKeyPresent( const TDEShortcut& cut, bool bWarnUser ) 00754 { 00755 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>(d->pList->currentItem()); 00756 00757 if (!pItem) { 00758 return false; 00759 } 00760 00761 bool has_global_chooser = false; 00762 bool has_standard_chooser = false; 00763 for( TQValueList< KKeyChooser* >::ConstIterator it = allChoosers->begin(); 00764 it != allChoosers->end(); 00765 ++it ) { 00766 has_global_chooser |= ((*it)->m_type == Global); 00767 has_standard_chooser |= ((*it)->m_type == Standard); 00768 } 00769 00770 // If editing global shortcuts, check them for conflicts with the stdaccels. 00771 if( m_type == ApplicationGlobal || m_type == Global ) { 00772 if( !has_standard_chooser ) { 00773 if( checkStandardShortcutsConflict( cut, bWarnUser, this )) 00774 return true; 00775 } 00776 } 00777 00778 // only check the global keys if one of the keychoosers isn't global 00779 if( !has_global_chooser ) { 00780 if( checkGlobalShortcutsConflict( cut, bWarnUser, this, d->mapGlobals, 00781 m_type == Global ? pItem->actionName() : TQString::null )) 00782 return true; 00783 } 00784 00785 if( isKeyPresentLocally( cut, pItem, bWarnUser )) 00786 return true; 00787 00788 // check also other KKeyChooser's 00789 for( TQValueList< KKeyChooser* >::ConstIterator it = allChoosers->begin(); 00790 it != allChoosers->end(); 00791 ++it ) { 00792 if( (*it) != this && (*it)->isKeyPresentLocally( cut, NULL, bWarnUser )) 00793 return true; 00794 } 00795 return false; 00796 } 00797 00798 // KDE4 remove 00799 bool KKeyChooser::isKeyPresentLocally( const TDEShortcut& cut, KKeyChooserItem* ignoreItem, const TQString& warnText ) 00800 { 00801 return isKeyPresentLocally( cut, ignoreItem, !warnText.isNull()); 00802 } 00803 00804 bool KKeyChooser::isKeyPresentLocally( const TDEShortcut& cut, KKeyChooserItem* ignoreItem, bool bWarnUser ) 00805 { 00806 if ( cut.toString().isEmpty()) 00807 return false; 00808 // Search for shortcut conflicts with other actions in the 00809 // lists we're configuring. 00810 for( TQListViewItemIterator it( d->pList ); it.current(); ++it ) { 00811 KKeyChooserItem* pItem2 = dynamic_cast<KKeyChooserItem*>(it.current()); 00812 if( pItem2 && pItem2 != ignoreItem ) { 00813 int iSeq = keyConflict( cut, pItem2->shortcut() ); 00814 if( iSeq > -1 ) { 00815 if( bWarnUser ) { 00816 if( !promptForReassign( cut.seq(iSeq), pItem2->text(0), Application, this )) 00817 return true; 00818 // else remove the shortcut from it 00819 TDEShortcut cut2 = pItem2->shortcut(); 00820 removeFromShortcut(cut2, cut); 00821 pItem2->setShortcut(cut2); 00822 updateButtons(); 00823 emit keyChange(); 00824 } 00825 } 00826 } 00827 } 00828 return false; 00829 } 00830 00831 bool KKeyChooser::checkStandardShortcutsConflict( const TDEShortcut& cut, bool bWarnUser, TQWidget* parent ) 00832 { 00833 // For each key sequence in the shortcut, 00834 for( uint i = 0; i < cut.count(); i++ ) { 00835 const KKeySequence& seq = cut.seq(i); 00836 TDEStdAccel::StdAccel id = TDEStdAccel::findStdAccel( seq ); 00837 if( id != TDEStdAccel::AccelNone 00838 && keyConflict( cut, TDEStdAccel::shortcut( id ) ) > -1 ) { 00839 if( bWarnUser ) { 00840 if( !promptForReassign( seq, TDEStdAccel::label(id), Standard, parent )) 00841 return true; 00842 removeStandardShortcut( TDEStdAccel::label(id), dynamic_cast< KKeyChooser* > ( parent ), TDEStdAccel::shortcut( id ), cut); 00843 } 00844 } 00845 } 00846 return false; 00847 } 00848 00849 bool KKeyChooser::checkGlobalShortcutsConflict( const TDEShortcut& cut, bool bWarnUser, TQWidget* parent ) 00850 { 00851 TQMap< TQString, TDEShortcut > map; 00852 readGlobalKeys( map ); 00853 return checkGlobalShortcutsConflict( cut, bWarnUser, parent, map, TQString::null ); 00854 } 00855 00856 bool KKeyChooser::checkGlobalShortcutsConflict( const TDEShortcut& cut, bool bWarnUser, TQWidget* parent, 00857 const TQMap< TQString, TDEShortcut >& map, const TQString& ignoreAction ) 00858 { 00859 TQMap<TQString, TDEShortcut>::ConstIterator it; 00860 for( it = map.begin(); it != map.end(); ++it ) { 00861 int iSeq = keyConflict( cut, (*it) ); 00862 if( iSeq > -1 ) { 00863 if( ignoreAction.isEmpty() || it.key() != ignoreAction ) { 00864 if( bWarnUser ) { 00865 if( !promptForReassign( cut.seq(iSeq), it.key(), Global, parent )) 00866 return true; 00867 removeGlobalShortcut( it.key(), dynamic_cast< KKeyChooser* >( parent ), (*it), cut); 00868 } 00869 } 00870 } 00871 } 00872 return false; 00873 } 00874 00875 void KKeyChooser::removeStandardShortcut( const TQString& name, KKeyChooser* chooser, const TDEShortcut &origCut, const TDEShortcut &cut ) 00876 { 00877 bool was_in_choosers = false; 00878 if( allChoosers != NULL ) { 00879 for( TQValueList< KKeyChooser* >::ConstIterator it = allChoosers->begin(); 00880 it != allChoosers->end(); 00881 ++it ) { 00882 if( (*it) != chooser && (*it)->m_type == Standard ) { 00883 was_in_choosers |= ( (*it)->removeShortcut( name, cut )); 00884 } 00885 } 00886 } 00887 if( !was_in_choosers ) { // not edited, needs to be changed in config file 00888 TDEStdAccel::ShortcutList std_list; 00889 TDEShortcut newCut = origCut; 00890 removeFromShortcut(newCut, cut); 00891 int index = std_list.index( name ); 00892 if ( index >= 0 ) { 00893 std_list.setShortcut( index, newCut ); 00894 std_list.save(); 00895 } 00896 } 00897 } 00898 00899 void KKeyChooser::removeGlobalShortcut( const TQString& name, KKeyChooser* chooser, const TDEShortcut &origCut, const TDEShortcut &cut ) 00900 { 00901 bool was_in_choosers = false; 00902 if( allChoosers != NULL ) { 00903 for( TQValueList< KKeyChooser* >::ConstIterator it = allChoosers->begin(); 00904 it != allChoosers->end(); 00905 ++it ) { 00906 if( (*it) != chooser && (*it)->m_type == Global ) { 00907 was_in_choosers |= ( (*it)->removeShortcut( name, cut )); 00908 } 00909 } 00910 } 00911 if( !was_in_choosers ) { // not edited, needs to be changed in config file 00912 TDEAccelActions actions; 00913 TDEShortcut newCut = origCut; 00914 removeFromShortcut(newCut, cut); 00915 actions.insert( name, "", "", newCut, newCut); 00916 actions.writeActions( "Global Shortcuts", 0, true, true ); 00917 } 00918 } 00919 00920 bool KKeyChooser::removeShortcut( const TQString& name, const TDEShortcut &cut ) 00921 { 00922 for( TQListViewItemIterator it( d->pList ); it.current(); ++it ) { 00923 KKeyChooserItem* pItem2 = dynamic_cast<KKeyChooserItem*>(it.current()); 00924 if( pItem2 && pItem2->actionName() == name ) { 00925 // remove the shortcut from it 00926 TDEShortcut cut2 = pItem2->shortcut(); 00927 removeFromShortcut(cut2, cut); 00928 pItem2->setShortcut(cut2); 00929 updateButtons(); 00930 emit keyChange(); 00931 return true; 00932 } 00933 } 00934 return false; 00935 } 00936 00937 // KDE4 remove this 00938 void KKeyChooser::_warning( const KKeySequence& cut, TQString sAction, TQString sTitle ) 00939 { 00940 sAction = sAction.stripWhiteSpace(); 00941 00942 TQString s = 00943 i18n("The '%1' key combination has already been allocated " 00944 "to the \"%2\" action.\n" 00945 "Please choose a unique key combination."). 00946 arg(cut.toString()).arg(sAction); 00947 00948 KMessageBox::sorry( this, s, sTitle ); 00949 } 00950 00951 bool KKeyChooser::promptForReassign( const KKeySequence& cut, const TQString& sAction, ActionType type, TQWidget* parent ) 00952 { 00953 if(cut.isNull()) 00954 return true; 00955 TQString sTitle; 00956 TQString s; 00957 if( type == Standard ) { 00958 sTitle = i18n("Conflict with Standard Application Shortcut"); 00959 s = i18n("The '%1' key combination has already been allocated " 00960 "to the standard action \"%2\".\n" 00961 "Do you want to reassign it from that action to the current one?"); 00962 } 00963 else if( type == Global ) { 00964 sTitle = i18n("Conflict with Global Shortcut"); 00965 s = i18n("The '%1' key combination has already been allocated " 00966 "to the global action \"%2\".\n" 00967 "Do you want to reassign it from that action to the current one?"); 00968 } 00969 else { 00970 sTitle = i18n("Key Conflict"); 00971 s = i18n("The '%1' key combination has already been allocated " 00972 "to the \"%2\" action.\n" 00973 "Do you want to reassign it from that action to the current one?"); 00974 } 00975 s = s.arg(cut.toString()).arg(sAction.stripWhiteSpace()); 00976 00977 return KMessageBox::warningContinueCancel( parent, s, sTitle, i18n("Reassign") ) == KMessageBox::Continue; 00978 } 00979 00980 //--------------------------------------------------- 00981 KKeyChooserItem::KKeyChooserItem( TDEListView* parent, TQListViewItem* after, TDEShortcutList* pList, uint iAction ) 00982 : TDEListViewItem( parent, after ) 00983 { 00984 m_pList = pList; 00985 m_iAction = iAction; 00986 m_bModified = false; 00987 m_cut = m_pList->shortcut(m_iAction); 00988 } 00989 00990 KKeyChooserItem::KKeyChooserItem( TQListViewItem* parent, TQListViewItem* after, TDEShortcutList* pList, uint iAction ) 00991 : TDEListViewItem( parent, after ) 00992 { 00993 m_pList = pList; 00994 m_iAction = iAction; 00995 m_bModified = false; 00996 m_cut = m_pList->shortcut(m_iAction); 00997 } 00998 00999 TQString KKeyChooserItem::actionName() const 01000 { 01001 return m_pList->name(m_iAction); 01002 } 01003 01004 const TDEShortcut& KKeyChooserItem::shortcut() const 01005 { 01006 return m_cut; 01007 } 01008 01009 void KKeyChooserItem::setShortcut( const TDEShortcut& cut ) 01010 { 01011 m_cut = cut; 01012 m_bModified = (m_cut != m_pList->shortcut(m_iAction)); 01013 listView()->repaintItem( this ); 01014 } 01015 01016 void KKeyChooserItem::commitChanges() 01017 { 01018 if( m_bModified ) 01019 m_pList->setShortcut( m_iAction, m_cut ); 01020 } 01021 01022 TQString KKeyChooserItem::text( int iCol ) const 01023 { 01024 if( iCol == 0 ) { 01025 // Quick HACK to get rid of '&'s. 01026 TQString s = m_pList->label(m_iAction); 01027 TQString s2; 01028 for( uint i = 0; i < s.length(); i++ ) 01029 if( s[i] != '&' || ( i+1<s.length() && s[i+1] == '&' ) ) 01030 s2 += s[i]; 01031 return s2; 01032 } 01033 else if( iCol <= (int) m_cut.count() ) 01034 return m_cut.seq(iCol-1).toString(); 01035 else 01036 return TQString::null; 01037 } 01038 01039 int KKeyChooserItem::compare( TQListViewItem* item, int iCol, bool bAscending ) const 01040 { 01041 KKeyChooserItem* pItem = dynamic_cast<KKeyChooserItem*>( item ); 01042 if( iCol == 0 && pItem ) { 01043 TQString psName1 = m_pList->name(m_iAction); 01044 TQString psName2 = pItem->m_pList->name(pItem->m_iAction); 01045 TQRegExp rxNumber1( " (\\d+)$" ); 01046 TQRegExp rxNumber2( " (\\d+)$" ); 01047 int iNumber1 = rxNumber1.search( psName1 ); 01048 int iNumber2 = rxNumber2.search( psName2 ); 01049 01050 // Check if the last word is one or more digits 01051 if( iNumber1 >= 0 && iNumber1 == iNumber2 && psName1.startsWith( psName2.left( iNumber1+1 ) ) ) { 01052 int n1 = rxNumber1.cap(1).toInt(); 01053 int n2 = rxNumber2.cap(1).toInt(); 01054 return (n1 < n2) ? -1 : (n1 > n2) ? 1 : 0; 01055 } 01056 } 01057 01058 return TQListViewItem::compare( item, iCol, bAscending ); 01059 } 01060 01062 01063 TQString KKeyChooserWhatsThis::text( const TQPoint& p ) { 01064 if ( !m_listView ) 01065 return TQString::null; 01066 01067 const TQListViewItem* item = m_listView->itemAt( p ); 01068 const KKeyChooserItem* pItem = dynamic_cast<const KKeyChooserItem*>(item); 01069 if ( !pItem ) 01070 return TQWhatsThis::textFor( m_listView ); 01071 01072 const TQString itemWhatsThis = pItem->whatsThis(); 01073 if ( itemWhatsThis.isEmpty() ) 01074 return TQWhatsThis::textFor( m_listView ); 01075 01076 return itemWhatsThis; 01077 } 01078 01079 /************************************************************************/ 01080 /* KKeyDialog */ 01081 /* */ 01082 /* Originally by Nicolas Hadacek <hadacek@via.ecp.fr> */ 01083 /* */ 01084 /* Substantially revised by Mark Donohoe <donohoe@kde.org> */ 01085 /* */ 01086 /* And by Espen Sand <espen@kde.org> 1999-10-19 */ 01087 /* (by using KDialogBase there is almost no code left ;) */ 01088 /* */ 01089 /************************************************************************/ 01090 KKeyDialog::KKeyDialog( KKeyChooser::ActionType type, bool bAllowLetterShortcuts, TQWidget *parent, const char* name ) 01091 : KDialogBase( parent, name ? name : "kkeydialog", true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok ) 01092 { 01093 m_pKeyChooser = new KKeyChooser( this, type, bAllowLetterShortcuts ); 01094 setMainWidget( m_pKeyChooser ); 01095 connect( this, TQT_SIGNAL(defaultClicked()), m_pKeyChooser, TQT_SLOT(allDefault()) ); 01096 01097 TDEConfigGroup group( TDEGlobal::config(), "KKeyDialog Settings" ); 01098 TQSize sz = size(); 01099 resize( group.readSizeEntry( "Dialog Size", &sz ) ); 01100 } 01101 01102 KKeyDialog::KKeyDialog( bool bAllowLetterShortcuts, TQWidget *parent, const char* name ) 01103 : KDialogBase( parent, name ? name : "kkeydialog", true, i18n("Configure Shortcuts"), Default|Ok|Cancel, Ok ) 01104 { 01105 m_pKeyChooser = new KKeyChooser( this, KKeyChooser::Application, bAllowLetterShortcuts ); 01106 setMainWidget( m_pKeyChooser ); 01107 connect( this, TQT_SIGNAL(defaultClicked()), m_pKeyChooser, TQT_SLOT(allDefault()) ); 01108 01109 TDEConfigGroup group( TDEGlobal::config(), "KKeyDialog Settings" ); 01110 TQSize sz = size(); 01111 resize( group.readSizeEntry( "Dialog Size", &sz ) ); 01112 } 01113 01114 KKeyDialog::~KKeyDialog() 01115 { 01116 TDEConfigGroup group( TDEGlobal::config(), "KKeyDialog Settings" ); 01117 group.writeEntry( "Dialog Size", size(), true, true ); 01118 } 01119 01120 bool KKeyDialog::insert( TDEActionCollection* pColl ) 01121 { 01122 return m_pKeyChooser->insert( pColl ); 01123 } 01124 01125 bool KKeyDialog::insert(TDEActionCollection *pColl, const TQString &title) 01126 { 01127 return m_pKeyChooser->insert(pColl, title); 01128 } 01129 01130 bool KKeyDialog::configure( bool bSaveSettings ) 01131 { 01132 int retcode = exec(); 01133 if( retcode == Accepted ) { 01134 if( bSaveSettings ) 01135 m_pKeyChooser->save(); 01136 else 01137 commitChanges(); 01138 } 01139 return retcode; 01140 } 01141 01142 void KKeyDialog::commitChanges() 01143 { 01144 m_pKeyChooser->commitChanges(); 01145 } 01146 01147 int KKeyDialog::configure( TDEActionCollection* coll, TQWidget* parent, bool bSaveSettings ) 01148 { 01149 return configure( coll, true, parent, bSaveSettings); 01150 } 01151 01152 int KKeyDialog::configure( TDEAccel* keys, TQWidget* parent, bool bSaveSettings ) 01153 { 01154 return configure( keys, true, parent, bSaveSettings); 01155 } 01156 01157 int KKeyDialog::configure( TDEGlobalAccel* keys, TQWidget* parent, bool bSaveSettings ) 01158 { 01159 return configure( keys, true, parent, bSaveSettings); 01160 } 01161 01162 int KKeyDialog::configure( TDEAccel* keys, bool bAllowLetterShortcuts, TQWidget *parent, bool bSaveSettings ) 01163 { 01164 KKeyDialog dlg( bAllowLetterShortcuts, parent ); 01165 dlg.m_pKeyChooser->insert( keys ); 01166 bool b = dlg.configure( bSaveSettings ); 01167 if( b && bSaveSettings ) 01168 keys->updateConnections(); 01169 return b; 01170 } 01171 01172 int KKeyDialog::configure( TDEGlobalAccel* keys, bool bAllowLetterShortcuts, TQWidget *parent, bool bSaveSettings ) 01173 { 01174 KKeyDialog dlg( KKeyChooser::ApplicationGlobal, bAllowLetterShortcuts, parent ); 01175 dlg.m_pKeyChooser->insert( keys ); 01176 bool b = dlg.configure( bSaveSettings ); 01177 if( b && bSaveSettings ) 01178 keys->updateConnections(); 01179 return b; 01180 } 01181 01182 int KKeyDialog::configure( TDEActionCollection* coll, bool bAllowLetterShortcuts, TQWidget *parent, bool bSaveSettings ) 01183 { 01184 kdDebug(125) << "KKeyDialog::configureKeys( TDEActionCollection*, " << bSaveSettings << " )" << endl; 01185 KKeyDialog dlg( bAllowLetterShortcuts, parent ); 01186 dlg.m_pKeyChooser->insert( coll ); 01187 return dlg.configure( bSaveSettings ); 01188 } 01189 01190 /*int KKeyDialog::configure( TDEActionPtrList* coll, const TQString& file, TQWidget *parent, bool bSaveSettings ) 01191 { 01192 kdDebug(125) << "KKeyDialog::configureKeys( TDEActionCollection*, " << file << ", " << bSaveSettings << " )" << endl; 01193 TDEAccelActions actions; 01194 coll->createKeyMap( actions ); 01195 01196 int retcode = configure( actions, file, parent, bSaveSettings ); 01197 if( retcode == Accepted ) 01198 coll->setKeyMap( actions ); 01199 01200 return retcode; 01201 }*/ 01202 01203 void KKeyChooser::virtual_hook( int, void* ) 01204 { /*BASE::virtual_hook( id, data );*/ } 01205 01206 void KKeyDialog::virtual_hook( int id, void* data ) 01207 { KDialogBase::virtual_hook( id, data ); } 01208 01209 #include "kkeydialog.moc"