44 #include "SpinBoxEventFilter.hh" 46 #include <QAbstractSpinBox> 51 #ifdef VERBOSE_DEBUGGING_OUTPUT 55 SpinBoxEventFilter::SpinBoxEventFilter(QObject *parent) :
56 QObject(parent), scrolling(false) {
58 scrollingTimer.setSingleShot(
true);
59 scrollingTimer.setInterval(500);
61 connect(&scrollingTimer, SIGNAL( timeout() ),
this, SLOT( unsetScrolling() ));
64 SpinBoxEventFilter::~SpinBoxEventFilter() {
67 bool SpinBoxEventFilter::eventFilter(QObject *
object, QEvent *event) {
69 if (event->type() != QEvent::Wheel)
return QObject::eventFilter(
object, event);
71 QWidget *widget = qobject_cast<QWidget*>(object);
73 if (scrollAreas.find(widget) != scrollAreas.end()) {
74 #ifdef VERBOSE_DEBUGGING_OUTPUT 75 std::cout <<
"Reset isScrolling." << std::endl;
78 return QObject::eventFilter(
object, event);
81 if (!isScrolling() && widget->isEnabled()) {
82 #ifdef VERBOSE_DEBUGGING_OUTPUT 83 std::cout <<
"Not scrolling. Letting wheel event pass." << std::endl;
85 return QObject::eventFilter(
object, event);
90 #ifdef VERBOSE_DEBUGGING_OUTPUT 91 std::cout <<
"Swallowing wheel event." << std::endl;
101 inline bool SpinBoxEventFilter::isScrolling() {
105 void SpinBoxEventFilter::hookUpToWidgetTree(QWidget *root_widget) {
106 std::stack<QWidget*> dfs;
107 dfs.push(root_widget);
109 while (!dfs.empty()) {
110 QWidget *cur = dfs.top(); dfs.pop();
112 cur->installEventFilter(
this);
114 const QObjectList &children = cur->children();
115 for (QObjectList::const_iterator it = children.begin(), it_end = children.end();
116 it != it_end; ++it) {
118 QWidget *widget = qobject_cast<QWidget*>(*it);
125 void SpinBoxEventFilter::registerScrollArea(QWidget *scrollArea) {
126 scrollAreas.insert(scrollArea);
127 scrollArea->installEventFilter(
this);
130 void SpinBoxEventFilter::setScrolling() {
132 scrollingTimer.start();
135 void SpinBoxEventFilter::unsetScrolling() {
136 #ifdef VERBOSE_DEBUGGING_OUTPUT 137 std::cout <<
"Scrolling timeout." << std::endl;