void starter::addShortcut(const KShortcut &cut) { // in case of empty shortcut, remove the entry from the list and return if (!short(cut.keyCodeQt())) { ShortcutList::Iterator it; for ( it = shortcutList.begin(); it != shortcutList.end(); ++it ) if (it.data() == configDialog->categoryList->currentText()) { shortcutList.remove(it); break; } configDialog->buttonShortcut->setShortcut(KShortcut::null(), false); return; } // generate MyKey short state = 0; if (cut.seq(0).key(0).modFlags() & KKey::CTRL) state |= Qt::ControlButton; if (cut.seq(0).key(0).modFlags() & KKey::ALT) state |= Qt::AltButton; if (cut.seq(0).key(0).modFlags() & KKey::SHIFT) state |= Qt::ShiftButton; MyKey key(cut.seq(0).keyCodeQt(), state); // Test if this is a valid shotrcut, i.e. contains 'ctrl' or 'alt', returns iff not if (!(state & Qt::ControlButton || state & Qt::AltButton)) { KMessageBox::sorry(this, i18n("<qt>To ensure usefull behaviour of the searchline, the shortcut <b>must contain</b> a metabutton, i.e. <b>'ctrl' and/or 'alt'</b></qt>"), i18n("Sorry, invalid Shortcut")); return; } // test if the cut was allready bound to another category and ask the user whta to do (return iff not rebind) ShortcutList::Iterator it = shortcutList.find(key); if ((it != shortcutList.end() && KMessageBox::questionYesNo(this, i18n("<qt>The selected shortcut is allready bound to the category \"%1\".<br>Do you want to <b>rebind</b> it?</qt>").arg(it.data()), i18n("Rebind Shortcut?")) == KMessageBox::No)) return; // if rebind (it is not end and we did not return ;) remove the old shortcut if (it != shortcutList.end()) { shortcutList.remove(it); } // test if another shortcut is bound to this category and remove it in case for ( it = shortcutList.begin(); it != shortcutList.end(); ++it ) if (it.data() == configDialog->categoryList->currentText()) { shortcutList.remove(it); break; } // add new shortcut/category map entry shortcutList[key] = configDialog->categoryList->currentText(); // update UI configDialog->buttonShortcut->setShortcut(cut, false); }
int KGlobalSettings::contextMenuKey () { KConfigGroup g(KGlobal::config(), "Shortcuts"); KShortcut cut (g.readEntry ("PopupMenuContext", "Menu")); return cut.keyCodeQt(); }