void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence) { Q_D(QKeySequenceEdit); d->resetState(); if (d->keySequence == keySequence) return; d->keySequence = keySequence; d->key[0] = d->key[1] = d->key[2] = d->key[3] = 0; d->keyNum = keySequence.count(); for (int i = 0; i < d->keyNum; ++i) d->key[i] = keySequence[i]; d->lineEdit->setText(keySequence.toString(QKeySequence::NativeText)); emit keySequenceChanged(keySequence); }
bool KeyboardTranslatorReader::parseAsKeyCode(const QString& item , int& keyCode) { QKeySequence sequence = QKeySequence::fromString(item); if ( !sequence.isEmpty() ) { keyCode = sequence[0]; if ( sequence.count() > 1 ) { kDebug() << "Unhandled key codes in sequence: " << item; } } // additional cases implemented for backwards compatibility with KDE 3 else if ( item == "prior" ) keyCode = Qt::Key_PageUp; else if ( item == "next" ) keyCode = Qt::Key_PageDown; else return false; return true; }
/*! Matches the sequence with \a seq. Returns \c Qt::Identical if successful, \c Qt::PartialMatch for matching but incomplete \a seq, and \c Qt::NoMatch if the sequences have nothing in common. Returns \c Qt::NoMatch if \a seq is shorter. */ Qt::SequenceMatch QKeySequence::matches( const QKeySequence& seq ) const { uint userN = count(), seqN = seq.count(); if ( userN > seqN ) return NoMatch; // If equal in length, we have a potential Identical sequence, // else we already know it can only be partial. SequenceMatch match = ( userN == seqN ? Identical : PartialMatch ); for ( uint i = 0; i < userN; i++ ) { int userKey = (*this)[i], sequenceKey = seq[i]; if ( (userKey & ~Qt::UNICODE_ACCEL) != (sequenceKey & ~Qt::UNICODE_ACCEL) ) return NoMatch; } return match; }
bool KeyTracker::match(const QKeySequence &sequence) const { auto keys = pressedKeys(); return keys.size() == 1 && sequence.count() == 1 && *keys.begin() == sequence[0]; }
/* \internal Checks for possible accelerators, if no widget ate the keypres, or we are in the middle of a partial key sequence. */ bool QAccelManager::dispatchAccelEvent( QWidget* w, QKeyEvent* e ) { #ifndef QT_NO_STATUSBAR // Needs to be declared and used here because of "goto doclash" QStatusBar* mainStatusBar = 0; #endif // Modifiers can NOT be accelerators... if ( e->key() >= Key_Shift && e->key() <= Key_Alt ) return FALSE; SequenceMatch result = Qt::NoMatch; QKeySequence tocheck, partial; QAccelPrivate* accel = 0; QAccelItem* item = 0; QAccelPrivate* firstaccel = 0; QAccelItem* firstitem = 0; QAccelPrivate* lastaccel = 0; QAccelItem* lastitem = 0; QKeyEvent pe = *e; int n = -1; int hasShift = (e->state()&Qt::ShiftButton)?1:0; bool identicalDisabled = FALSE; bool matchFound = FALSE; do { accel = accels.first(); matchFound = FALSE; while ( accel ) { if ( correctSubWindow( w, accel ) ) { if ( accel->enabled ) { item = accel->aitems.last(); while( item ) { if ( Qt::Identical == (result = match( &pe, item, tocheck )) ) { if ( item->enabled ) { if ( !firstaccel ) { firstaccel = accel; firstitem = item; } lastaccel = accel; lastitem = item; n++; matchFound = TRUE; if ( n > QMAX(clash,0) ) goto doclash; } else { identicalDisabled = TRUE; } } if ( item->enabled && Qt::PartialMatch == result ) { partial = tocheck; matchFound = TRUE; } item = accel->aitems.prev(); } } else { item = accel->aitems.last(); while( item ) { if ( Qt::Identical == match( &pe, item, tocheck ) ) identicalDisabled = TRUE; item = accel->aitems.prev(); } } } accel = accels.next(); } pe = QKeyEvent( QEvent::Accel, pe.key(), pe.ascii(), pe.state()&~Qt::ShiftButton, pe.text() ); } while ( hasShift-- && !matchFound && !identicalDisabled ); #ifndef QT_NO_STATUSBAR mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" ); #endif if ( n < 0 ) { // no match found currentState = partial.count() ? PartialMatch : NoMatch; #ifndef QT_NO_STATUSBAR // Only display message if we are, or were, in a partial match if ( mainStatusBar && (PartialMatch == currentState || intermediate.count() ) ) { if ( currentState == Qt::PartialMatch ) { mainStatusBar->message( (QString)partial + ", ...", 0 ); } else if (!identicalDisabled) { QString message = QAccel::tr("%1, %2 not defined"). arg( (QString)intermediate ). arg( QKeySequence::encodeString( e->key() | translateModifiers(e->state()) ) ); mainStatusBar->message( message, 2000 ); // Since we're a NoMatch, reset the clash count clash = -1; } else { mainStatusBar->clear(); } } #endif bool eatKey = (PartialMatch == currentState || intermediate.count() ); intermediate = partial; if ( eatKey ) e->accept(); return eatKey; } else if ( n == 0 ) { // found exactly one match clash = -1; // reset #ifndef QT_NO_STATUSBAR if ( currentState == Qt::PartialMatch && mainStatusBar ) mainStatusBar->clear(); #endif currentState = Qt::NoMatch; // Free sequence keylock intermediate = QKeySequence(); lastaccel->activate( lastitem ); e->accept(); return TRUE; } doclash: // found more than one match #ifndef QT_NO_STATUSBAR if ( !mainStatusBar ) // if "goto doclash", we need to get statusbar again. mainStatusBar = (QStatusBar*) w->topLevelWidget()->child( 0, "QStatusBar" ); #endif QString message = QAccel::tr( "Ambiguous \"%1\" not handled" ).arg( (QString)tocheck ); if ( clash >= 0 && n > clash ) { // pick next match intermediate = QKeySequence(); currentState = Qt::NoMatch; // Free sequence keylock clash++; #ifndef QT_NO_STATUSBAR if ( mainStatusBar && !lastitem->signal && !(lastaccel->parent->receivers( "activatedAmbiguously(int)" )) ) mainStatusBar->message( message, 2000 ); #endif lastaccel->activateAmbiguously( lastitem ); } else { // start (or wrap) with the first matching intermediate = QKeySequence(); currentState = Qt::NoMatch; // Free sequence keylock clash = 0; #ifndef QT_NO_STATUSBAR if ( mainStatusBar && !firstitem->signal && !(firstaccel->parent->receivers( "activatedAmbiguously(int)" )) ) mainStatusBar->message( message, 2000 ); #endif firstaccel->activateAmbiguously( firstitem ); } e->accept(); return TRUE; }
bool GlobalHotkey::registerHotkey(const QKeySequence &hk) { if (hk.count() != 1) return false; return registerHotkey(hk[0]); }
/** ***************************************************************************/ bool HotkeyManager::unregisterHotkey(const QKeySequence &hk) { if (hk.count() != 1) return false; unregisterHotkey(hk[0]); return true; }
int KeySequence::count(lua_State * L) // const : uint { QKeySequence* lhs = QtValue<QKeySequence>::check( L, 1 ); Lua::Util::push(L, lhs->count() ); return 1; }
bool ShortcutsHandler::send_macro_key( const QKeySequence &key, Window window_P ) { kDebug() << key << key.count() << window_P; if (key.isEmpty()) return false; unsigned int keysym = key[0]; int x_keycode; KKeyServer::keyQtToCodeX(keysym, &x_keycode); if( x_keycode == NoSymbol ) return false; unsigned int x_mod; KKeyServer::keyQtToModX(keysym, &x_mod ); #ifdef HAVE_XTEST if( xtest() && window_P == None ) { // CHECKME tohle jeste potrebuje modifikatory bool ret = XTestFakeKeyEvent( QX11Info::display(), x_keycode, True, CurrentTime ); ret = ret && XTestFakeKeyEvent( QX11Info::display(), x_keycode, False, CurrentTime ); return ret; } #endif if( window_P == None || window_P == InputFocus ) window_P = windows_handler->active_window(); if( window_P == None ) // CHECKME tohle cele je ponekud ... window_P = InputFocus; XEvent ev; ev.type = KeyPress; ev.xkey.display = QX11Info::display(); ev.xkey.window = window_P; ev.xkey.root = QX11Info::appRootWindow(); // I don't know whether these have to be set ev.xkey.subwindow = None; // to these values, but it seems to work, hmm ev.xkey.time = CurrentTime; ev.xkey.x = 0; ev.xkey.y = 0; ev.xkey.x_root = 0; ev.xkey.y_root = 0; ev.xkey.keycode = x_keycode; ev.xkey.state = x_mod; ev.xkey.same_screen = True; bool ret = XSendEvent( QX11Info::display(), window_P, True, KeyPressMask, &ev ); #if 1 ev.type = KeyRelease; // is this actually really needed ?? ev.xkey.display = QX11Info::display(); ev.xkey.window = window_P; ev.xkey.root = QX11Info::appRootWindow(); ev.xkey.subwindow = None; ev.xkey.time = CurrentTime; ev.xkey.x = 0; ev.xkey.y = 0; ev.xkey.x_root = 0; ev.xkey.y_root = 0; ev.xkey.state = x_mod; ev.xkey.keycode = x_keycode; ev.xkey.same_screen = True; ret = ret && XSendEvent( QX11Info::display(), window_P, True, KeyReleaseMask, &ev ); #endif // Qt's autorepeat compression is broken and can create "aab" from "aba" // XSync() should create delay longer than Qt's max autorepeat interval XSync( QX11Info::display(), False ); return ret; }
void FcitxQtKeySequenceWidgetPrivate::updateShortcutDisplay() { do { if (keySequence.count() != 1) { break; } int key = keySequence[0] & (~Qt::KeyboardModifierMask); if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Meta || key == Qt::Key_Alt) { QString s; int mod = keySequence[0] & (Qt::KeyboardModifierMask); if (mod & Qt::META && key != Qt::Key_Meta) s += "Meta+"; if (mod & Qt::CTRL && key != Qt::Key_Control) s += "Ctrl+"; if (mod & Qt::ALT && key != Qt::Key_Alt) s += "Alt+"; if (mod & Qt::SHIFT && key != Qt::Key_Shift) s += "Shift+"; if (side == MS_Left) { s += _("Left") + " "; } else if (side == MS_Right) { s += _("Right") + " "; } switch(key) { case Qt::Key_Shift: s += "Shift"; break; case Qt::Key_Control: s += "Ctrl"; break; case Qt::Key_Meta: s += "Meta"; break; case Qt::Key_Alt: s += "Alt"; break; } keyButton->setText(s); return; } } while(0); //empty string if no non-modifier was pressed QString s = keySequence.toString(QKeySequence::NativeText); s.replace('&', QLatin1String("&&")); if (isRecording) { if (modifierKeys) { if (!s.isEmpty()) s.append(","); if (modifierKeys & Qt::META) s += "Meta+"; if (modifierKeys & Qt::CTRL) s += "Ctrl+"; if (modifierKeys & Qt::ALT) s += "Alt+"; if (modifierKeys & Qt::SHIFT) s += "Shift+"; } else if (nKey == 0) { s = "..."; } //make it clear that input is still going on s.append(" ..."); } if (s.isEmpty()) { s = _("Empty"); } s.prepend(' '); s.append(' '); keyButton->setText(s); }