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)
, mEditInProgress(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
{
if (mUpdatingModel) return;
BlockRelays(true);
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 (!pEditor) return;
mUpdatingModel = true;
IProperty *pProp = mpModel->PropertyForIndex(rkIndex, false);
IPropertyValue *pOldValue = nullptr;
@ -531,6 +535,8 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
else
delete pOldValue;
}
mUpdatingModel = false;
}
bool CPropertyDelegate::eventFilter(QObject *pObject, QEvent *pEvent)

View File

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

View File

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

View File

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

View File

@ -529,7 +529,7 @@ void CWorldEditor::UpdateStatusBar()
void CWorldEditor::UpdateGizmoUI()
{
// Update transform XYZ spin boxes
if (!ui->TransformSpinBox->IsBeingDragged())
if (!ui->TransformSpinBox->IsBeingEdited())
{
CVector3f spinBoxValue = CVector3f::skZero;
@ -695,6 +695,8 @@ void CWorldEditor::OnClipboardDataModified()
void CWorldEditor::OnSelectionModified()
{
ui->TransformSpinBox->setEnabled(!mpSelection->IsEmpty());
bool HasScriptNode = HasAnyScriptNodesSelected();
ui->ActionCut->setEnabled(HasScriptNode);
ui->ActionCopy->setEnabled(HasScriptNode);
@ -933,10 +935,6 @@ void CWorldEditor::OnTransformSpinBoxModified(CVector3f value)
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 (mGizmo.Mode() == CGizmo::eTranslate) mUndoStack.push(CTranslateNodeCommand::End());

View File

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