Commit 67b87c31 authored by Hans-Christian Ebke's avatar Hans-Christian Ebke

Spin boxes and the like don't steal mouse wheel focus when scrolling anymore....

Spin boxes and the like don't steal mouse wheel focus when scrolling anymore. You can buy me a beer to thank me.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17184 383ad7c9-94d9-4d36-a494-682f7c89f535
parent fec5c26e
......@@ -254,6 +254,10 @@ Core::init() {
coreWidget_ = new CoreWidget(viewModes_ , plugins_, coreSlots_);
spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxScrollArea());
spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolboxArea());
spinBoxEventFilter_.registerScrollArea(coreWidget_->getToolbox());
connect(coreWidget_, SIGNAL(clearAll()) , this, SLOT(clearAll()));
connect(coreWidget_, SIGNAL(loadMenu()) , this, SLOT(loadObject()));
connect(coreWidget_, SIGNAL(addEmptyObjectMenu()) , this, SLOT(slotAddEmptyObjectMenu()));
......
......@@ -116,6 +116,7 @@
#include <OpenFlipper/common/FileTypes.hh>
#include <OpenFlipper/common/InformationPlugins.hh>
#include "SpinBoxEventFilter.hh"
//== CLASS DEFINITION =========================================================
......@@ -1462,6 +1463,8 @@ private slots:
* Checks if the used libraries are consistent
*/
bool checkLibraryVersions();
void hookUpEventFilter(QWidget *widget);
private :
......@@ -1497,6 +1500,8 @@ private slots:
/// If enabled, this timer will block screen refresh if done more then 30 times per second.
QTimer* redrawTimer_;
SpinBoxEventFilter spinBoxEventFilter_;
};
......
/*
* SpinBoxEventFilter.cc
*
* Created on: Aug 1, 2013
* Author: ebke
*/
//#define VERBOSE_DEBUGGING_OUTPUT
#include "SpinBoxEventFilter.hh"
#include <QAbstractSpinBox>
#include <QAbstractSlider>
#include <QEvent>
#include <QWidget>
#include <QObjectList>
#include <QMetaEnum>
#include <stack>
#ifdef VERBOSE_DEBUGGING_OUTPUT
#include <iostream>
#endif
SpinBoxEventFilter::SpinBoxEventFilter(QObject *parent) :
QObject(parent), scrolling(false) {
scrollingTimer.setSingleShot(true);
scrollingTimer.setInterval(500);
connect(&scrollingTimer, SIGNAL( timeout() ), this, SLOT( unsetScrolling() ));
}
SpinBoxEventFilter::~SpinBoxEventFilter() {
}
bool SpinBoxEventFilter::eventFilter(QObject *object, QEvent *event) {
if (event->type() != QEvent::Wheel) return QObject::eventFilter(object, event);
/*
* We only need the QWidget-Pointer to check whether object
* is contained in scrollAreas, so a static_cast is safe here
* (and faster than a dynamic_cast).
*/
if (scrollAreas.find(static_cast<QWidget*>(object)) != scrollAreas.end()) {
#ifdef VERBOSE_DEBUGGING_OUTPUT
std::cout << "Reset isScrolling." << std::endl;
#endif
setScrolling();
return QObject::eventFilter(object, event);
}
if (!isScrolling()) {
#ifdef VERBOSE_DEBUGGING_OUTPUT
std::cout << "Not scrolling. Letting wheel event pass." << std::endl;
#endif
return QObject::eventFilter(object, event);
}
setScrolling();
event->ignore();
#ifdef VERBOSE_DEBUGGING_OUTPUT
std::cout << "Swallowing wheel event." << std::endl;
#endif
return true;
//#ifdef VERBOSE_DEBUGGING_OUTPUT
// std::cout << "Not a spin box. Letting wheel event pass." << std::endl;
//#endif
// return QObject::eventFilter(object, event);
}
inline bool SpinBoxEventFilter::isScrolling() {
return scrolling;
}
void SpinBoxEventFilter::hookUpToWidgetTree(QWidget *root_widget) {
std::stack<QWidget*> dfs;
dfs.push(root_widget);
while (!dfs.empty()) {
QWidget *cur = dfs.top(); dfs.pop();
cur->installEventFilter(this);
const QObjectList &children = cur->children();
for (QObjectList::const_iterator it = children.begin(), it_end = children.end();
it != it_end; ++it) {
QWidget *widget = qobject_cast<QWidget*>(*it);
if (widget)
dfs.push(widget);
}
}
}
void SpinBoxEventFilter::registerScrollArea(QWidget *scrollArea) {
scrollAreas.insert(scrollArea);
scrollArea->installEventFilter(this);
}
void SpinBoxEventFilter::setScrolling() {
scrolling = true;
scrollingTimer.start();
}
void SpinBoxEventFilter::unsetScrolling() {
#ifdef VERBOSE_DEBUGGING_OUTPUT
std::cout << "Scrolling timeout." << std::endl;
#endif
scrolling = false;
}
/*
* SpinBoxEventFilter.hh
*
* Created on: Aug 1, 2013
* Author: ebke
*/
#ifndef SPINBOXEVENTFILTER_HH_
#define SPINBOXEVENTFILTER_HH_
#include <QObject>
#include <QTimer>
#include <set>
class SpinBoxEventFilter : public QObject {
Q_OBJECT
public:
SpinBoxEventFilter(QObject *parent = 0);
virtual ~SpinBoxEventFilter();
bool eventFilter(QObject *object, QEvent *event);
bool isScrolling();
void hookUpToWidgetTree(QWidget *widget);
void registerScrollArea(QWidget *scrollArea);
private:
void setScrolling();
private slots:
void unsetScrolling();
private:
std::set<QWidget*> scrollAreas;
bool scrolling;
QTimer scrollingTimer;
};
#endif /* SPINBOXEVENTFILTER_HH_ */
......@@ -267,6 +267,7 @@ void Core::addToolbox(QString _name ,QWidget* _widget) {
}
}
spinBoxEventFilter_.hookUpToWidgetTree(_widget);
plugins_[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
plugins_[id].toolboxIcons.push_back( 0 );
......@@ -308,6 +309,7 @@ void Core::addToolbox(QString _name ,QWidget* _widget, QIcon* _icon) {
}
}
spinBoxEventFilter_.hookUpToWidgetTree(_widget);
plugins_[id].toolboxWidgets.push_back( std::pair< QString,QWidget* >( _name , _widget) );
plugins_[id].toolboxIcons.push_back( _icon );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment