void BasicTab::slotCapturedShortcut(const KShortcut &cut) { if(signalsBlocked()) return; if(KKeyChooser::checkGlobalShortcutsConflict(cut, true, topLevelWidget()) || KKeyChooser::checkStandardShortcutsConflict(cut, true, topLevelWidget())) return; if(KHotKeys::present()) { if(!_menuEntryInfo->isShortcutAvailable(cut)) { KService::Ptr service; emit findServiceShortcut(cut, service); if(!service) service = KHotKeys::findMenuEntry(cut.toString()); if(service) { KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already used to activate <b>%2</b>.") .arg(cut.toString(), service->name())); return; } else { KMessageBox::sorry(this, i18n("<qt>The key <b>%1</b> can not be used here because it is already in use.").arg(cut.toString())); return; } } _menuEntryInfo->setShortcut(cut); } _keyEdit->setShortcut(cut, false); if(_menuEntryInfo) emit changed(_menuEntryInfo); }
bool KKeyChooser::isKeyPresentLocally(const KShortcut &cut, KKeyChooserItem *ignoreItem, bool bWarnUser) { if(cut.toString().isEmpty()) return false; // Search for shortcut conflicts with other actions in the // lists we're configuring. for(QListViewItemIterator it(d->pList); it.current(); ++it) { KKeyChooserItem *pItem2 = dynamic_cast< KKeyChooserItem * >(it.current()); if(pItem2 && pItem2 != ignoreItem) { int iSeq = keyConflict(cut, pItem2->shortcut()); if(iSeq > -1) { if(bWarnUser) { if(!promptForReassign(cut.seq(iSeq), pItem2->text(0), Application, this)) return true; // else remove the shortcut from it KShortcut cut2 = pItem2->shortcut(); removeFromShortcut(cut2, cut); pItem2->setShortcut(cut2); updateButtons(); emit keyChange(); } } } } return false; }
void KKeyChooser::setShortcut(const KShortcut &cut) { kdDebug(125) << "KKeyChooser::setShortcut( " << cut.toString() << " )" << endl; KKeyChooserItem *pItem = dynamic_cast< KKeyChooserItem * >(d->pList->currentItem()); if(!pItem) return; for(uint i = 0; i < cut.count(); i++) { const KKeySequence &seq = cut.seq(i); const KKey &key = seq.key(0); if(!d->bAllowLetterShortcuts && key.modFlags() == 0 && key.sym() < 0x3000 && QChar(key.sym()).isLetterOrNumber()) { QString s = i18n( "In order to use the '%1' key as a shortcut, " "it must be combined with the " "Win, Alt, Ctrl, and/or Shift keys.") .arg(QChar(key.sym())); KMessageBox::sorry(this, s, i18n("Invalid Shortcut Key")); return; } } // If key isn't already in use, if(!isKeyPresent(cut)) { // Set new key code pItem->setShortcut(cut); // Update display updateButtons(); emit keyChange(); } }
void FolderShortcutDialog::slotCapturedShortcut( const KShortcut& sc ) { if ( sc == mKeyButton->shortcut() ) return; if ( sc.toString().isNull() ) { // null is fine, that's reset, but sc.іsNull() will be false :/ mKeyButton->setShortcut( KShortcut::null(), false ); } else { if( !mMainWidget->shortcutIsValid( sc ) ) { QString msg( i18n( "The selected shortcut is already used, " "please select a different one." ) ); KMessageBox::sorry( mMainWidget, msg ); } else { mKeyButton->setShortcut( sc, false ); } } }
void SnippetDlg::slotCapturedShortcut(const KShortcut &sc) { if(sc == keyButton->shortcut()) return; if(sc.toString().isNull()) { // null is fine, that's reset, but sc.іsNull() will be false :/ keyButton->setShortcut(KShortcut::null(), false); } else { if(!shortcutIsValid(actionCollection, sc)) { QString msg(i18n("The selected shortcut is already used, " "please select a different one.")); KMessageBox::sorry(this, msg); } else { keyButton->setShortcut(sc, false); } } }
void ActionConfigDialog::slotShortcutCaptured(const KShortcut &shortcut) { QString shortcutText = shortcut.toString(); QString shortcutText2; int pos = shortcutText.find(';'); if (pos != -1) { shortcutText2 = shortcutText.mid(pos + 1); shortcutText = shortcutText.left(pos); } QString s = shortcutText; s.replace('+', "\\+"); QRegExp shortcutRx("\\(" + s + "\\)|" + s + "$|" + s + ";"); s = shortcutText2; s.replace('+', "\\+"); QRegExp shortcutRx2("\\(" + s + "\\)|" + s + "$|" + s + ";"); QString global; //check for conflicting global shortcuts QMap<QString, QString>::Iterator it; for ( it = globalShortcuts.begin(); it != globalShortcuts.end(); ++it ) { if (it.data().contains(shortcutRx)) { global = it.key(); break; } if (!shortcutText2.isEmpty() && it.data().contains(shortcutRx2)) { shortcutText = shortcutText2; global = it.key(); break; } } if (global.isEmpty()) { QPtrList<KXMLGUIClient> clients = m_mainWindow->guiFactory()->clients(); for( QPtrListIterator<KXMLGUIClient> it( clients ); it.current(); ++it ) { KActionCollection *ac = (*it)->actionCollection(); for (uint i = 0; i < ac->count(); i++) { KAction *action = ac->action(i); if (action != currentAction && action->shortcut().toString().contains(shortcutRx)) { global = action->text(); break; } if (!shortcutText2.isEmpty() && action != currentAction && action->shortcut().toString().contains(shortcutRx)) { shortcutText = shortcutText2; global = action->text(); break; } } if (!global.isEmpty()) break; } } if (global.isEmpty()) { shortcutKeyButton->setText(shortcutText); buttonApply->setEnabled(true); selectedShortcut = shortcut; } else { global.replace('&',""); QString s = i18n("The '%1' key combination has already been allocated " "to the \"%2\" action.\n" "Please choose a unique key combination."). arg(shortcutText).arg(global); KMessageBox::sorry( this, s, i18n("Conflicting Shortcuts")); } }