From 8280055e21fcd6e483fd642204d394595fa97e72 Mon Sep 17 00:00:00 2001 From: parax0 Date: Wed, 29 Jul 2015 00:41:23 -0400 Subject: [PATCH] Prevented spin boxes in property editor from stealing focus on wheel scroll --- PrimeWorldEditor.pro | 6 ++++-- UI/WDraggableSpinBox.cpp | 6 ++++++ UI/WDraggableSpinBox.h | 7 ++++--- UI/WIntegralSpinBox.cpp | 16 ++++++++++++++++ UI/WIntegralSpinBox.h | 16 ++++++++++++++++ UI/WPropertyEditor.cpp | 17 +++++++++++------ UI/WVectorEditor.cpp | 6 ++++++ 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 UI/WIntegralSpinBox.cpp create mode 100644 UI/WIntegralSpinBox.h diff --git a/PrimeWorldEditor.pro b/PrimeWorldEditor.pro index e12c4bd0..2dfc8083 100644 --- a/PrimeWorldEditor.pro +++ b/PrimeWorldEditor.pro @@ -131,7 +131,8 @@ SOURCES += \ Resource/CScan.cpp \ Resource/factory/CScanLoader.cpp \ UI/WStringPreviewPanel.cpp \ - UI/WScanPreviewPanel.cpp + UI/WScanPreviewPanel.cpp \ + UI/WIntegralSpinBox.cpp HEADERS += \ Common/AnimUtil.h \ @@ -277,7 +278,8 @@ HEADERS += \ Resource/CScan.h \ Resource/factory/CScanLoader.h \ UI/WStringPreviewPanel.h \ - UI/WScanPreviewPanel.h + UI/WScanPreviewPanel.h \ + UI/WIntegralSpinBox.h FORMS += \ UI/CWorldEditorWindow.ui \ diff --git a/UI/WDraggableSpinBox.cpp b/UI/WDraggableSpinBox.cpp index 61b0b91d..066a7e94 100644 --- a/UI/WDraggableSpinBox.cpp +++ b/UI/WDraggableSpinBox.cpp @@ -77,3 +77,9 @@ void WDraggableSpinBox::mouseMoveEvent(QMouseEvent*) mLastY = QCursor::pos().y(); } } + +void WDraggableSpinBox::wheelEvent(QWheelEvent *pEvent) +{ + if (!hasFocus()) pEvent->ignore(); + else QDoubleSpinBox::wheelEvent(pEvent); +} diff --git a/UI/WDraggableSpinBox.h b/UI/WDraggableSpinBox.h index 2374d7d3..f3f815ac 100644 --- a/UI/WDraggableSpinBox.h +++ b/UI/WDraggableSpinBox.h @@ -14,9 +14,10 @@ class WDraggableSpinBox : public QDoubleSpinBox public: explicit WDraggableSpinBox(QWidget *parent = 0); ~WDraggableSpinBox(); - void mousePressEvent(QMouseEvent *Event); - void mouseReleaseEvent(QMouseEvent *Event); - void mouseMoveEvent(QMouseEvent *Event); + void mousePressEvent(QMouseEvent *pEvent); + void mouseReleaseEvent(QMouseEvent *pEvent); + void mouseMoveEvent(QMouseEvent *pEvent); + void wheelEvent(QWheelEvent *pEvent); }; #endif // WDRAGGABLESPINBOX_H diff --git a/UI/WIntegralSpinBox.cpp b/UI/WIntegralSpinBox.cpp new file mode 100644 index 00000000..dacd2d3a --- /dev/null +++ b/UI/WIntegralSpinBox.cpp @@ -0,0 +1,16 @@ +#include "WIntegralSpinBox.h" +#include + +WIntegralSpinBox::WIntegralSpinBox(QWidget *pParent) : QSpinBox(pParent) +{ +} + +WIntegralSpinBox::~WIntegralSpinBox() +{ +} + +void WIntegralSpinBox::wheelEvent(QWheelEvent *pEvent) +{ + if (!hasFocus()) pEvent->ignore(); + else QSpinBox::wheelEvent(pEvent); +} diff --git a/UI/WIntegralSpinBox.h b/UI/WIntegralSpinBox.h new file mode 100644 index 00000000..2295a6e3 --- /dev/null +++ b/UI/WIntegralSpinBox.h @@ -0,0 +1,16 @@ +#ifndef WINTEGRALSPINBOX_H +#define WINTEGRALSPINBOX_H + +#include + +// Simple subclass to disable focus stealing on wheel event +class WIntegralSpinBox : public QSpinBox +{ + Q_OBJECT +public: + explicit WIntegralSpinBox(QWidget *pParent); + ~WIntegralSpinBox(); + void wheelEvent(QWheelEvent *pEvent); +}; + +#endif // WINTEGRALSPINBOX_H diff --git a/UI/WPropertyEditor.cpp b/UI/WPropertyEditor.cpp index fae719ee..8045fab8 100644 --- a/UI/WPropertyEditor.cpp +++ b/UI/WPropertyEditor.cpp @@ -1,5 +1,6 @@ #include "WPropertyEditor.h" #include "WDraggableSpinBox.h" +#include "WIntegralSpinBox.h" #include "WResourceSelector.h" #include "WColorPicker.h" #include "WVectorEditor.h" @@ -85,39 +86,42 @@ void WPropertyEditor::CreateEditor() break; } - // Byte - QSpinBox + // Byte - WIntegralSpinBox case eByteProperty: { CByteProperty *pByteCast = static_cast(mpProperty); - QSpinBox *pSpinBox = new QSpinBox(this); + QSpinBox *pSpinBox = new WIntegralSpinBox(this); pSpinBox->setRange(-128, 128); + pSpinBox->setFocusPolicy(Qt::StrongFocus); pSpinBox->setValue(pByteCast->Get()); mUI.EditorWidget = pSpinBox; break; } - // Short - QSpinBox + // Short - WIntegralSpinBox case eShortProperty: { CShortProperty *pShortCast = static_cast(mpProperty); - QSpinBox *pSpinBox = new QSpinBox(this); + QSpinBox *pSpinBox = new WIntegralSpinBox(this); pSpinBox->setRange(-32768, 32767); + pSpinBox->setFocusPolicy(Qt::StrongFocus); pSpinBox->setValue(pShortCast->Get()); mUI.EditorWidget = pSpinBox; break; } - // Long - QSpinBox + // Long - WIntegralSpinBox case eLongProperty: { CLongProperty *pLongCast = static_cast(mpProperty); - QSpinBox *pSpinBox = new QSpinBox(this); + QSpinBox *pSpinBox = new WIntegralSpinBox(this); pSpinBox->setRange(-2147483648, 2147483647); + pSpinBox->setFocusPolicy(Qt::StrongFocus); pSpinBox->setValue(pLongCast->Get()); mUI.EditorWidget = pSpinBox; @@ -131,6 +135,7 @@ void WPropertyEditor::CreateEditor() WDraggableSpinBox *pDraggableSpinBox = new WDraggableSpinBox(this); pDraggableSpinBox->setDecimals(4); + pDraggableSpinBox->setFocusPolicy(Qt::StrongFocus); pDraggableSpinBox->setValue(pFloatCast->Get()); mUI.EditorWidget = pDraggableSpinBox; diff --git a/UI/WVectorEditor.cpp b/UI/WVectorEditor.cpp index c554d7a8..415a00fd 100644 --- a/UI/WVectorEditor.cpp +++ b/UI/WVectorEditor.cpp @@ -7,6 +7,9 @@ WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent) mpSpinBoxX = new WDraggableSpinBox(this); mpSpinBoxY = new WDraggableSpinBox(this); mpSpinBoxZ = new WDraggableSpinBox(this); + mpSpinBoxX->setFocusPolicy(Qt::StrongFocus); + mpSpinBoxY->setFocusPolicy(Qt::StrongFocus); + mpSpinBoxZ->setFocusPolicy(Qt::StrongFocus); connect(mpSpinBoxX, SIGNAL(valueChanged(double)), this, SLOT(SetX(double))); connect(mpSpinBoxY, SIGNAL(valueChanged(double)), this, SLOT(SetY(double))); connect(mpSpinBoxZ, SIGNAL(valueChanged(double)), this, SLOT(SetZ(double))); @@ -46,6 +49,9 @@ WVectorEditor::WVectorEditor(const CVector3f& Value, QWidget *pParent) : QWidget mpSpinBoxX->setMaximumHeight(21); mpSpinBoxY->setMaximumHeight(21); mpSpinBoxZ->setMaximumHeight(21); + mpSpinBoxX->setFocusPolicy(Qt::StrongFocus); + mpSpinBoxY->setFocusPolicy(Qt::StrongFocus); + mpSpinBoxZ->setFocusPolicy(Qt::StrongFocus); connect(mpSpinBoxX, SIGNAL(valueChanged(double)), this, SLOT(SetX(double))); connect(mpSpinBoxY, SIGNAL(valueChanged(double)), this, SLOT(SetY(double))); connect(mpSpinBoxZ, SIGNAL(valueChanged(double)), this, SLOT(SetZ(double)));