Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/mixxxkeyboard.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           mixxxkeyboard.cpp  -  description
00003                              -------------------
00004     begin                : Wed Dec 2 2003
00005     copyright            : (C) 2003 by Tue Haste Andersen
00006     email                :
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 ***************************************************************************/
00017 
00018 #include "mixxxkeyboard.h"
00019 #include "controlobject.h"
00020 #include <QList>
00021 #include <QtDebug>
00022 #include <QKeyEvent>
00023 #include <QEvent>
00024 
00025 MixxxKeyboard::MixxxKeyboard(ConfigObject<ConfigValueKbd> * pKbdConfigObject, QObject * parent, const char * name) : QObject(parent)
00026 {
00027     m_pKbdConfigObject = pKbdConfigObject;
00028     setObjectName(name);
00029 }
00030 
00031 MixxxKeyboard::~MixxxKeyboard()
00032 {
00033    // TODO(XXX) ugly workaround to get no leak
00034    delete m_pKbdConfigObject;
00035 }
00036 
00037 bool MixxxKeyboard::eventFilter(QObject *, QEvent * e)
00038 {
00039     if (e->type()==QEvent::KeyPress)
00040     {
00041         QKeyEvent * ke = (QKeyEvent *)e;
00042 
00043         //qDebug() << "press";
00044         bool autoRepeat = ke->isAutoRepeat();
00045 
00046         if (kbdPress(getKeySeq(ke), false, autoRepeat)) {
00047             // Add key to active key list
00048             if (!autoRepeat)
00049                 m_qActiveKeyList.append(ke->key());
00050 
00051             return true;
00052         }
00053     }
00054     else if (e->type()==QEvent::KeyRelease)
00055     {
00056         QKeyEvent * ke = (QKeyEvent *)e;
00057 
00058         // Run through list of active keys to see if the released key is active
00059         int key = -1;
00060         QListIterator<int> it(m_qActiveKeyList);
00061 
00062         while (it.hasNext())
00063         {
00064             key = it.next();
00065             if (key == ke->key())
00066             {
00067                 //qDebug() << "release";
00068 
00069                 bool autoRepeat = ke->isAutoRepeat();
00070                 if (kbdPress(getKeySeq(ke), true, autoRepeat)) {
00071                     if (!autoRepeat) {
00072                         //qDebug() << "release else";
00073                         m_qActiveKeyList.removeOne(key);
00074                     }
00075                     return true;
00076                 }
00077                 return false;
00078             }
00079         }
00080     }
00081 
00082     return false;
00083 }
00084 
00085 bool MixxxKeyboard::kbdPress(QKeySequence k, bool release, bool autoRepeat)
00086 {
00087     bool react = false;
00088 
00089     if (!k.isEmpty())
00090     {
00091         // Check if a shortcut is defined
00092         ConfigKey * pConfigKey = m_pKbdConfigObject->get(ConfigValueKbd(k));
00093 
00094         react = pConfigKey != NULL;
00095 
00096         if (pConfigKey && !autoRepeat)
00097         {
00098             if (release) {
00099                 //qDebug() << "Sending MIDI NOTE_OFF";
00100                 ControlObject::getControl(*pConfigKey)->queueFromMidi(NOTE_OFF, 0);
00101             }
00102             else
00103             {
00104                 //qDebug() << "Sending MIDI NOTE_ON";
00105                 ControlObject::getControl(*pConfigKey)->queueFromMidi(NOTE_ON, 1);
00106             }
00107         }
00108     }
00109     return react;
00110 }
00111 
00112 QKeySequence MixxxKeyboard::getKeySeq(QKeyEvent * e)
00113 {
00114     QString modseq = QString::null;
00115         QString keyseq = QString::null;
00116 
00117 
00118         if (e->modifiers() & Qt::ShiftModifier)
00119                modseq += "Shift+";
00120 
00121         if (e->modifiers() & Qt::ControlModifier)
00122                 modseq += "Ctrl+";
00123 
00124         if (e->modifiers() & Qt::AltModifier)
00125                 modseq += "Alt+";
00126 
00127         if (e->modifiers() & Qt::MetaModifier)
00128                 modseq += "Meta+";
00129 
00130         keyseq = (QString)QKeySequence(e->key());
00131 
00132         QString seq = modseq + keyseq;
00133         QKeySequence k = QKeySequence(seq);
00134         //qDebug() << "keyboard press: " << k;
00135         return k;
00136 }
00137 
00138 ConfigObject<ConfigValueKbd>* MixxxKeyboard::getKeyboardConfig() {
00139     return m_pKbdConfigObject;
00140 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines