diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index e364319c..f9981016 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "WDraggableSpinBox.h" #include "WorldEditor/CLayerEditor.h" #include "WorldEditor/WModifyTab.h" @@ -29,8 +30,6 @@ CWorldEditor::CWorldEditor(QWidget *parent) : mpArea = nullptr; mpWorld = nullptr; mpHoverNode = nullptr; - //mpInstanceModel = new CInstanceModel(this); - //ui->InstancesTreeView->setModel(mpInstanceModel); mDrawSky = true; mFrameCount = 0; @@ -47,11 +46,16 @@ CWorldEditor::CWorldEditor(QWidget *parent) : delete pOldTitleBar; - ResetHover(); + // Initialize UI stuff ui->ModifyTabContents->SetEditor(this); ui->InstancesTabContents->SetEditor(this, mpSceneManager); ui->MainDock->installEventFilter(this); + ui->CamSpeedSpinBox->SetDefaultValue(1.0); + ResetHover(); + + // Connect signals and slots + connect(ui->CamSpeedSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnCameraSpeedChange(double))); connect(ui->MainViewport, SIGNAL(PreRender()), this, SLOT(ViewportPreRender())); connect(ui->MainViewport, SIGNAL(Render(CCamera&)), this, SLOT(ViewportRender(CCamera&))); connect(ui->MainViewport, SIGNAL(ViewportResized(int,int)), this, SLOT(SetViewportSize(int,int))); @@ -362,9 +366,25 @@ void CWorldEditor::UpdateSelectionUI() QFontMetrics Metrics(ui->SelectionInfoLabel->font()); SelectionText = Metrics.elidedText(SelectionText, Qt::ElideRight, ui->SelectionInfoFrame->width() - 10); ui->SelectionInfoLabel->setText(SelectionText); + + // Update transform + CVector3f pos = (!mSelectedNodes.empty() ? mSelectedNodes.front()->GetAbsolutePosition() : CVector3f::skZero); + ui->XSpinBox->setValue(pos.x); + ui->YSpinBox->setValue(pos.y); + ui->ZSpinBox->setValue(pos.z); } // ************ ACTIONS ************ +void CWorldEditor::OnCameraSpeedChange(double speed) +{ + static const double skDefaultSpeed = 1.0; + ui->MainViewport->Camera().SetMoveSpeed(skDefaultSpeed * speed); + + ui->CamSpeedSpinBox->blockSignals(true); + ui->CamSpeedSpinBox->setValue(speed); + ui->CamSpeedSpinBox->blockSignals(false); +} + // These functions are from "Go to slot" in the designer void CWorldEditor::on_ActionDrawWorld_triggered() { diff --git a/UI/CWorldEditor.h b/UI/CWorldEditor.h index ad6e379c..717d742b 100644 --- a/UI/CWorldEditor.h +++ b/UI/CWorldEditor.h @@ -74,6 +74,7 @@ private: void UpdateStatusBar(); private slots: + void OnCameraSpeedChange(double speed); void on_ActionDrawWorld_triggered(); void on_ActionDrawCollision_triggered(); void on_ActionDrawObjects_triggered(); diff --git a/UI/CWorldEditor.ui b/UI/CWorldEditor.ui index 6c499258..52417c3a 100644 --- a/UI/CWorldEditor.ui +++ b/UI/CWorldEditor.ui @@ -38,12 +38,6 @@ 1 - YLabel - YSpinBox - XSpinBox - XLabel - ZSpinBox - ZLabel @@ -158,6 +152,9 @@ 16777215 + + Qt::NoFocus + 4 @@ -199,6 +196,9 @@ 16777215 + + Qt::NoFocus + 4 @@ -240,6 +240,9 @@ 16777215 + + Qt::NoFocus + 4 @@ -278,6 +281,9 @@ 16777215 + + Qt::NoFocus + true diff --git a/UI/WDraggableSpinBox.cpp b/UI/WDraggableSpinBox.cpp index 066a7e94..35666f38 100644 --- a/UI/WDraggableSpinBox.cpp +++ b/UI/WDraggableSpinBox.cpp @@ -6,7 +6,7 @@ WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent) { mBeingDragged = false; - mDefaultValue = value(); + mDefaultValue = 0; setMinimum(-1000000.0); setMaximum(1000000.0); } @@ -25,6 +25,7 @@ void WDraggableSpinBox::mousePressEvent(QMouseEvent*) void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event) { mBeingDragged = false; + setCursor(Qt::ArrowCursor); if (Event->button() == Qt::LeftButton) { @@ -35,11 +36,6 @@ void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event) else stepDown(); } - - else - { - setCursor(Qt::ArrowCursor); - } } else if (Event->button() == Qt::RightButton) @@ -83,3 +79,13 @@ void WDraggableSpinBox::wheelEvent(QWheelEvent *pEvent) if (!hasFocus()) pEvent->ignore(); else QDoubleSpinBox::wheelEvent(pEvent); } + +void WDraggableSpinBox::contextMenuEvent(QContextMenuEvent *pEvent) +{ + pEvent->ignore(); +} + +void WDraggableSpinBox::SetDefaultValue(double value) +{ + mDefaultValue = value; +} diff --git a/UI/WDraggableSpinBox.h b/UI/WDraggableSpinBox.h index f3f815ac..0fca511a 100644 --- a/UI/WDraggableSpinBox.h +++ b/UI/WDraggableSpinBox.h @@ -18,6 +18,8 @@ public: void mouseReleaseEvent(QMouseEvent *pEvent); void mouseMoveEvent(QMouseEvent *pEvent); void wheelEvent(QWheelEvent *pEvent); + void contextMenuEvent(QContextMenuEvent *pEvent); + void SetDefaultValue(double value); }; #endif // WDRAGGABLESPINBOX_H diff --git a/UI/WVectorEditor.cpp b/UI/WVectorEditor.cpp index 415a00fd..5105d5d4 100644 --- a/UI/WVectorEditor.cpp +++ b/UI/WVectorEditor.cpp @@ -40,6 +40,9 @@ WVectorEditor::WVectorEditor(const CVector3f& Value, QWidget *pParent) : QWidget mpSpinBoxX = new WDraggableSpinBox(this); mpSpinBoxY = new WDraggableSpinBox(this); mpSpinBoxZ = new WDraggableSpinBox(this); + mpSpinBoxX->setDecimals(4); + mpSpinBoxX->setDecimals(4); + mpSpinBoxX->setDecimals(4); mpSpinBoxX->setValue((double) Value.x); mpSpinBoxY->setValue((double) Value.y); mpSpinBoxZ->setValue((double) Value.z);