BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
customeventfilters.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/viewmodel/mvvm/editors/customeventfilters.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include <QAbstractSpinBox>
17 #include <QComboBox>
18 #include <QEvent>
19 
20 using namespace ModelView;
21 
22 LostFocusFilter::LostFocusFilter(QObject* parent) : QObject(parent) {}
23 
24 bool LostFocusFilter::eventFilter(QObject* obj, QEvent* event)
25 {
26  if (event->type() == QEvent::FocusOut)
27  return true;
28 
29  return QObject::eventFilter(obj, event);
30 }
31 
32 // ----------------------------------------------------------------------------
33 
34 WheelEventFilter::WheelEventFilter(QObject* parent) : QObject(parent) {}
35 
36 bool WheelEventFilter::eventFilter(QObject* obj, QEvent* event)
37 {
38  if (auto spinBox = qobject_cast<QAbstractSpinBox*>(obj); spinBox) {
39  if (event->type() == QEvent::Wheel) {
40  if (spinBox->focusPolicy() == Qt::WheelFocus) {
41  event->accept();
42  return false;
43  } else {
44  event->ignore();
45  return true;
46  }
47  } else if (event->type() == QEvent::FocusIn) {
48  spinBox->setFocusPolicy(Qt::WheelFocus);
49  } else if (event->type() == QEvent::FocusOut) {
50  spinBox->setFocusPolicy(Qt::StrongFocus);
51  }
52 
53  } else if (auto comboBox = qobject_cast<QComboBox*>(obj); comboBox) {
54  if (event->type() == QEvent::Wheel) {
55  event->ignore();
56  return true;
57  } else {
58  event->accept();
59  return false;
60  }
61  }
62  return QObject::eventFilter(obj, event);
63 }
bool eventFilter(QObject *obj, QEvent *event) override
LostFocusFilter(QObject *parent=nullptr)
WheelEventFilter(QObject *parent=nullptr)
bool eventFilter(QObject *obj, QEvent *event)
Defines class CLASS?
materialitems.h Collection of materials to populate MaterialModel.