Esempio n. 1
0
/*
    \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;
}