Made the transform spin boxes in the world editor functional

This commit is contained in:
parax0 2015-08-24 21:17:15 -04:00
parent ae11e50bcd
commit 8d633553c9
8 changed files with 291 additions and 289 deletions

View File

@ -9,6 +9,7 @@
#include <QComboBox> #include <QComboBox>
#include <Core/Log.h> #include <Core/Log.h>
#include "WDraggableSpinBox.h" #include "WDraggableSpinBox.h"
#include "WVectorEditor.h"
#include "WorldEditor/CLayerEditor.h" #include "WorldEditor/CLayerEditor.h"
#include "WorldEditor/WModifyTab.h" #include "WorldEditor/WModifyTab.h"
@ -55,6 +56,8 @@ CWorldEditor::CWorldEditor(QWidget *parent) :
ui->ModifyTabContents->SetEditor(this); ui->ModifyTabContents->SetEditor(this);
ui->InstancesTabContents->SetEditor(this, mpSceneManager); ui->InstancesTabContents->SetEditor(this, mpSceneManager);
ui->MainDock->installEventFilter(this); ui->MainDock->installEventFilter(this);
ui->TransformSpinBox->SetOrientation(Qt::Horizontal);
ui->TransformSpinBox->layout()->setContentsMargins(0,0,0,0);
ui->CamSpeedSpinBox->SetDefaultValue(1.0); ui->CamSpeedSpinBox->SetDefaultValue(1.0);
ResetHover(); ResetHover();
@ -71,6 +74,8 @@ CWorldEditor::CWorldEditor(QWidget *parent) :
addAction(ui->ActionDecrementGizmo); addAction(ui->ActionDecrementGizmo);
// Connect signals and slots // Connect signals and slots
connect(ui->TransformSpinBox, SIGNAL(EditingDone(CVector3f)), this, SLOT(OnTransformSpinBoxEdited(CVector3f)));
connect(ui->TransformSpinBox, SIGNAL(ValueChanged(CVector3f)), this, SLOT(OnTransformSpinBoxModified(CVector3f)));
connect(pTransformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTransformSpace(int))); connect(pTransformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(SetTransformSpace(int)));
connect(ui->CamSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnCameraSpeedChange(double))); connect(ui->CamSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnCameraSpeedChange(double)));
connect(ui->MainViewport, SIGNAL(PreRender()), this, SLOT(ViewportPreRender())); connect(ui->MainViewport, SIGNAL(PreRender()), this, SLOT(ViewportPreRender()));
@ -520,41 +525,44 @@ void CWorldEditor::UpdateSelectionUI()
void CWorldEditor::UpdateGizmoUI() void CWorldEditor::UpdateGizmoUI()
{ {
// Update transform XYZ spin boxes // Update transform XYZ spin boxes
CVector3f spinBoxValue = CVector3f::skZero; if (!ui->TransformSpinBox->IsBeingDragged())
// If the gizmo is transforming, use the total transform amount
// Otherwise, use the first selected node transform, or 0 if no selection
if (mShowGizmo)
{ {
switch (mGizmo.Mode()) CVector3f spinBoxValue = CVector3f::skZero;
// If the gizmo is transforming, use the total transform amount
// Otherwise, use the first selected node transform, or 0 if no selection
if (mShowGizmo)
{ {
case CGizmo::eTranslate: switch (mGizmo.Mode())
if (mGizmoTransforming && mGizmo.HasTransformed()) {
spinBoxValue = mGizmo.TotalTranslation(); case CGizmo::eTranslate:
else if (!mSelectedNodes.empty()) if (mGizmoTransforming && mGizmo.HasTransformed())
spinBoxValue = mSelectedNodes.front()->AbsolutePosition(); spinBoxValue = mGizmo.TotalTranslation();
break; else if (!mSelectedNodes.empty())
spinBoxValue = mSelectedNodes.front()->AbsolutePosition();
break;
case CGizmo::eRotate: case CGizmo::eRotate:
if (mGizmoTransforming && mGizmo.HasTransformed()) if (mGizmoTransforming && mGizmo.HasTransformed())
spinBoxValue = mGizmo.TotalRotation(); spinBoxValue = mGizmo.TotalRotation();
else if (!mSelectedNodes.empty()) else if (!mSelectedNodes.empty())
spinBoxValue = mSelectedNodes.front()->AbsoluteRotation().ToEuler(); spinBoxValue = mSelectedNodes.front()->AbsoluteRotation().ToEuler();
break; break;
case CGizmo::eScale: case CGizmo::eScale:
if (mGizmoTransforming && mGizmo.HasTransformed()) if (mGizmoTransforming && mGizmo.HasTransformed())
spinBoxValue = mGizmo.TotalScale(); spinBoxValue = mGizmo.TotalScale();
else if (!mSelectedNodes.empty()) else if (!mSelectedNodes.empty())
spinBoxValue = mSelectedNodes.front()->AbsoluteScale(); spinBoxValue = mSelectedNodes.front()->AbsoluteScale();
break; break;
}
} }
} else if (!mSelectedNodes.empty()) spinBoxValue = mSelectedNodes.front()->AbsolutePosition();
else if (!mSelectedNodes.empty()) spinBoxValue = mSelectedNodes.front()->AbsolutePosition();
ui->XSpinBox->setValue(spinBoxValue.x); ui->TransformSpinBox->blockSignals(true);
ui->YSpinBox->setValue(spinBoxValue.y); ui->TransformSpinBox->SetValue(spinBoxValue);
ui->ZSpinBox->setValue(spinBoxValue.z); ui->TransformSpinBox->blockSignals(false);
}
// Update gizmo // Update gizmo
if (!mGizmoTransforming) if (!mGizmoTransforming)
@ -582,6 +590,35 @@ void CWorldEditor::OnCameraSpeedChange(double speed)
ui->CamSpeedSpinBox->blockSignals(false); ui->CamSpeedSpinBox->blockSignals(false);
} }
void CWorldEditor::OnTransformSpinBoxModified(CVector3f value)
{
switch (mGizmo.Mode())
{
case CGizmo::eTranslate:
for (auto it = mSelectedNodes.begin(); it != mSelectedNodes.end(); it++)
(*it)->SetPosition(value);
break;
case CGizmo::eRotate:
for (auto it = mSelectedNodes.begin(); it != mSelectedNodes.end(); it++)
(*it)->SetRotation(value);
break;
case CGizmo::eScale:
for (auto it = mSelectedNodes.begin(); it != mSelectedNodes.end(); it++)
(*it)->SetScale(value);
break;
}
RecalculateSelectionBounds();
UpdateGizmoUI();
}
void CWorldEditor::OnTransformSpinBoxEdited(CVector3f)
{
UpdateGizmoUI();
}
// These functions are from "Go to slot" in the designer // These functions are from "Go to slot" in the designer
void CWorldEditor::on_ActionDrawWorld_triggered() void CWorldEditor::on_ActionDrawWorld_triggered()
{ {
@ -738,6 +775,9 @@ void CWorldEditor::on_ActionTranslate_triggered()
ui->ActionTranslate->setChecked(true); ui->ActionTranslate->setChecked(true);
ui->ActionRotate->setChecked(false); ui->ActionRotate->setChecked(false);
ui->ActionScale->setChecked(false); ui->ActionScale->setChecked(false);
ui->TransformSpinBox->SetSingleStep(0.1);
ui->TransformSpinBox->SetDefaultValue(0.0);
} }
void CWorldEditor::on_ActionRotate_triggered() void CWorldEditor::on_ActionRotate_triggered()
@ -749,6 +789,9 @@ void CWorldEditor::on_ActionRotate_triggered()
ui->ActionTranslate->setChecked(false); ui->ActionTranslate->setChecked(false);
ui->ActionRotate->setChecked(true); ui->ActionRotate->setChecked(true);
ui->ActionScale->setChecked(false); ui->ActionScale->setChecked(false);
ui->TransformSpinBox->SetSingleStep(1.0);
ui->TransformSpinBox->SetDefaultValue(0.0);
} }
void CWorldEditor::on_ActionScale_triggered() void CWorldEditor::on_ActionScale_triggered()
@ -760,6 +803,9 @@ void CWorldEditor::on_ActionScale_triggered()
ui->ActionTranslate->setChecked(false); ui->ActionTranslate->setChecked(false);
ui->ActionRotate->setChecked(false); ui->ActionRotate->setChecked(false);
ui->ActionScale->setChecked(true); ui->ActionScale->setChecked(true);
ui->TransformSpinBox->SetSingleStep(0.1);
ui->TransformSpinBox->SetDefaultValue(1.0);
} }
void CWorldEditor::on_ActionIncrementGizmo_triggered() void CWorldEditor::on_ActionIncrementGizmo_triggered()

View File

@ -86,6 +86,8 @@ private:
private slots: private slots:
void OnCameraSpeedChange(double speed); void OnCameraSpeedChange(double speed);
void OnTransformSpinBoxModified(CVector3f value);
void OnTransformSpinBoxEdited(CVector3f value);
void on_ActionDrawWorld_triggered(); void on_ActionDrawWorld_triggered();
void on_ActionDrawCollision_triggered(); void on_ActionDrawCollision_triggered();
void on_ActionDrawObjects_triggered(); void on_ActionDrawObjects_triggered();

View File

@ -126,162 +126,19 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="XLabel"> <widget class="WVectorEditor" name="TransformSpinBox" native="true">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="XSpinBox">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>78</width> <width>300</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="YLabel">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="YSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>78</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ZLabel">
<property name="text">
<string>Z:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="ZSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>78</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="keyboardTracking">
<bool>false</bool>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@ -970,11 +827,14 @@
<header>WorldEditor/WInstancesTab.h</header> <header>WorldEditor/WInstancesTab.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>WVectorEditor</class>
<extends>QWidget</extends>
<header>WVectorEditor.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>XSpinBox</tabstop>
<tabstop>YSpinBox</tabstop>
<tabstop>ZSpinBox</tabstop>
<tabstop>TabWidget</tabstop> <tabstop>TabWidget</tabstop>
</tabstops> </tabstops>
<resources> <resources>

View File

@ -49,6 +49,8 @@ void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
{ {
setValue(mDefaultValue); setValue(mDefaultValue);
} }
emit editingFinished();
} }
void WDraggableSpinBox::mouseMoveEvent(QMouseEvent*) void WDraggableSpinBox::mouseMoveEvent(QMouseEvent*)
@ -138,6 +140,11 @@ QString WDraggableSpinBox::textFromValue(double val) const
return str; return str;
} }
bool WDraggableSpinBox::IsBeingDragged()
{
return mBeingDragged;
}
void WDraggableSpinBox::SetDefaultValue(double value) void WDraggableSpinBox::SetDefaultValue(double value)
{ {
mDefaultValue = value; mDefaultValue = value;

View File

@ -22,6 +22,7 @@ public:
void wheelEvent(QWheelEvent *pEvent); void wheelEvent(QWheelEvent *pEvent);
bool eventFilter(QObject *pObj, QEvent *pEvent); bool eventFilter(QObject *pObj, QEvent *pEvent);
QString textFromValue(double val) const; QString textFromValue(double val) const;
bool IsBeingDragged();
void SetDefaultValue(double value); void SetDefaultValue(double value);
void SetMinDecimals(int dec); void SetMinDecimals(int dec);
void TrimTrailingZeroes(bool trim); void TrimTrailingZeroes(bool trim);

View File

@ -160,17 +160,24 @@ void WPropertyEditor::CreateEditor()
break; break;
} }
// Vector3 - WVectorEditor // Vector3 - WVectorEditor (inside QGroupBox)
case eVector3Property: case eVector3Property:
{ {
CVector3Property *pVector3Cast = static_cast<CVector3Property*>(mpProperty); CVector3Property *pVector3Cast = static_cast<CVector3Property*>(mpProperty);
WVectorEditor *pVectorEditor = new WVectorEditor(this); QGroupBox *pGroupBox = new QGroupBox(this);
WVectorEditor *pVectorEditor = new WVectorEditor(pGroupBox);
QVBoxLayout *pGroupLayout = new QVBoxLayout(pGroupBox);
pGroupLayout->addWidget(pVectorEditor);
pGroupLayout->setContentsMargins(0,0,0,0);
pGroupBox->setLayout(pGroupLayout);
pGroupBox->setTitle(QString::fromStdString(mpProperty->Name()));
pVectorEditor->SetValue(pVector3Cast->Get()); pVectorEditor->SetValue(pVector3Cast->Get());
pVectorEditor->SetText(QString::fromStdString(mpProperty->Name())); pVectorEditor->SetOrientation(Qt::Vertical);
mUI.PropertyName->hide(); mUI.PropertyName->hide();
mUI.EditorWidget = pVectorEditor; mUI.EditorWidget = pGroupBox;
break; break;
} }
@ -303,7 +310,9 @@ void WPropertyEditor::UpdateEditor()
case eVector3Property: case eVector3Property:
{ {
CVector3Property *pVector3Cast = static_cast<CVector3Property*>(mpProperty); CVector3Property *pVector3Cast = static_cast<CVector3Property*>(mpProperty);
WVectorEditor *pVectorEditor = static_cast<WVectorEditor*>(mUI.EditorWidget); QGroupBox *pGroupBox = static_cast<QGroupBox*>(mUI.EditorWidget);
WVectorEditor *pVectorEditor = static_cast<WVectorEditor*>(pGroupBox->children().first());
pVectorEditor->SetValue(pVector3Cast->Get()); pVectorEditor->SetValue(pVector3Cast->Get());
break; break;
} }

View File

@ -2,8 +2,146 @@
WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent) WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent)
{ {
SetupUI();
mValue = CVector3f::skZero; mValue = CVector3f::skZero;
mpSpinBoxX->setValue(0.0);
mpSpinBoxY->setValue(0.0);
mpSpinBoxZ->setValue(0.0);
}
WVectorEditor::WVectorEditor(const CVector3f& value, QWidget *pParent) : QWidget(pParent)
{
SetupUI();
mValue = value;
mpSpinBoxX->setValue((double) value.x);
mpSpinBoxY->setValue((double) value.y);
mpSpinBoxZ->setValue((double) value.z);
}
WVectorEditor::~WVectorEditor()
{
delete mpLayout;
}
CVector3f WVectorEditor::Value()
{
return mValue;
}
void WVectorEditor::SetValue(const CVector3f& value)
{
mValue = value;
mpSpinBoxX->blockSignals(true);
mpSpinBoxY->blockSignals(true);
mpSpinBoxZ->blockSignals(true);
mpSpinBoxX->setValue((double) value.x);
mpSpinBoxY->setValue((double) value.y);
mpSpinBoxZ->setValue((double) value.z);
mpSpinBoxX->blockSignals(false);
mpSpinBoxY->blockSignals(false);
mpSpinBoxZ->blockSignals(false);
}
void WVectorEditor::SetOrientation(Qt::Orientation orientation)
{
mOrientation = orientation;
if (mpLayout)
{
mpLayout->removeItem(mpXLayout);
mpLayout->removeItem(mpYLayout);
mpLayout->removeItem(mpZLayout);
delete mpLayout;
}
mpLayout = (orientation == Qt::Horizontal ? (QLayout*) new QHBoxLayout : (QLayout*) new QVBoxLayout);
mpLayout->addItem(mpXLayout);
mpLayout->addItem(mpYLayout);
mpLayout->addItem(mpZLayout);
mpLayout->setContentsMargins(5,5,5,5);
setLayout(mpLayout);
emit
}
void WVectorEditor::SetDefaultValue(double value)
{
mpSpinBoxX->SetDefaultValue(value);
mpSpinBoxY->SetDefaultValue(value);
mpSpinBoxZ->SetDefaultValue(value);
}
void WVectorEditor::SetSingleStep(double step)
{
mpSpinBoxX->setSingleStep(step);
mpSpinBoxY->setSingleStep(step);
mpSpinBoxZ->setSingleStep(step);
}
void WVectorEditor::SetLabelsHidden(bool hidden)
{
if (hidden)
{
mpLabelX->hide();
mpLabelY->hide();
mpLabelZ->hide();
}
else
{
mpLabelX->show();
mpLabelY->show();
mpLabelZ->show();
}
}
bool WVectorEditor::IsBeingDragged()
{
return (mpSpinBoxX->IsBeingDragged() || mpSpinBoxY->IsBeingDragged() || mpSpinBoxZ->IsBeingDragged());
}
// ************ PUBLIC SLOTS ************
void WVectorEditor::SetX(double x)
{
mValue.x = (float) x;
mpSpinBoxX->blockSignals(true);
mpSpinBoxX->setValue((double) x);
mpSpinBoxX->blockSignals(false);
emit ValueChanged(mValue);
}
void WVectorEditor::SetY(double y)
{
mValue.y = (float) y;
mpSpinBoxY->blockSignals(true);
mpSpinBoxY->setValue((double) y);
mpSpinBoxY->blockSignals(false);
emit ValueChanged(mValue);
}
void WVectorEditor::SetZ(double z)
{
mValue.z = (float) z;
mpSpinBoxZ->blockSignals(true);
mpSpinBoxZ->setValue((double) z);
mpSpinBoxZ->blockSignals(false);
emit ValueChanged(mValue);
}
// ************ PRIVATE ************
void WVectorEditor::SetupUI()
{
// Create and initialize widgets
mpLabelX = new QLabel("X", this);
mpLabelY = new QLabel("Y", this);
mpLabelZ = new QLabel("Z", this);
mpSpinBoxX = new WDraggableSpinBox(this); mpSpinBoxX = new WDraggableSpinBox(this);
mpSpinBoxY = new WDraggableSpinBox(this); mpSpinBoxY = new WDraggableSpinBox(this);
mpSpinBoxZ = new WDraggableSpinBox(this); mpSpinBoxZ = new WDraggableSpinBox(this);
@ -19,107 +157,31 @@ WVectorEditor::WVectorEditor(QWidget *pParent) : QWidget(pParent)
connect(mpSpinBoxX, SIGNAL(valueChanged(double)), this, SLOT(SetX(double))); connect(mpSpinBoxX, SIGNAL(valueChanged(double)), this, SLOT(SetX(double)));
connect(mpSpinBoxY, SIGNAL(valueChanged(double)), this, SLOT(SetY(double))); connect(mpSpinBoxY, SIGNAL(valueChanged(double)), this, SLOT(SetY(double)));
connect(mpSpinBoxZ, SIGNAL(valueChanged(double)), this, SLOT(SetZ(double))); connect(mpSpinBoxZ, SIGNAL(valueChanged(double)), this, SLOT(SetZ(double)));
connect(mpSpinBoxX, SIGNAL(editingFinished()), this, SLOT(OnSpinBoxEditingDone()));
connect(mpSpinBoxY, SIGNAL(editingFinished()), this, SLOT(OnSpinBoxEditingDone()));
connect(mpSpinBoxZ, SIGNAL(editingFinished()), this, SLOT(OnSpinBoxEditingDone()));
mpGroupBox = new QGroupBox(this); // Create and initialize spinbox layouts
mpFormLayout = new QFormLayout(mpGroupBox); mpXLayout = new QHBoxLayout();
mpFormLayout->addRow(new QLabel("X", mpGroupBox), mpSpinBoxX); mpYLayout = new QHBoxLayout();
mpFormLayout->addRow(new QLabel("Y", mpGroupBox), mpSpinBoxY); mpZLayout = new QHBoxLayout();
mpFormLayout->addRow(new QLabel("Z", mpGroupBox), mpSpinBoxZ); mpXLayout->addWidget(mpLabelX, 0);
mpGroupBox->setLayout(mpFormLayout); mpXLayout->addWidget(mpSpinBoxX, 1);
mpXLayout->setSpacing(5);
mpYLayout->addWidget(mpLabelY, 0);
mpYLayout->addWidget(mpSpinBoxY, 1);
mpYLayout->setSpacing(5);
mpZLayout->addWidget(mpLabelZ, 0);
mpZLayout->addWidget(mpSpinBoxZ, 1);
mpZLayout->setSpacing(5);
mpLayout = new QHBoxLayout(this); // Create and initialize widget layout
mpLayout->addWidget(mpGroupBox); mpLayout = nullptr;
setLayout(mpLayout); SetOrientation(Qt::Vertical);
} }
WVectorEditor::WVectorEditor(const CVector3f& Value, QWidget *pParent) : QWidget(pParent) // ************ PRIVATE SLOTS ************
void WVectorEditor::OnSpinBoxEditingDone()
{ {
mValue = Value; emit EditingDone(mValue);
mpSpinBoxX = new WDraggableSpinBox(this);
mpSpinBoxY = new WDraggableSpinBox(this);
mpSpinBoxZ = new WDraggableSpinBox(this);
mpSpinBoxX->setDecimals(4);
mpSpinBoxY->setDecimals(4);
mpSpinBoxZ->setDecimals(4);
mpSpinBoxX->setValue((double) Value.x);
mpSpinBoxY->setValue((double) Value.y);
mpSpinBoxZ->setValue((double) Value.z);
mpSpinBoxX->setMinimumHeight(21);
mpSpinBoxY->setMinimumHeight(21);
mpSpinBoxZ->setMinimumHeight(21);
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)));
mpLayout = new QHBoxLayout(this);
mpLayout->setContentsMargins(0,0,0,0);
mpLayout->addWidget(mpSpinBoxX);
mpLayout->addWidget(mpSpinBoxY);
mpLayout->addWidget(mpSpinBoxZ);
setLayout(mpLayout);
}
WVectorEditor::~WVectorEditor()
{
}
CVector3f WVectorEditor::Value()
{
return mValue;
}
void WVectorEditor::SetValue(const CVector3f& Value)
{
mValue = Value;
mpSpinBoxX->blockSignals(true);
mpSpinBoxY->blockSignals(true);
mpSpinBoxZ->blockSignals(true);
mpSpinBoxX->setValue((double) Value.x);
mpSpinBoxY->setValue((double) Value.y);
mpSpinBoxZ->setValue((double) Value.z);
mpSpinBoxX->blockSignals(false);
mpSpinBoxY->blockSignals(false);
mpSpinBoxZ->blockSignals(false);
}
void WVectorEditor::SetText(const QString &Text)
{
mpGroupBox->setTitle(Text);
}
// ************ SLOTS ************
void WVectorEditor::SetX(double x)
{
mValue.x = (float) x;
mpSpinBoxX->blockSignals(true);
mpSpinBoxX->setValue((double) x);
mpSpinBoxX->blockSignals(false);
}
void WVectorEditor::SetY(double y)
{
mValue.y = (float) y;
mpSpinBoxY->blockSignals(true);
mpSpinBoxY->setValue((double) y);
mpSpinBoxY->blockSignals(false);
}
void WVectorEditor::SetZ(double z)
{
mValue.z = (float) z;
mpSpinBoxZ->blockSignals(true);
mpSpinBoxZ->setValue((double) z);
mpSpinBoxZ->blockSignals(false);
} }

View File

@ -14,30 +14,45 @@ class WVectorEditor : public QWidget
Q_OBJECT Q_OBJECT
CVector3f mValue; CVector3f mValue;
Qt::Orientation mOrientation;
QLayout *mpLayout;
QHBoxLayout *mpXLayout;
QHBoxLayout *mpYLayout;
QHBoxLayout *mpZLayout;
WDraggableSpinBox *mpSpinBoxX; WDraggableSpinBox *mpSpinBoxX;
WDraggableSpinBox *mpSpinBoxY; WDraggableSpinBox *mpSpinBoxY;
WDraggableSpinBox *mpSpinBoxZ; WDraggableSpinBox *mpSpinBoxZ;
QHBoxLayout *mpLayout;
// new layout test
QGroupBox *mpGroupBox;
QLabel *mpLabelX; QLabel *mpLabelX;
QLabel *mpLabelY; QLabel *mpLabelY;
QLabel *mpLabelZ; QLabel *mpLabelZ;
QFormLayout *mpFormLayout;
public: public:
explicit WVectorEditor(QWidget *pParent = 0); explicit WVectorEditor(QWidget *pParent = 0);
WVectorEditor(const CVector3f& Value, QWidget *pParent = 0); WVectorEditor(const CVector3f& value, QWidget *pParent = 0);
~WVectorEditor(); ~WVectorEditor();
CVector3f Value(); CVector3f Value();
void SetValue(const CVector3f& Value); void SetOrientation(Qt::Orientation orientation);
void SetText(const QString& Text); void SetValue(const CVector3f& value);
void SetDefaultValue(double value);
void SetSingleStep(double step);
void SetLabelsHidden(bool hidden);
bool IsBeingDragged();
public slots: public slots:
void SetX(double x); void SetX(double x);
void SetY(double y); void SetY(double y);
void SetZ(double z); void SetZ(double z);
signals:
void ValueChanged(const CVector3f& value);
void EditingDone(const CVector3f& value);
private:
void SetupUI();
private slots:
void OnSpinBoxEditingDone();
}; };
#endif // WVECTOREDITOR_H #endif // WVECTOREDITOR_H