Added ability to change camera move speed in World Editor + display position in bottom bar, and WDraggableSpinBox fixes

This commit is contained in:
parax0 2015-07-29 09:51:59 -04:00
parent 8280055e21
commit 0ba4b7ddd4
6 changed files with 53 additions and 15 deletions

View File

@ -7,6 +7,7 @@
#include <QOpenGLContext> #include <QOpenGLContext>
#include <QFontMetrics> #include <QFontMetrics>
#include <Core/Log.h> #include <Core/Log.h>
#include "WDraggableSpinBox.h"
#include "WorldEditor/CLayerEditor.h" #include "WorldEditor/CLayerEditor.h"
#include "WorldEditor/WModifyTab.h" #include "WorldEditor/WModifyTab.h"
@ -29,8 +30,6 @@ CWorldEditor::CWorldEditor(QWidget *parent) :
mpArea = nullptr; mpArea = nullptr;
mpWorld = nullptr; mpWorld = nullptr;
mpHoverNode = nullptr; mpHoverNode = nullptr;
//mpInstanceModel = new CInstanceModel(this);
//ui->InstancesTreeView->setModel(mpInstanceModel);
mDrawSky = true; mDrawSky = true;
mFrameCount = 0; mFrameCount = 0;
@ -47,11 +46,16 @@ CWorldEditor::CWorldEditor(QWidget *parent) :
delete pOldTitleBar; delete pOldTitleBar;
ResetHover();
// Initialize UI stuff
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->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(PreRender()), this, SLOT(ViewportPreRender()));
connect(ui->MainViewport, SIGNAL(Render(CCamera&)), this, SLOT(ViewportRender(CCamera&))); connect(ui->MainViewport, SIGNAL(Render(CCamera&)), this, SLOT(ViewportRender(CCamera&)));
connect(ui->MainViewport, SIGNAL(ViewportResized(int,int)), this, SLOT(SetViewportSize(int,int))); connect(ui->MainViewport, SIGNAL(ViewportResized(int,int)), this, SLOT(SetViewportSize(int,int)));
@ -362,9 +366,25 @@ void CWorldEditor::UpdateSelectionUI()
QFontMetrics Metrics(ui->SelectionInfoLabel->font()); QFontMetrics Metrics(ui->SelectionInfoLabel->font());
SelectionText = Metrics.elidedText(SelectionText, Qt::ElideRight, ui->SelectionInfoFrame->width() - 10); SelectionText = Metrics.elidedText(SelectionText, Qt::ElideRight, ui->SelectionInfoFrame->width() - 10);
ui->SelectionInfoLabel->setText(SelectionText); 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 ************ // ************ 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 // These functions are from "Go to slot" in the designer
void CWorldEditor::on_ActionDrawWorld_triggered() void CWorldEditor::on_ActionDrawWorld_triggered()
{ {

View File

@ -74,6 +74,7 @@ private:
void UpdateStatusBar(); void UpdateStatusBar();
private slots: private slots:
void OnCameraSpeedChange(double speed);
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

@ -38,12 +38,6 @@
<verstretch>1</verstretch> <verstretch>1</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<zorder>YLabel</zorder>
<zorder>YSpinBox</zorder>
<zorder>XSpinBox</zorder>
<zorder>XLabel</zorder>
<zorder>ZSpinBox</zorder>
<zorder>ZLabel</zorder>
</widget> </widget>
</item> </item>
<item> <item>
@ -158,6 +152,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="decimals"> <property name="decimals">
<number>4</number> <number>4</number>
</property> </property>
@ -199,6 +196,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="decimals"> <property name="decimals">
<number>4</number> <number>4</number>
</property> </property>
@ -240,6 +240,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="decimals"> <property name="decimals">
<number>4</number> <number>4</number>
</property> </property>
@ -278,6 +281,9 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="frame"> <property name="frame">
<bool>true</bool> <bool>true</bool>
</property> </property>

View File

@ -6,7 +6,7 @@
WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent) WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
{ {
mBeingDragged = false; mBeingDragged = false;
mDefaultValue = value(); mDefaultValue = 0;
setMinimum(-1000000.0); setMinimum(-1000000.0);
setMaximum(1000000.0); setMaximum(1000000.0);
} }
@ -25,6 +25,7 @@ void WDraggableSpinBox::mousePressEvent(QMouseEvent*)
void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event) void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
{ {
mBeingDragged = false; mBeingDragged = false;
setCursor(Qt::ArrowCursor);
if (Event->button() == Qt::LeftButton) if (Event->button() == Qt::LeftButton)
{ {
@ -35,11 +36,6 @@ void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
else else
stepDown(); stepDown();
} }
else
{
setCursor(Qt::ArrowCursor);
}
} }
else if (Event->button() == Qt::RightButton) else if (Event->button() == Qt::RightButton)
@ -83,3 +79,13 @@ void WDraggableSpinBox::wheelEvent(QWheelEvent *pEvent)
if (!hasFocus()) pEvent->ignore(); if (!hasFocus()) pEvent->ignore();
else QDoubleSpinBox::wheelEvent(pEvent); else QDoubleSpinBox::wheelEvent(pEvent);
} }
void WDraggableSpinBox::contextMenuEvent(QContextMenuEvent *pEvent)
{
pEvent->ignore();
}
void WDraggableSpinBox::SetDefaultValue(double value)
{
mDefaultValue = value;
}

View File

@ -18,6 +18,8 @@ public:
void mouseReleaseEvent(QMouseEvent *pEvent); void mouseReleaseEvent(QMouseEvent *pEvent);
void mouseMoveEvent(QMouseEvent *pEvent); void mouseMoveEvent(QMouseEvent *pEvent);
void wheelEvent(QWheelEvent *pEvent); void wheelEvent(QWheelEvent *pEvent);
void contextMenuEvent(QContextMenuEvent *pEvent);
void SetDefaultValue(double value);
}; };
#endif // WDRAGGABLESPINBOX_H #endif // WDRAGGABLESPINBOX_H

View File

@ -40,6 +40,9 @@ WVectorEditor::WVectorEditor(const CVector3f& Value, QWidget *pParent) : QWidget
mpSpinBoxX = new WDraggableSpinBox(this); mpSpinBoxX = new WDraggableSpinBox(this);
mpSpinBoxY = new WDraggableSpinBox(this); mpSpinBoxY = new WDraggableSpinBox(this);
mpSpinBoxZ = new WDraggableSpinBox(this); mpSpinBoxZ = new WDraggableSpinBox(this);
mpSpinBoxX->setDecimals(4);
mpSpinBoxX->setDecimals(4);
mpSpinBoxX->setDecimals(4);
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);