1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "input_filter.h"
28 #include <QMouseEvent>
31 InputEventFilter::InputEventFilter(QWidget *target)
34 m_keyMapping(new QHash<int, int>()),
35 m_mouseMapping(new QHash<int, int>())
37 m_target->installEventFilter(this);
40 InputEventFilter::~InputEventFilter(void)
42 m_target->removeEventFilter(this);
43 X264_DELETE(m_keyMapping);
44 X264_DELETE(m_mouseMapping);
47 void InputEventFilter::addKeyFilter(const int &keyCode, const int &tag)
49 m_keyMapping->insert(keyCode, tag);
52 void InputEventFilter::addMouseFilter(const int &mouseCode, const int &tag)
54 m_mouseMapping->insert(mouseCode, tag);
57 bool InputEventFilter::eventFilter(QObject *obj, QEvent *event)
61 if(event->type() == QEvent::KeyPress)
63 QKeyEvent *keyEvent = dynamic_cast<QKeyEvent*>(event);
66 return eventFilter(keyEvent);
69 else if(event->type() == QEvent::MouseButtonPress)
71 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
74 return eventFilter(mouseEvent);
81 bool InputEventFilter::eventFilter(QKeyEvent *keyEvent)
83 const int keyCode = keyEvent->key() | keyEvent->modifiers();
84 if(m_keyMapping->contains(keyCode))
86 emit keyPressed(m_keyMapping->value(keyCode));
92 bool InputEventFilter::eventFilter(QMouseEvent *mouseEvent)
94 if(m_mouseMapping->contains(mouseEvent->button()))
96 emit mouseClicked(m_mouseMapping->value(mouseEvent->button()));