Skip to content
Snippets Groups Projects
Commit 5955d46e authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Mouse wheel events interception localized in custom editors.

parent 70ccbb48
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,6 @@
#include "SessionModel.h"
#include "LayoutUtils.h"
#include "PropertyWidgetItem.h"
#include "CustomEventFilters.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QGridLayout>
......@@ -35,7 +34,6 @@ ComponentFlatView::ComponentFlatView(QWidget* parent)
, m_gridLayout(nullptr)
, m_model(nullptr)
, m_show_children(true)
, m_wheel_event_filter(new WheelEventEater)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......@@ -170,25 +168,8 @@ PropertyWidgetItem* ComponentFlatView::createWidget(const SessionItem* item)
if (!editor)
return nullptr;
install_custom_filters(editor);
auto result = new PropertyWidgetItem(this);
result->setItemEditor(item, editor);
return result;
}
void ComponentFlatView::install_custom_filters(QWidget* editor)
{
editor->installEventFilter(m_wheel_event_filter.get());
editor->setFocusPolicy(Qt::StrongFocus);
for(auto w : editor->findChildren<QAbstractSpinBox *>()) {
w->installEventFilter(m_wheel_event_filter.get());
w->setFocusPolicy(Qt::StrongFocus);
}
for(auto w : editor->findChildren<QComboBox *>())
w->installEventFilter(m_wheel_event_filter.get());
}
......@@ -25,7 +25,6 @@ class SessionModel;
class QGridLayout;
class QBoxLayout;
class PropertyWidgetItem;
class WheelEventEater;
//! Component property widget for SessionItems. On the contrary to ComponentTreeView
//! properties are presented as widgets in grid layout.
......@@ -58,14 +57,11 @@ private:
void initGridLayout();
PropertyWidgetItem* createWidget(const SessionItem* item);
void install_custom_filters(QWidget* editor);
QBoxLayout* m_mainLayout;
QGridLayout* m_gridLayout;
QVector<PropertyWidgetItem*> m_widgetItems;
SessionModel* m_model;
bool m_show_children;
std::unique_ptr<WheelEventEater> m_wheel_event_filter;
QVector<const SessionItem*> m_topItems;
};
......
......@@ -162,6 +162,7 @@ void ColorPropertyEditor::initEditor()
CustomComboEditor::CustomComboEditor(QWidget* parent)
: CustomEditor(parent)
, m_box(new QComboBox)
, m_wheel_event_filter(new WheelEventEater(this))
{
setAutoFillBackground(true);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
......@@ -171,6 +172,8 @@ CustomComboEditor::CustomComboEditor(QWidget* parent)
layout->setSpacing(0);
layout->addWidget(m_box);
m_box->installEventFilter(m_wheel_event_filter);
setLayout(layout);
setConnected(true);
}
......
......@@ -109,7 +109,8 @@ protected:
virtual int internIndex();
void setConnected(bool isConnected);
QComboBox* m_box;
QComboBox* m_box;
class WheelEventEater* m_wheel_event_filter;
};
//! Editor for GroupProperty variant.
......@@ -151,9 +152,6 @@ protected:
//! Editor for ScientificDoubleProperty variant.
class QLineEdit;
class QDoubleValidator;
class BA_CORE_API_ ScientificDoublePropertyEditor : public CustomEditor
{
Q_OBJECT
......@@ -167,8 +165,8 @@ protected:
void initEditor();
private:
QLineEdit* m_lineEdit;
QDoubleValidator* m_validator;
class QLineEdit* m_lineEdit;
class QDoubleValidator* m_validator;
};
//! Editor for boolean.
......
......@@ -22,6 +22,7 @@
#include "CustomEditors.h"
#include "ComboProperty.h"
#include "ColorProperty.h"
#include "CustomEventFilters.h"
#include <QDoubleSpinBox>
#include <QSpinBox>
#include <QLineEdit>
......@@ -183,6 +184,9 @@ QWidget* createCustomDoubleEditor(const SessionItem& item)
auto result = new QDoubleSpinBox;
result->setKeyboardTracking(false);
result->setFocusPolicy(Qt::StrongFocus);
result->installEventFilter(new WheelEventEater(result));
result->setMaximum(std::numeric_limits<double>::max());
result->setMinimum(std::numeric_limits<double>::lowest());
......@@ -202,6 +206,8 @@ QWidget* createCustomDoubleEditor(const SessionItem& item)
QWidget* createCustomIntEditor(const SessionItem& item)
{
auto result = new QSpinBox;
result->setFocusPolicy(Qt::StrongFocus);
result->installEventFilter(new WheelEventEater(result));
result->setMaximum(std::numeric_limits<int>::max());
result->setKeyboardTracking(false);
......
......@@ -102,6 +102,10 @@ void PropertyWidgetItem::connectEditor(QWidget* editor)
connect(combo, &ComboPropertyEditor::currentIndexChanged,
[=] { m_delegate->commitData(combo); });
// TODO after merging GroupProperty and ComboProperty
// 1) cast to CustomEditor
// 2) switch to CustomEditor::dataChanged()
} else if (auto spinbox = dynamic_cast<QSpinBox*>(editor)) {
// To provide update of the model on valueChanged() and not only on editingFinished()
connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment