Ejemplo n.º 1
0
void AssignHotKey_Test::keyPressEventOnlyModifiers()
{
    AssignHotKey ahk(NULL);
    bool autoclose = ahk.m_autoCloseCheckBox->isChecked();

    ahk.m_autoCloseCheckBox->setChecked(false);
    QKeyEvent ev(QEvent::KeyPress, Qt::Key_Shift, Qt::ShiftModifier);
    ahk.keyPressEvent(&ev);
    QCOMPARE(ahk.keySequence(), QKeySequence());
    QCOMPARE(ahk.result(), (int) QDialog::Rejected);

    ev = QKeyEvent(QEvent::KeyPress, Qt::Key_Control, Qt::ControlModifier);
    ahk.keyPressEvent(&ev);
    QCOMPARE(ahk.keySequence(), QKeySequence());
    QCOMPARE(ahk.result(), (int) QDialog::Rejected);

    ev = QKeyEvent(QEvent::KeyPress, Qt::Key_Alt, Qt::AltModifier);
    ahk.keyPressEvent(&ev);
    QCOMPARE(ahk.keySequence(), QKeySequence());
    QCOMPARE(ahk.result(), (int) QDialog::Rejected);

    ev = QKeyEvent(QEvent::KeyPress, Qt::Key_Meta, Qt::MetaModifier);
    ahk.keyPressEvent(&ev);
    QCOMPARE(ahk.keySequence(), QKeySequence());
    QCOMPARE(ahk.result(), (int) QDialog::Rejected);

    // Reset autoclose
    ahk.m_autoCloseCheckBox->setChecked(autoclose);
}
Ejemplo n.º 2
0
void finishOpenVrKeyboardInput() {
    auto offscreenUi = DependencyManager::get<OffscreenUi>();
    updateFromOpenVrKeyboardInput();
    // Simulate an enter press on the top level window to trigger the action
    if (0 == (_currentHints & Qt::ImhMultiLine)) {
        qApp->sendEvent(offscreenUi->getWindow(), &QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::KeyboardModifiers(), QString("\n")));
        qApp->sendEvent(offscreenUi->getWindow(), &QKeyEvent(QEvent::KeyRelease, Qt::Key_Return, Qt::KeyboardModifiers()));
    }
}
Ejemplo n.º 3
0
/*!
    \fn KeyHold::eventFilter( QObject* o, QEvent* e )
    \internal
*/
bool KeyHold::eventFilter( QObject*, QEvent* e )
{
static bool enabled = true;

    if( enabled ) {
        switch( e->type() )
        {
        case QEvent::KeyPress:
            {
            QKeyEvent *ke = (QKeyEvent*)e;
            if( ke->key() == m_key ) {
                if( !ke->isAutoRepeat() ) {
                    // Start hold countdown
                    m_countdown->start( m_threshold );
                }
                return true;
            }
            }
            break;
        case QEvent::KeyRelease:
            {
            QKeyEvent *ke = (QKeyEvent*)e;
            if( ke->key() == m_key ) {
                if( !ke->isAutoRepeat() ) {
                    // If countdown active, generate key press and key release
                    // Otherwise, generate key hold release
                    if( m_countdown->isActive() ) {
                        m_countdown->stop();
                        enabled = false;
                        QKeyEvent event = QKeyEvent( QEvent::KeyPress, m_key, Qt::NoModifier );
                        QCoreApplication::sendEvent( m_target, &event );
                        event = QKeyEvent( QEvent::KeyRelease, m_key, Qt::NoModifier );
                        QCoreApplication::sendEvent( m_target, &event );
                        enabled = true;
                    } else {
                        QKeyEvent event = QKeyEvent( QEvent::KeyRelease, m_keyHold, Qt::NoModifier );
                        QCoreApplication::sendEvent( m_target, &event );
                    }
                }
                return true;
            }
            }
            break;
        default:
            // Ignore
            break;
        }
    }

    return false;
}
Ejemplo n.º 4
0
void MacroDialog::buildKeypadKeys(Qt::KeyboardModifiers modifers, int start, int end) {
    QList<QKeyEvent> keyList;
    for(int keyCode = start; keyCode <= end; keyCode++) {
        keyList << QKeyEvent(QEvent::User, keyCode, Qt::KeypadModifier | modifers, QKeySequence(modifers | keyCode).toString());
    }        
    keys["keypad"] << keyList;
}
void JavascriptInvocation::keypress(QChar key) {
  int keyCode = keyCodeFor(key);
  QKeyEvent event(QKeyEvent::KeyPress, keyCode, Qt::NoModifier, key);
  QApplication::sendEvent(m_page, &event);
  event = QKeyEvent(QKeyEvent::KeyRelease, keyCode, Qt::NoModifier, key);
  QApplication::sendEvent(m_page, &event);
}
Ejemplo n.º 6
0
void MacroDialog::buildKeys(QString tabName, Qt::KeyboardModifiers modifers, int start, int end) {
    QList<QKeyEvent> keyList;
    for(int keyCode = start; keyCode <= end; keyCode++) {        
        // mac include modifier in sequence? QT::ALT
        keyList << QKeyEvent(QEvent::User, keyCode, modifers, QKeySequence(keyCode).toString());
    }
    keys[tabName] << keyList;
}
Ejemplo n.º 7
0
void PeopleApplication::searchClicked()
{
    m_searchWidget->show();
    //force keyboard to pop-up
    m_searchEdit->setFocus(Qt::TabFocusReason);
    emit QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier);
    m_bottomSpacer->setPreferredHeight(m_searchWidget->size().height());
}
Ejemplo n.º 8
0
bool CanvasWindow::event(QEvent *ev)
{
    if(ev->type() == QEvent::ActivationChange)
    {
        //LOG_DEBUG("CanvasWindow: Forwarding QEvent::KeyRelease, Qt::Key_Alt");
        QKeyEvent keyEvent = QKeyEvent(QEvent::KeyRelease, Qt::Key_Alt, Qt::NoModifier);
        return QApplication::sendEvent(&canvas(), &keyEvent);
    }
    return QMainWindow::event(ev);
}
void MAbstractInputMethod::processKeyEvent(QEvent::Type keyType, Qt::Key keyCode,
                                           Qt::KeyboardModifiers modifiers,
                                           const QString &text, bool autoRepeat, int count,
                                           quint32 /* nativeScanCode */, quint32 /* nativeModifiers */,
                                           unsigned long /*time*/)
{
    // default implementation, just sendKeyEvent back
    inputMethodHost()->sendKeyEvent(QKeyEvent(keyType, keyCode, modifiers, text, autoRepeat,
                                              count));
}
Ejemplo n.º 10
0
void PythonEdit::keyPressEvent(QKeyEvent *e)
{
    if (e->key() == Qt::Key_Tab) {
        QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, " ");
        for (int i = 0; i < 4; i++) {
            QTextEdit::keyPressEvent(&event);
        }
    } else {
        QTextEdit::keyPressEvent(e);
    }
}
Ejemplo n.º 11
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;
}
QKeyEvent CreateDown() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Down,Qt::NoModifier); }
Ejemplo n.º 13
0
/*!
    \fn KeyHold::generateKeyHoldPress()
    \internal
*/
void KeyHold::generateKeyHoldPress()
{
    QKeyEvent event = QKeyEvent( QEvent::KeyPress, m_keyHold, Qt::NoModifier );
    QCoreApplication::sendEvent( m_target, &event );
}
void tst_Q3RichText::keyPressEvent()
{
    // Still needs to test Key_Prior and Key_Next

    int para, index;

    Q3TextEdit textedit;
    textedit.show();
    textedit.setText( "This is a test" );

    qWarning( "Consider using QtTestCase::keyEvent() for sending key events" );
    QKeyEvent ke( QEvent::KeyPress, Qt::Key_Right, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    textedit.getCursorPosition( &para, &index );
    QCOMPARE( para, 0 );
    QCOMPARE( index, 1 );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Right, 0, Qt::ControlModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    textedit.getCursorPosition( &para, &index );
    QCOMPARE( para, 0 );
    QCOMPARE( index, 5 );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Left, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    textedit.getCursorPosition( &para, &index );
    QCOMPARE( para, 0 );
    QCOMPARE( index, 4 );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Left, 0, Qt::ControlModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    textedit.getCursorPosition( &para, &index );
    QCOMPARE( para, 0 );
    QCOMPARE( index, 0 );

    // Test that the text is removed when Enter/Return is pressed first
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Enter, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("\n") );

    textedit.setText( "This is a test" );
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Return, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("\n") );

    // Now test if the line-break is added in rich text mode
    textedit.setTextFormat( Qt::RichText );

    textedit.setText( "This is a test" );
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Enter, 0, Qt::ControlModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QVERIFY( textedit.text().contains( "<br />" ) );

    textedit.setText( "This is a test" );
    textedit.moveCursor( Q3TextEdit::MoveLineEnd, FALSE );
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Return, 0, Qt::ControlModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QVERIFY( textedit.text().contains( "<br />" ) );

    textedit.setText( "This is a test" );
    textedit.moveCursor( Q3TextEdit::MoveWordForward, FALSE );
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Return, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QString es = QString::fromLatin1("<p dir=\"ltr\">");
    QVERIFY( textedit.text().count( es ) == 2 );

    textedit.setTextFormat( Qt::AutoText );

    textedit.setText( "This is a test" );
    QApplication::clipboard()->setText("");
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Delete, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("") );

#if defined (Q_WS_WIN)
    textedit.setText( "This is a test" );
    QApplication::clipboard()->setText("");
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Delete, 0, Qt::ShiftModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("") );
    QCOMPARE( QApplication::clipboard()->text(), QString("This is a test") );
#endif

    textedit.setText( "This is a test" );
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Delete, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("his is a test") );

    bool nativeClipboardWorking = true;
#if defined (Q_WS_MAC)
    PasteboardRef pasteboard;
    OSStatus status = PasteboardCreate(0, &pasteboard);
    if (status == noErr)
        CFRelease(pasteboard);
    nativeClipboardWorking = status == noErr;
#endif

    if (nativeClipboardWorking) {
        textedit.setText( "This is a test" );
        QApplication::clipboard()->setText(" and this is another test");
        textedit.moveCursor( Q3TextEdit::MoveLineEnd, FALSE );
        ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Insert, 0, Qt::ShiftModifier );
        QApplication::sendEvent( textedit.viewport(), &ke );
        QCOMPARE( textedit.text(), QString("This is a test and this is another test") );
    }

#if defined (Q_WS_WIN)
    textedit.setText( "This is a test" );
    QApplication::clipboard()->setText("");
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Insert, 0, Qt::ControlModifier );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( QApplication::clipboard()->text(), QString("This is a test") );
#endif

    textedit.setText( "This is a test" );
    textedit.selectAll();
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Backspace, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString("") );

    textedit.setText( "This is a test" );
    textedit.moveCursor( Q3TextEdit::MoveLineEnd, FALSE );
    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Backspace, 0, Qt::NoButton );
    QApplication::sendEvent( textedit.viewport(), &ke );
    QCOMPARE( textedit.text(), QString( "This is a tes" ) );

    if (nativeClipboardWorking) {
        textedit.setText( "This is a test" );
        QApplication::clipboard()->setText("");
        textedit.selectAll();
        ke = QKeyEvent( QEvent::KeyPress, Qt::Key_F16, 0, Qt::NoButton );
        QApplication::sendEvent( textedit.viewport(), &ke );
        QCOMPARE( QApplication::clipboard()->text(), QString("This is a test") );

        textedit.setText( "This is a test" );
        textedit.moveCursor( Q3TextEdit::MoveLineEnd, FALSE );
        QApplication::clipboard()->setText(" and this is another test");
        ke = QKeyEvent( QEvent::KeyPress, Qt::Key_F18, 0, Qt::NoButton );
        QApplication::sendEvent( textedit.viewport(), &ke );
        QCOMPARE( textedit.text(), QString("This is a test and this is another test") );

        textedit.setText( "This is a test" );
        QApplication::clipboard()->setText("");
        textedit.selectAll();
        ke = QKeyEvent( QEvent::KeyPress, Qt::Key_F20, 0, Qt::NoButton );
        QApplication::sendEvent( textedit.viewport(), &ke );
        QCOMPARE( textedit.text(), QString("") );
        QCOMPARE( QApplication::clipboard()->text(), QString("This is a test") );
    }
}
void tst_Q3RichText::richtext()
{
    Q3TextEdit* textedit = new Q3TextEdit();
    QString result( "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:%1;font-family:%2\">\n"
	    "<p dir=\"ltr\">k <span style=\"font-family:Arial;font-size:20pt%3\">   </span><span style=\"font-family:Arial;font-size:15pt%4\">  </span><span style=\"font-family:Arial;font-size:20pt%5\">k k  </span></p>\n"
	    "</body></html>\n" );
    QFont font = textedit->font();
    result = result.arg( QString::number(font.pointSize()) + "pt" ).arg( font.family() ).arg( "" ).arg( "" ).arg( "" );

    textedit->setTextFormat( Qt::RichText );

    QKeyEvent ke( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    textedit->setCurrentFont( QFont( "Arial", 20 ) );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    textedit->setCurrentFont( QFont( "Arial", 15 ) );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    textedit->setCurrentFont( QFont( "Arial", 20 ) );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_K, 107, Qt::NoButton, "k" );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    ke = QKeyEvent( QEvent::KeyPress, Qt::Key_Space, 32, Qt::NoButton, " " );
    QApplication::sendEvent( textedit->viewport(), &ke );

    QCOMPARE( textedit->text(), result );

    delete textedit;
}
QKeyEvent CreateUp() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Up,Qt::NoModifier); }
QKeyEvent CreateTab() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Tab,Qt::NoModifier); }
Ejemplo n.º 18
0
void TimelineView::keyPressEvent(QKeyEvent *event){
    int i, next;
    if(!event->modifiers().testFlag(Qt::ShiftModifier) &&
       !event->modifiers().testFlag(Qt::ControlModifier) &&
       !event->modifiers().testFlag(Qt::AltModifier)){
        switch(event->key()){
        case Qt::Key_M:
            next = -1;
            for(i=model()->baseIndex()-1; i>=0; i--){
                if(isRelatedPost(i, model()->baseIndex())){
                    next = i;
                    break;
                }
            }
            if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
            return;
        case Qt::Key_N:
            next = -1;
            for(i=model()->baseIndex()+1; i<model()->count(); i++){
                if(isRelatedPost(i, model()->baseIndex())){
                    next = i;
                    break;
                }
            }
            if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
            return;
        case Qt::Key_I:
            emit favorite();
            return;
        case Qt::Key_H:
            next = -1;
            for(i=model()->baseIndex()+1; i<model()->count(); i++){
                if(model()->itemAt(i).userId() == model()->itemAt(model()->baseIndex()).userId()){
                    next = i;
                    break;
                }
            }
            if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
            return;
        case Qt::Key_J:
            QApplication::sendEvent(this, &QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
            return;
        case Qt::Key_K:
            QApplication::sendEvent(this, &QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier));
            return;
        case Qt::Key_L:
            next = -1;
            for(i=model()->baseIndex()-1; i>=0; i--){
                if(model()->itemAt(i).userId() == model()->itemAt(model()->baseIndex()).userId()){
                    next = i;
                    break;
                }
            }
            if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
            return;
        case Qt::Key_Space:
            jumpToUnread();
            return;
        case Qt::Key_Return:
            emit reply();
            return;
        default:
            break;
        }
    }
    if(event->modifiers().testFlag(Qt::ShiftModifier) &&
       !event->modifiers().testFlag(Qt::ControlModifier) &&
       !event->modifiers().testFlag(Qt::AltModifier)){
        switch(event->key()){
       case Qt::Key_M:
           next = -1;
           for(i=model()->baseIndex()-1; i>=0; i--){
               if(model()->itemAt(i).favorited()){
                   next = i;
                   break;
               }
           }
           if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
           return;
       case Qt::Key_N:
           next = -1;
           for(i=model()->baseIndex()+1; i<model()->count(); i++){
               if(model()->itemAt(i).favorited()){
                   next = i;
                   break;
               }
           }
           if(next>=0) setCurrentIndex(model()->index(next,currentIndex().column()));
           return;
       }
    }

    QTreeView::keyPressEvent(event);
}
Ejemplo n.º 19
0
    QPoint wep[2];
    int we[2];

    ds >> type
        >> e.context
        >> ke[0]
        >> ke[1]
        >> ke[2]
        >> me[0]
        >> mepf
        >> me[1]
        >> me[2]
        >> me[3]
        >> wepf[0]
        >> wepf[1]
        >> wep[0]
        >> wep[1]
        >> we[0]
        >> we[1];

    e.type = static_cast<QVREventType>(type);
    e.keyEvent = QKeyEvent(static_cast<QEvent::Type>(ke[0]), ke[1], static_cast<Qt::KeyboardModifier>(ke[2]));
    e.mouseEvent = QMouseEvent(static_cast<QEvent::Type>(me[0]), mepf,
            static_cast<Qt::MouseButton>(me[1]), static_cast<Qt::MouseButtons>(me[2]),
            static_cast<Qt::KeyboardModifier>(me[3]));
    e.wheelEvent = QWheelEvent(wepf[0], wepf[1], wep[0], wep[1], 0, Qt::Horizontal,
            static_cast<Qt::MouseButtons>(we[0]), static_cast<Qt::KeyboardModifier>(we[1]));

    return ds;
}
QKeyEvent CreateEnter() noexcept { return QKeyEvent(QEvent::KeyPress,Qt::Key_Enter,Qt::NoModifier); }