Fixed draggable spinboxes updating while the user is typing into them

This commit is contained in:
parax0 2016-03-21 16:51:35 -06:00
parent 9d782f5a4c
commit 87bf3dbfcc
6 changed files with 44 additions and 16 deletions

View File

@ -30,6 +30,7 @@ CPropertyDelegate::CPropertyDelegate(QObject *pParent /*= 0*/)
, mInRelayWidgetEdit(false) , mInRelayWidgetEdit(false)
, mEditInProgress(false) , mEditInProgress(false)
, mRelaysBlocked(false) , mRelaysBlocked(false)
, mUpdatingModel(false)
{ {
} }
@ -196,6 +197,8 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const
{ {
if (mUpdatingModel) return;
BlockRelays(true); BlockRelays(true);
mEditInProgress = false; // fixes case where user does undo mid-edit mEditInProgress = false; // fixes case where user does undo mid-edit
@ -351,6 +354,7 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
{ {
if (!mpModel) return; if (!mpModel) return;
if (!pEditor) return; if (!pEditor) return;
mUpdatingModel = true;
IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false); IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false);
IPropertyValue *pOldValue = nullptr; IPropertyValue *pOldValue = nullptr;
@ -531,6 +535,8 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
else else
delete pOldValue; delete pOldValue;
} }
mUpdatingModel = false;
} }
bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent) bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent)

View File

@ -14,6 +14,7 @@ class CPropertyDelegate : public QStyledItemDelegate
bool mInRelayWidgetEdit; bool mInRelayWidgetEdit;
mutable bool mEditInProgress; mutable bool mEditInProgress;
mutable bool mRelaysBlocked; mutable bool mRelaysBlocked;
mutable bool mUpdatingModel;
public: public:
CPropertyDelegate(QObject *pParent = 0); CPropertyDelegate(QObject *pParent = 0);

View File

@ -7,6 +7,7 @@ WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent)
mpSpinBoxX->setValue(0.0); mpSpinBoxX->setValue(0.0);
mpSpinBoxY->setValue(0.0); mpSpinBoxY->setValue(0.0);
mpSpinBoxZ->setValue(0.0); mpSpinBoxZ->setValue(0.0);
mEditing = false;
} }
WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget(pParent) WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget(pParent)
@ -16,6 +17,7 @@ WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget
mpSpinBoxX->setValue((double) value.x); mpSpinBoxX->setValue((double) value.x);
mpSpinBoxY->setValue((double) value.y); mpSpinBoxY->setValue((double) value.y);
mpSpinBoxZ->setValue((double) value.z); mpSpinBoxZ->setValue((double) value.z);
mEditing = false;
} }
WVectorEditor::~WVectorEditor() WVectorEditor::~WVectorEditor()
@ -94,19 +96,27 @@ void WVectorEditor::SetLabelsHidden(bool hidden)
} }
} }
bool WVectorEditor::IsBeingDragged() bool WVectorEditor::IsBeingDragged() const
{ {
return (mpSpinBoxX->IsBeingDragged() || mpSpinBoxY->IsBeingDragged() || mpSpinBoxZ->IsBeingDragged()); return (mpSpinBoxX->IsBeingDragged() || mpSpinBoxY->IsBeingDragged() || mpSpinBoxZ->IsBeingDragged());
} }
bool WVectorEditor::IsBeingEdited() const
{
return IsBeingDragged() || mEditing;
}
// ************ PUBLIC SLOTS ************ // ************ PUBLIC SLOTS ************
void WVectorEditor::SetX(double x) void WVectorEditor::SetX(double x)
{ {
mValue.x = (float) x; mValue.x = (float) x;
mpSpinBoxX->blockSignals(true); if (sender() != mpSpinBoxX)
mpSpinBoxX->setValue((double) x); {
mpSpinBoxX->blockSignals(false); mpSpinBoxX->blockSignals(true);
mpSpinBoxX->setValue((double) x);
mpSpinBoxX->blockSignals(false);
}
mEditing = true; mEditing = true;
emit ValueChanged(mValue); emit ValueChanged(mValue);
@ -116,9 +126,12 @@ void WVectorEditor::SetY(double y)
{ {
mValue.y = (float) y; mValue.y = (float) y;
mpSpinBoxY->blockSignals(true); if (sender() != mpSpinBoxY)
mpSpinBoxY->setValue((double) y); {
mpSpinBoxY->blockSignals(false); mpSpinBoxY->blockSignals(true);
mpSpinBoxY->setValue((double) y);
mpSpinBoxY->blockSignals(false);
}
mEditing = true; mEditing = true;
emit ValueChanged(mValue); emit ValueChanged(mValue);
@ -128,9 +141,12 @@ void WVectorEditor::SetZ(double z)
{ {
mValue.z = (float) z; mValue.z = (float) z;
mpSpinBoxZ->blockSignals(true); if (sender() != mpSpinBoxZ)
mpSpinBoxZ->setValue((double) z); {
mpSpinBoxZ->blockSignals(false); mpSpinBoxZ->blockSignals(true);
mpSpinBoxZ->setValue((double) z);
mpSpinBoxZ->blockSignals(false);
}
mEditing = true; mEditing = true;
emit ValueChanged(mValue); emit ValueChanged(mValue);
@ -176,6 +192,9 @@ void WVectorEditor::SetupUI()
mpZLayout->addWidget(mpSpinBoxZ, 1); mpZLayout->addWidget(mpSpinBoxZ, 1);
mpZLayout->setSpacing(5); mpZLayout->setSpacing(5);
setTabOrder(mpSpinBoxX, mpSpinBoxY);
setTabOrder(mpSpinBoxY, mpSpinBoxZ);
// Create and initialize widget layout // Create and initialize widget layout
mpLayout = nullptr; mpLayout = nullptr;
SetOrientation(Qt::Vertical); SetOrientation(Qt::Vertical);

View File

@ -39,7 +39,8 @@ public:
void SetDefaultValue(double value); void SetDefaultValue(double value);
void SetSingleStep(double step); void SetSingleStep(double step);
void SetLabelsHidden(bool hidden); void SetLabelsHidden(bool hidden);
bool IsBeingDragged(); bool IsBeingDragged() const;
bool IsBeingEdited() const;
public slots: public slots:
void SetX(double x); void SetX(double x);

View File

@ -529,7 +529,7 @@ void CWorldEditor::UpdateStatusBar()
void CWorldEditor::UpdateGizmoUI() void CWorldEditor::UpdateGizmoUI()
{ {
// Update transform XYZ spin boxes // Update transform XYZ spin boxes
if (!ui->TransformSpinBox->IsBeingDragged()) if (!ui->TransformSpinBox->IsBeingEdited())
{ {
CVector3f spinBoxValue = CVector3f::skZero; CVector3f spinBoxValue = CVector3f::skZero;
@ -695,6 +695,8 @@ void CWorldEditor::OnClipboardDataModified()
void CWorldEditor::OnSelectionModified() void CWorldEditor::OnSelectionModified()
{ {
ui->TransformSpinBox->setEnabled(!mpSelection->IsEmpty());
bool HasScriptNode = HasAnyScriptNodesSelected(); bool HasScriptNode = HasAnyScriptNodesSelected();
ui->ActionCut->setEnabled(HasScriptNode); ui->ActionCut->setEnabled(HasScriptNode);
ui->ActionCopy->setEnabled(HasScriptNode); ui->ActionCopy->setEnabled(HasScriptNode);
@ -933,10 +935,6 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value)
void CWorldEditor::OnTransformSpinBoxEdited(CVector3f) void CWorldEditor::OnTransformSpinBoxEdited(CVector3f)
{ {
// bit of a hack - the vector editor emits a second "editing done" signal when it loses focus
ui->TransformSpinBox->blockSignals(true);
ui->MainViewport->setFocus();
ui->TransformSpinBox->blockSignals(false);
if (mpSelection->IsEmpty()) return; if (mpSelection->IsEmpty()) return;
if (mGizmo.Mode() == CGizmo::eTranslate) mUndoStack.push(CTranslateNodeCommand::End()); if (mGizmo.Mode() == CGizmo::eTranslate) mUndoStack.push(CTranslateNodeCommand::End());

View File

@ -119,6 +119,9 @@
</item> </item>
<item> <item>
<widget class="WVectorEditor" name="TransformSpinBox" native="true"> <widget class="WVectorEditor" name="TransformSpinBox" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>