2014-07-07 17:08:30 +00:00
|
|
|
#include "filter.h"
|
|
|
|
#include <QKeyEvent>
|
2014-07-09 14:18:48 +00:00
|
|
|
#include <QDebug>
|
2014-07-07 17:08:30 +00:00
|
|
|
|
|
|
|
filter::filter(QObject *parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
2014-07-13 12:27:50 +00:00
|
|
|
m_tabPressed = false;
|
2014-07-07 17:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool filter::eventFilter(QObject *obj, QEvent *ev) {
|
|
|
|
switch(ev->type()) {
|
|
|
|
case QEvent::KeyPress: {
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent*>(ev);
|
2014-07-13 12:27:50 +00:00
|
|
|
if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) {
|
|
|
|
if(m_tabPressed)
|
|
|
|
break;
|
|
|
|
else m_tabPressed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString sks;
|
|
|
|
if(ke->key() == Qt::Key_Control) {
|
|
|
|
sks = "Ctrl";
|
2014-07-16 13:02:16 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
} else if(ke->key() == Qt::Key_Meta) {
|
|
|
|
sks = "Ctrl";
|
|
|
|
#endif
|
2014-07-09 14:18:48 +00:00
|
|
|
} else {
|
|
|
|
QKeySequence ks(ke->modifiers() + ke->key());
|
2014-07-13 12:27:50 +00:00
|
|
|
sks = ks.toString();
|
2014-07-07 17:08:30 +00:00
|
|
|
}
|
2014-07-16 12:40:09 +00:00
|
|
|
#ifndef Q_OS_MAC
|
|
|
|
if(sks.contains("Alt+Tab") || sks.contains("Alt+Shift+Backtab"))
|
|
|
|
break;
|
2014-07-16 13:02:16 +00:00
|
|
|
#else
|
|
|
|
sks.replace("Meta", "Ctrl");
|
2014-07-16 12:40:09 +00:00
|
|
|
#endif
|
2014-07-13 12:27:50 +00:00
|
|
|
emit sequencePressed(QVariant::fromValue<QObject*>(obj), sks);
|
2014-07-07 17:08:30 +00:00
|
|
|
} break;
|
|
|
|
case QEvent::KeyRelease: {
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent*>(ev);
|
2014-07-13 12:27:50 +00:00
|
|
|
if(ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab)
|
|
|
|
m_tabPressed = false;
|
|
|
|
|
|
|
|
QString sks;
|
|
|
|
if(ke->key() == Qt::Key_Control) {
|
|
|
|
sks = "Ctrl";
|
2014-07-16 13:02:16 +00:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
} else if(ke->key() == Qt::Key_Meta) {
|
|
|
|
sks = "Ctrl";
|
|
|
|
#endif
|
2014-07-13 12:27:50 +00:00
|
|
|
} else {
|
|
|
|
QKeySequence ks(ke->modifiers() + ke->key());
|
|
|
|
sks = ks.toString();
|
2014-07-07 17:08:30 +00:00
|
|
|
}
|
2014-07-16 12:40:09 +00:00
|
|
|
#ifndef Q_OS_MAC
|
|
|
|
if(sks.contains("Alt+Tab") || sks.contains("Alt+Shift+Backtab"))
|
|
|
|
break;
|
2014-07-16 13:02:16 +00:00
|
|
|
#else
|
|
|
|
sks.replace("Meta", "Ctrl");
|
2014-07-16 12:40:09 +00:00
|
|
|
#endif
|
2014-07-13 12:27:50 +00:00
|
|
|
emit sequenceReleased(QVariant::fromValue<QObject*>(obj), sks);
|
2014-07-07 17:08:30 +00:00
|
|
|
} break;
|
2014-07-09 14:18:48 +00:00
|
|
|
case QEvent::MouseButtonPress: {
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent*>(ev);
|
|
|
|
emit mousePressed(QVariant::fromValue<QObject*>(obj), me->x(), me->y());
|
|
|
|
} break;
|
|
|
|
case QEvent::MouseButtonRelease: {
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent*>(ev);
|
|
|
|
emit mouseReleased(QVariant::fromValue<QObject*>(obj), me->x(), me->y());
|
|
|
|
} break;
|
2014-07-07 17:08:30 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QObject::eventFilter(obj, ev);
|
|
|
|
}
|