Esempio n. 1
0
bool MixxxKeyboard::eventFilter(QObject*, QEvent* e) {
    if (e->type() == QEvent::FocusOut) {
        // If we lose focus, we need to clear out the active key list
        // because we might not get Key Release events.
        m_qActiveKeyList.clear();
    } else if (e->type() == QEvent::KeyPress) {
        QKeyEvent* ke = (QKeyEvent *)e;

#ifdef __APPLE__
        // On Mac OSX the nativeScanCode is empty (const 1) http://doc.qt.nokia.com/4.7/qkeyevent.html#nativeScanCode
        // We may loose the release event if a the shift key is pressed later
        // and there is character shift like "1" -> "!"
        int keyId = ke->key();
#else
        int keyId = ke->nativeScanCode();
#endif
        //qDebug() << "KeyPress event =" << ke->key() << "KeyId =" << keyId;

        // Run through list of active keys to see if the pressed key is already active
        // Just for returning true if we are consuming this key event

        foreach (const KeyDownInformation& keyDownInfo, m_qActiveKeyList) {
            if (keyDownInfo.keyId == keyId) {
                return true;
            }
        }

        QKeySequence ks = getKeySeq(ke);
        if (!ks.isEmpty()) {
            ConfigValueKbd ksv(ks);
            // Check if a shortcut is defined
            bool result = false;
            // using const_iterator here is faster than QMultiHash::values()
            for (QMultiHash<ConfigValueKbd, ConfigKey>::const_iterator it =
                         m_keySequenceToControlHash.find(ksv);
                 it != m_keySequenceToControlHash.end() && it.key() == ksv; ++it) {
                const ConfigKey& configKey = it.value();
                if (configKey.group != "[KeyboardShortcuts]") {
                    ControlObject* control = ControlObject::getControl(configKey);
                    if (control) {
                        //qDebug() << configKey << "MIDI_NOTE_ON" << 1;
                        // Add key to active key list
                        m_qActiveKeyList.append(KeyDownInformation(
                            keyId, ke->modifiers(), control));
                        // Since setting the value might cause us to go down
                        // a route that would eventually clear the active
                        // key list, do that last.
                        control->setValueFromMidi(MIDI_NOTE_ON, 1);
                        result = true;
                    } else {
                        qDebug() << "Warning: Keyboard key is configured for nonexistent control:"
                                 << configKey.group << configKey.item;
                    }
                }
            }
            return result;
        }
    } else if (e->type()==QEvent::KeyRelease) {
Esempio n. 2
0
bool MixxxKeyboard::eventFilter(QObject*, QEvent* e) {
    if (e->type() == QEvent::KeyPress) {
        QKeyEvent* ke = (QKeyEvent *)e;

#ifdef __APPLE__
        // On Mac OSX the nativeScanCode is empty (const 1) http://doc.qt.nokia.com/4.7/qkeyevent.html#nativeScanCode
        // We may loose the release event if a the shift key is pressed later
        // and there is character shift like "1" -> "!"
        int keyId = ke->key();
#else
        int keyId = ke->nativeScanCode();
#endif
        //qDebug() << "KeyPress event =" << ke->key() << "KeyId =" << keyId;

        // Run through list of active keys to see if the pressed key is already active
        // Just for returning true if we are consuming this key event

        foreach (const KeyDownInformation& keyDownInfo, m_qActiveKeyList) {
            if (keyDownInfo.keyId == keyId) {
                return true;
            }
        }

        QKeySequence ks = getKeySeq(ke);
        if (!ks.isEmpty()) {
            // Check if a shortcut is defined
            ConfigKey* pConfigKey = m_pKbdConfigObject->get(ConfigValueKbd(ks));
            if (pConfigKey && pConfigKey->group != "[KeyboardShortcuts]") {
                ControlObject* control = ControlObject::getControl(*pConfigKey);
                if (control) {
                    //qDebug() << pConfigKey->group << pConfigKey->item << "MIDI_NOTE_ON" << 1;
                    control->setValueFromMidi(MIDI_NOTE_ON, 1);
                    // Add key to active key list
                    m_qActiveKeyList.append(KeyDownInformation(
                        keyId, ke->modifiers(), pConfigKey));
                    return true;
                } else {
                    qDebug() << "Warning: Keyboard key is configured for nonexistent control: "
                             << pConfigKey->group << " " << pConfigKey->item;
                    return false;
                }
            }
        }
    } else if (e->type()==QEvent::KeyRelease) {