1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2015 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 <MUtils/Global.h>
33 #include <QMouseEvent>
36 InputEventFilter::InputEventFilter(QWidget
*target
)
39 m_keyMapping(new QHash
<int, int>()),
40 m_mouseMapping(new QHash
<int, int>())
42 m_target
->installEventFilter(this);
45 InputEventFilter::~InputEventFilter(void)
47 m_target
->removeEventFilter(this);
48 MUTILS_DELETE(m_keyMapping
);
49 MUTILS_DELETE(m_mouseMapping
);
52 void InputEventFilter::addKeyFilter(const int &keyCode
, const int &tag
)
54 m_keyMapping
->insert(keyCode
, tag
);
57 void InputEventFilter::addMouseFilter(const int &mouseCode
, const int &tag
)
59 m_mouseMapping
->insert(mouseCode
, tag
);
62 bool InputEventFilter::eventFilter(QObject
*obj
, QEvent
*event
)
66 if(event
->type() == QEvent::KeyPress
)
68 QKeyEvent
*keyEvent
= dynamic_cast<QKeyEvent
*>(event
);
71 return eventFilter(keyEvent
);
74 else if(event
->type() == QEvent::MouseButtonPress
)
76 QMouseEvent
*mouseEvent
= dynamic_cast<QMouseEvent
*>(event
);
79 return eventFilter(mouseEvent
);
86 bool InputEventFilter::eventFilter(QKeyEvent
*keyEvent
)
88 const int keyCode
= keyEvent
->key() | keyEvent
->modifiers();
89 if(m_keyMapping
->contains(keyCode
))
91 emit
keyPressed(m_keyMapping
->value(keyCode
));
97 bool InputEventFilter::eventFilter(QMouseEvent
*mouseEvent
)
99 if(m_mouseMapping
->contains(mouseEvent
->button()))
101 emit
mouseClicked(m_mouseMapping
->value(mouseEvent
->button()));