void PWidget::eventKey(QObject *, QEvent *e) { PukeMessage pm; widgetId wI; QKeyEvent *ke = Q_KEY_EVENT(e); wI = widgetIden(); pm.iCommand = - e->type() - 1020; // 1020 offset for events pm.iWinId = wI.iWinId; pm.iArg = 0; // special cArg handling pm.iTextSize = 3*sizeof(int); int *icArg = new int[3]; icArg[0] = ke->key(); icArg[1] = ke->ascii(); icArg[2] = ke->state(); pm.cArg = (char *) icArg; emit outputMessage(wI.fd, &pm); delete[] icArg; }
bool QAccel::eventFilter( QObject *, QEvent *e ) { if ( enabled && e->type() == Event_Accel && parent() && parent()->isWidgetType() && ((QWidget *)parent())->isVisibleToTLW() ) { QKeyEvent *k = (QKeyEvent *)e; int key = k->key(); if ( k->state() & ShiftButton ) key |= SHIFT; if ( k->state() & ControlButton ) key |= CTRL; if ( k->state() & AltButton ) key |= ALT; QAccelItem *item = find_key(aitems,key,k->ascii()); if ( item && item->enabled ) { if ( item->signal ) item->signal->activate(); else emit activated( item->id ); k->accept(); return TRUE; } } return FALSE; }
/*! Reimplementation of the \c QObject function. Always returns \p false (meaning event is \e not handled and should be forwarded to the \p qglviewer). When EventRecorder isRecording(), the following \c QEvent::type are recorded in an internal data structure: \c KeyPress, \c KeyRelease, \c MouseButtonPress, \c MouseButtonRelease, \c MouseButtonDblClick, \c MouseMove, \c Wheel and \c Timer (used by QGLViewer::animate()). Does nothing when isRecording() is \c false. You may overload this method to filter other \c QEvent::type (your implementation should probably call this function). Other specific events can be recorded using recordFrameState() and recordCustomEvent(). */ bool EventRecorder::eventFilter(QObject *, QEvent *e) { if (isRecording()) { bool record = true; switch (e->type()) { case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent* ke = (QKeyEvent*)(e); eventRecords_[eventIndex_].event.keyEvent = new QKeyEvent(e->type(), ke->key(), ke->ascii(), int(ke->state())); break; } case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: { QMouseEvent* me = (QMouseEvent*)(e); eventRecords_[eventIndex_].event.mouseEvent = new QMouseEvent(e->type(), me->pos(), int(me->button()), int(me->state())); break; } case QEvent::Wheel: { QWheelEvent* we = (QWheelEvent*)(e); eventRecords_[eventIndex_].event.wheelEvent = new QWheelEvent(we->pos(), we->delta(), int(we->state())); break; } case QEvent::Timer: { eventRecords_[eventIndex_].event.keyEvent = NULL; // or any other pointer break; } default: record = false; break; } if (record) { eventRecords_[eventIndex_].type = e->type(); eventRecords_[eventIndex_].time = time_.elapsed(); eventIndex_++; } } return false; }
bool Window::eventFilter(QObject*, QEvent* event) { if (event->type() != QEvent::KeyPress) { return false; } QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) { QKeyEvent* newEvent = new QKeyEvent( keyEvent->type(), keyEvent->key(), keyEvent->ascii(), keyEvent->state(), keyEvent->text()); QApplication::postEvent(mView, newEvent); return true; } return false; }
/* \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 QUimInputContext::filterEvent( const QEvent *event ) { #ifdef ENABLE_DEBUG // qDebug("filterEvent"); #endif int type = event->type(); if ( type != QEvent::KeyPress && type != QEvent::KeyRelease ) return FALSE; QKeyEvent *keyevent = ( QKeyEvent * ) event; int qkey = keyevent->key(); int modifier = 0; if ( keyevent->state() & Qt::ShiftButton ) modifier |= UMod_Shift; if ( keyevent->state() & Qt::ControlButton ) modifier |= UMod_Control; if ( keyevent->state() & Qt::AltButton ) modifier |= UMod_Alt; #if defined(Q_WS_X11) if ( keyevent->state() & Qt::MetaButton ) modifier |= UMod_Meta; #endif int key = 0; if ( isascii( qkey ) && isprint( qkey ) ) { int ascii = keyevent->ascii(); if ( isalpha( ascii ) ) { key = ascii; // uim needs lower/upper encoded key } else { if ( keyevent->state() & Qt::ControlButton && ( ascii >= 0x01 && ascii <= 0x1a ) ) if ( keyevent->state() & Qt::ShiftButton ) key = ascii + 0x40; else key = ascii + 0x60; else key = qkey; } } else if ( qkey == Qt::Key_unknown ) { QString text = keyevent->text(); if ( !text.isNull() ) { QChar s = text.at(0); key = unicodeToUKey ( s.unicode() ); } else { key = UKey_Other; } } else { if ( qkey >= Qt::Key_F1 && qkey <= Qt::Key_F35 ) { key = qkey - Qt::Key_F1 + UKey_F1; } else if ( qkey >= Qt::Key_Dead_Grave && qkey <= Qt::Key_Dead_Horn ) { key = qkey - Qt::Key_Dead_Grave + UKey_Dead_Grave; } else if ( qkey >= Qt::Key_Kanji && qkey <= Qt::Key_Eisu_toggle ) { key = qkey - Qt::Key_Kanji + UKey_Kanji; } else if ( qkey >= Qt::Key_Hangul && qkey <= Qt::Key_Hangul_Special ) { key = qkey - Qt::Key_Hangul + UKey_Hangul; } else { switch ( qkey ) { case Qt::Key_Tab: key = UKey_Tab; break; case Qt::Key_BackSpace: key = UKey_Backspace; break; case Qt::Key_Escape: key = UKey_Escape; break; case Qt::Key_Delete: key = UKey_Delete; break; case Qt::Key_Return: key = UKey_Return; break; case Qt::Key_Left: key = UKey_Left; break; case Qt::Key_Up: key = UKey_Up; break; case Qt::Key_Right: key = UKey_Right; break; case Qt::Key_Down: key = UKey_Down; break; case Qt::Key_Prior: key = UKey_Prior; break; case Qt::Key_Next: key = UKey_Next; break; case Qt::Key_Home: key = UKey_Home; break; case Qt::Key_End: key = UKey_End; break; case Qt::Key_Multi_key: key = UKey_Multi_key; break; case Qt::Key_Mode_switch: key = UKey_Mode_switch; break; case Qt::Key_Codeinput: key = UKey_Codeinput; break; case Qt::Key_SingleCandidate: key = UKey_SingleCandidate; break; case Qt::Key_MultipleCandidate: key = UKey_MultipleCandidate; break; case Qt::Key_PreviousCandidate: key = UKey_PreviousCandidate; break; case Qt::Key_Shift: key = UKey_Shift_key; break; case Qt::Key_Control: key = UKey_Control_key; break; case Qt::Key_Alt: key = UKey_Alt_key; break; case Qt::Key_Meta: key = UKey_Meta_key; break; case Qt::Key_CapsLock: key = UKey_Caps_Lock; break; case Qt::Key_NumLock: key = UKey_Num_Lock; break; case Qt::Key_ScrollLock: key = UKey_Scroll_Lock; break; default: key = UKey_Other; } } } int notFiltered; if ( type == QEvent::KeyPress ) { notFiltered = uim_press_key( m_uc, key, modifier ); #ifdef Q_WS_X11 if ( notFiltered ) return mCompose->handle_qkey( keyevent ); #else if ( notFiltered ) return FALSE; #endif } else if ( type == QEvent::KeyRelease ) { notFiltered = uim_release_key( m_uc, key, modifier ); #ifdef Q_WS_X11 if ( notFiltered ) return mCompose->handle_qkey( keyevent ); #else if ( notFiltered ) return FALSE; #endif } return TRUE; }
bool TEWidget::eventFilter( QObject *obj, QEvent *e ) { #if 0 // because QT4 using QShortcut, so I diable this function if ( (e->type() == QEvent::Accel || e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { static_cast<QKeyEvent *>( e )->ignore(); return true; } #endif if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) return FALSE; // not us if ( e->type() == QEvent::Wheel) { QApplication::sendEvent(scrollbar, e); } #ifdef FAKE_CTRL_AND_ALT static bool control = FALSE; static bool alt = FALSE; // Has a keyboard with no CTRL and ALT keys, but we fake it: bool dele=FALSE; if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent* ke = (QKeyEvent*)e; bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); switch (ke->key()) { case Key_F9: // let this be "Control" control = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); dele=TRUE; break; case Key_F13: // let this be "Alt" alt = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); dele=TRUE; break; default: if ( control ) { int a = toupper(ke->ascii())-64; if ( a >= 0 && a < ' ' ) { e = new QKeyEvent(e->type(), ke->key(), a, ke->state()|ControlButton, QChar(a,0)); dele=TRUE; } } if ( alt ) { e = new QKeyEvent(e->type(), ke->key(), ke->ascii(), ke->state()|AltButton, ke->text()); dele=TRUE; } } } #endif if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; actSel=0; // Key stroke implies a screen update, so TEWidget won't // know where the current selection is. emit keyPressedSignal(ke); // expose ke->accept(); #ifdef FAKE_CTRL_AND_ALT if ( dele ) delete e; #endif return true; // stop the event } if ( e->type() == QEvent::Enter ) { QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } if ( e->type() == QEvent::Leave ) { QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } return QFrame::eventFilter( obj, e ); }