forked from SpineML/SpineCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilteroutundoredoevents.cpp
63 lines (59 loc) · 1.57 KB
/
filteroutundoredoevents.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "filteroutundoredoevents.h"
#include <QEvent>
#include <QShortcutEvent>
#include <QDebug>
#include <QComboBox>
FilterOutUndoRedoEvents::FilterOutUndoRedoEvents(QObject *parent) :
QObject(parent)
{
}
/*!
* \brief FilterOutUndoRedoEvents::eventFilter
* \param event
* \return
* This is a filter to prevent the QWidgets from using their built in undo and redo functions,
* and to prevent the mousewheels changing the values when scrolling down the page.
*/
bool FilterOutUndoRedoEvents::eventFilter(QObject * obj, QEvent *event)
{
const QEvent::Type type = event->type();
switch (type)
{
case QEvent::ShortcutOverride:
{
QKeyEvent * key = static_cast<QKeyEvent *>(event);
if (key->key() == Qt::Key_Z) {
//qDebug() << "Z";
event->ignore();
return true;
} else {
//qDebug() << "not Z";
event->accept();
return false;
}
}
case QEvent::Wheel:
{
// if we are attached to a ComboBox
QComboBox * combo = qobject_cast<QComboBox*>(obj);
if (combo) {
// if the ComboBox is focused then allow scroll
if (combo->hasFocus()) {
event->accept();
return false;
} else {
event->ignore();
return true;
}
} else {
// if it is not a combobox then deny scroll
event->ignore();
return true;
}
}
default:
event->accept();
return false;
}
return false;
}