bool KShortcut::conflictsWith(const QKeySequence &needle) const { if (needle.isEmpty()) return false; bool primaryConflicts = false; bool alternateConflicts = false; if (!d->primary.isEmpty()) { primaryConflicts = ( d->primary.matches(needle) == QKeySequence::NoMatch && needle.matches(d->primary) == QKeySequence::NoMatch ) ? false : true; } if (!d->alternate.isEmpty()) { alternateConflicts= ( d->alternate.matches(needle) == QKeySequence::NoMatch && needle.matches(d->alternate) == QKeySequence::NoMatch ) ? false : true; } return primaryConflicts || alternateConflicts; }
void KShortcutsEditorDelegate::stealShortcut( const QKeySequence &seq, QAction *action) { QTreeWidget *view = static_cast<QTreeWidget *>(parent()); // Iterate over all items QTreeWidgetItemIterator it(view, QTreeWidgetItemIterator::NoChildren); for (; (*it); ++it) { KShortcutsEditorItem *item = dynamic_cast<KShortcutsEditorItem *>(*it); if (item && item->data(0, ObjectRole).value<QObject *>() == action) { // We found the action, snapshot the current state. Steal the // shortcut. We will save the change later. const QList<QKeySequence> cut = action->shortcuts(); const QKeySequence primary = cut.isEmpty() ? QKeySequence() : cut.at(0); const QKeySequence alternate = cut.size() <= 1 ? QKeySequence() : cut.at(1); if (primary.matches(seq) != QKeySequence::NoMatch || seq.matches(primary) != QKeySequence::NoMatch) { item->setKeySequence(LocalPrimary, QKeySequence()); } if (alternate.matches(seq) != QKeySequence::NoMatch || seq.matches(alternate) != QKeySequence::NoMatch) { item->setKeySequence(LocalAlternate, QKeySequence()); } break; } } }
/* \internal Matches the current intermediate key sequence + the latest keyevent, with and AccelItem. Returns Identical, PartialMatch or NoMatch, and fills \a temp with the resulting key sequence. */ Qt::SequenceMatch QAccelManager::match( QKeyEvent *e, QAccelItem* item, QKeySequence& temp ) { SequenceMatch result = Qt::NoMatch; int index = intermediate.count(); temp = intermediate; int modifier = translateModifiers( e->state() ); if ( e->key() && e->key() != Key_unknown) { int key = e->key() | modifier; if ( e->key() == Key_BackTab ) { /* In QApplication, we map shift+tab to shift+backtab. This code here reverts the mapping in a way that keeps backtab and shift+tab accelerators working, in that order, meaning backtab has priority.*/ key &= ~SHIFT; temp.setKey( key, index ); if ( Qt::NoMatch != (result = temp.matches( item->key )) ) return result; if ( e->state() & ShiftButton ) key |= SHIFT; key = Key_Tab | ( key & MODIFIER_MASK ); temp.setKey( key, index ); if ( Qt::NoMatch != (result = temp.matches( item->key )) ) return result; } else { temp.setKey( key, index ); if ( Qt::NoMatch != (result = temp.matches( item->key )) ) return result; } if ( key == Key_BackTab ) { if ( e->state() & ShiftButton ) key |= SHIFT; temp.setKey( key, index ); if ( Qt::NoMatch != (result = temp.matches( item->key )) ) return result; } } if ( !e->text().isEmpty() ) { QChar c = e->text()[0]; // be in accordance with accoQAccel::shortcutKey() if ( modifier != 0 && c.isPrint() ) c = c.upper(); temp.setKey( (int)c.unicode() | UNICODE_ACCEL | modifier, index ); result = temp.matches( item->key ); } return result; }
bool UIActionPool::processHotKey(const QKeySequence &key) { /* Get the list of keys: */ QList<int> keys = m_pool.keys(); /* Iterate through the whole list of keys: */ for (int i = 0; i < keys.size(); ++i) { /* Get current action: */ UIAction *pAction = m_pool[keys[i]]; /* Skip menus/separators: */ if (pAction->type() == UIActionType_Menu) continue; /* Get the hot key of the current action: */ QString strHotKey = VBoxGlobal::extractKeyFromActionText(pAction->text()); if (pAction->isEnabled() && pAction->isVisible() && !strHotKey.isEmpty()) { if (key.matches(QKeySequence(strHotKey)) == QKeySequence::ExactMatch) { /* We asynchronously post a special event instead of calling * pAction->trigger() directly, to let key presses and * releases be processed correctly by Qt first. * Note: we assume that nobody will delete the menu item * corresponding to the key sequence, so that the pointer to * menu data posted along with the event will remain valid in * the event handler, at least until the main window is closed. */ QApplication::postEvent(this, new ActivateActionEvent(pAction)); return true; } } } return false; }
int KeySequence::matches(lua_State * L) // ( const QKeySequence & seq ) const : SequenceMatch { QKeySequence* lhs = QtValue<QKeySequence>::check( L, 1 ); QKeySequence* rhs = QtValue<QKeySequence>::check( L, 2 ); Lua::Util::push( L, lhs->matches( *rhs ) ); return 1; }
void QxtLookupLineEdit::keyPressEvent ( QKeyEvent * event ) { QKeySequence currSeq = QKeySequence(event->key() | event->modifiers()); if(currSeq.matches(qxt_d().m_trigger)) showPopup (); else QLineEdit::keyPressEvent(event); }
bool Prefs_KeyboardShortcuts::checkKey(int code) { bool ret = false; QKeySequence key = QKeySequence(code); for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=keyMap.end(); ++it) { if (key.matches(it.value().keySequence) != QKeySequence::NoMatch) { ret = true; break; } } return ret; }
QString Prefs_KeyboardShortcuts::getAction(int code) { QString ret; QKeySequence key = QKeySequence(code); for (QMap<QString,Keys>::Iterator it=keyMap.begin(); it!=keyMap.end(); ++it) { if (key.matches(it.value().keySequence) != QKeySequence::NoMatch) { ret = it->cleanMenuText; break; } } return ret; }