59 #include "SpinBoxEventFilter.hh"
61 #include <QAbstractSpinBox>
66 #ifdef VERBOSE_DEBUGGING_OUTPUT
70 SpinBoxEventFilter::SpinBoxEventFilter(QObject *parent) :
71 QObject(parent), scrolling(false) {
73 scrollingTimer.setSingleShot(
true);
74 scrollingTimer.setInterval(500);
76 connect(&scrollingTimer, SIGNAL( timeout() ),
this, SLOT( unsetScrolling() ));
79 SpinBoxEventFilter::~SpinBoxEventFilter() {
82 bool SpinBoxEventFilter::eventFilter(QObject *
object, QEvent *event) {
84 if (event->type() != QEvent::Wheel)
return QObject::eventFilter(
object, event);
86 QWidget *widget = qobject_cast<QWidget*>(object);
88 if (scrollAreas.find(widget) != scrollAreas.end()) {
89 #ifdef VERBOSE_DEBUGGING_OUTPUT
90 std::cout <<
"Reset isScrolling." << std::endl;
93 return QObject::eventFilter(
object, event);
96 if (!isScrolling() && widget->isEnabled()) {
97 #ifdef VERBOSE_DEBUGGING_OUTPUT
98 std::cout <<
"Not scrolling. Letting wheel event pass." << std::endl;
100 return QObject::eventFilter(
object, event);
105 #ifdef VERBOSE_DEBUGGING_OUTPUT
106 std::cout <<
"Swallowing wheel event." << std::endl;
116 inline bool SpinBoxEventFilter::isScrolling() {
120 void SpinBoxEventFilter::hookUpToWidgetTree(QWidget *root_widget) {
121 std::stack<QWidget*> dfs;
122 dfs.push(root_widget);
124 while (!dfs.empty()) {
125 QWidget *cur = dfs.top(); dfs.pop();
127 cur->installEventFilter(
this);
129 const QObjectList &children = cur->children();
130 for (QObjectList::const_iterator it = children.begin(), it_end = children.end();
131 it != it_end; ++it) {
133 QWidget *widget = qobject_cast<QWidget*>(*it);
140 void SpinBoxEventFilter::registerScrollArea(QWidget *scrollArea) {
141 scrollAreas.insert(scrollArea);
142 scrollArea->installEventFilter(
this);
145 void SpinBoxEventFilter::setScrolling() {
147 scrollingTimer.start();
150 void SpinBoxEventFilter::unsetScrolling() {
151 #ifdef VERBOSE_DEBUGGING_OUTPUT
152 std::cout <<
"Scrolling timeout." << std::endl;