Set spinbox and ladder steps based on context.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "lc_doublespinbox.h"
|
||||
#include "lc_ladderwidget.h"
|
||||
#include "lc_qutils.h"
|
||||
#include "lc_mainwindow.h"
|
||||
|
||||
lcDoubleSpinBox::lcDoubleSpinBox(QWidget* Parent)
|
||||
: QDoubleSpinBox(Parent)
|
||||
@@ -19,6 +20,34 @@ void lcDoubleSpinBox::SetValue(double Value)
|
||||
setValue(Value);
|
||||
}
|
||||
|
||||
void lcDoubleSpinBox::SetSnap(lcFloatPropertySnap Snap)
|
||||
{
|
||||
mSnap = Snap;
|
||||
|
||||
switch (Snap)
|
||||
{
|
||||
case lcFloatPropertySnap::Auto:
|
||||
setSingleStep(10.0);
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::PiecePositionXY:
|
||||
setSingleStep(gMainWindow->GetMoveXYSnap());
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::PiecePositionZ:
|
||||
setSingleStep(gMainWindow->GetMoveZSnap());
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::Position:
|
||||
setSingleStep(10.0);
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::Rotation:
|
||||
setSingleStep(gMainWindow->GetAngleSnap());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString lcDoubleSpinBox::textFromValue(double Value) const
|
||||
{
|
||||
return lcFormatValueLocalized(Value);
|
||||
@@ -71,7 +100,7 @@ void lcDoubleSpinBox::HandleMousePressEvent(QMouseEvent* MouseEvent)
|
||||
|
||||
if (MouseEvent->buttons() == Qt::MiddleButton)
|
||||
{
|
||||
lcLadderWidget* LadderWidget = new lcLadderWidget(this);
|
||||
lcLadderWidget* LadderWidget = new lcLadderWidget(this, mSnap);
|
||||
|
||||
connect(LadderWidget, &lcLadderWidget::EditingCanceled, this, &lcDoubleSpinBox::CancelEditing);
|
||||
connect(LadderWidget, &lcLadderWidget::EditingFinished, this, &lcDoubleSpinBox::FinishEditing);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "lc_objectproperty.h"
|
||||
|
||||
class lcDoubleSpinBox : public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -9,6 +11,7 @@ public:
|
||||
virtual ~lcDoubleSpinBox() = default;
|
||||
|
||||
void SetValue(double Value);
|
||||
void SetSnap(lcFloatPropertySnap Snap);
|
||||
|
||||
QString textFromValue(double Value) const override;
|
||||
bool eventFilter(QObject* Object, QEvent* Event) override;
|
||||
@@ -53,4 +56,5 @@ protected:
|
||||
double mInitialValue = 0.0;
|
||||
QPoint mLastPosition;
|
||||
DragMode mDragMode = DragMode::None;
|
||||
lcFloatPropertySnap mSnap = lcFloatPropertySnap::Auto;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#include "lc_global.h"
|
||||
#include "lc_ladderwidget.h"
|
||||
#include "lc_objectproperty.h"
|
||||
|
||||
lcLadderWidget::lcLadderWidget(QAbstractSpinBox* SpinBox)
|
||||
lcLadderWidget::lcLadderWidget(QAbstractSpinBox* SpinBox, lcFloatPropertySnap Snap)
|
||||
: QWidget(nullptr, Qt::Popup | Qt::Sheet), mSpinBox(SpinBox)
|
||||
{
|
||||
mSpinBox->installEventFilter(this);
|
||||
|
||||
CalculateSteps(Snap);
|
||||
}
|
||||
|
||||
void lcLadderWidget::Show()
|
||||
@@ -16,7 +19,6 @@ void lcLadderWidget::Show()
|
||||
const QRect Desktop = QApplication::desktop()->geometry();
|
||||
#endif
|
||||
|
||||
mSteps = { 100, 10, 1 };
|
||||
int LineHeight = QFontMetrics(font()).height();
|
||||
int CellSize = LineHeight * 4;
|
||||
|
||||
@@ -48,6 +50,45 @@ void lcLadderWidget::Show()
|
||||
grabMouse();
|
||||
}
|
||||
|
||||
void lcLadderWidget::CalculateSteps(lcFloatPropertySnap Snap)
|
||||
{
|
||||
QDoubleSpinBox* SpinBox = qobject_cast<QDoubleSpinBox*>(mSpinBox);
|
||||
|
||||
switch (Snap)
|
||||
{
|
||||
case lcFloatPropertySnap::Auto:
|
||||
if (SpinBox)
|
||||
{
|
||||
double Max = SpinBox->maximum();
|
||||
|
||||
if (Max > 200.0)
|
||||
mSteps = { 1000.0, 100.0, 10.0, 1.0, 0.1 };
|
||||
else
|
||||
mSteps = { 30.0, 10.0, 1.0, 0.1, 0.01 };
|
||||
}
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::PiecePositionXY:
|
||||
mSteps = { 80.0, 40.0, 24.0, 20.0, 10.0, 8.0, 1.0 };
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::PiecePositionZ:
|
||||
mSteps = { 192.0, 96.0, 48.0, 24.0, 10.0, 8.0, 1.0 };
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::Position:
|
||||
mSteps = { 1000.0, 100.0, 50.0, 10.0, 5.0, 1.0, 0.1 };
|
||||
break;
|
||||
|
||||
case lcFloatPropertySnap::Rotation:
|
||||
mSteps = { 90.0, 45.0, 30.0, 22.5, 15.0, 1.0, 0.1 };
|
||||
break;
|
||||
}
|
||||
|
||||
if (mSteps.empty())
|
||||
mSteps = { 100.0, 10.0, 1.0, 0.1, 0.01 };
|
||||
}
|
||||
|
||||
void lcLadderWidget::UpdateMousePosition()
|
||||
{
|
||||
QPoint MousePosition = mapFromGlobal(QCursor::pos());
|
||||
@@ -128,7 +169,7 @@ void lcLadderWidget::paintEvent(QPaintEvent* Event)
|
||||
QTextOption TextOption(Qt::AlignCenter);
|
||||
QString Text = QString::number(mSteps[Step]);
|
||||
|
||||
if (Step == mCurrentStep)
|
||||
if (Step == mCurrentStep && mSpinBox)
|
||||
Text = QString("%1\n\n(%2)").arg(Text, mSpinBox->text());
|
||||
|
||||
Painter.drawText(Rect, Text, TextOption);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
enum class lcFloatPropertySnap;
|
||||
|
||||
class lcLadderWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcLadderWidget(QAbstractSpinBox* SpinBox);
|
||||
lcLadderWidget(QAbstractSpinBox* SpinBox, lcFloatPropertySnap Snap);
|
||||
virtual ~lcLadderWidget() = default;
|
||||
|
||||
void Show();
|
||||
@@ -24,11 +26,12 @@ protected slots:
|
||||
void FinishEditing();
|
||||
|
||||
protected:
|
||||
void CalculateSteps(lcFloatPropertySnap Snap);
|
||||
void UpdateMousePosition();
|
||||
|
||||
void paintEvent(QPaintEvent* PaintEvent) override;
|
||||
|
||||
QAbstractSpinBox* mSpinBox = nullptr;
|
||||
QPointer<QAbstractSpinBox> mSpinBox = nullptr;
|
||||
std::vector<double> mSteps;
|
||||
int mCurrentStep = -1;
|
||||
int mLastMousePositionX = 0;
|
||||
|
||||
@@ -48,6 +48,15 @@ enum class lcObjectPropertyId
|
||||
Count
|
||||
};
|
||||
|
||||
enum class lcFloatPropertySnap
|
||||
{
|
||||
Auto,
|
||||
PiecePositionXY,
|
||||
PiecePositionZ,
|
||||
Position,
|
||||
Rotation
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct lcObjectPropertyKey
|
||||
{
|
||||
|
||||
@@ -481,6 +481,82 @@ void lcPropertiesWidget::UpdateFloat(lcObjectPropertyId PropertyId, float Value)
|
||||
{
|
||||
QSignalBlocker Blocker(Widget);
|
||||
|
||||
switch (PropertyId)
|
||||
{
|
||||
case lcObjectPropertyId::PieceId:
|
||||
case lcObjectPropertyId::PieceColor:
|
||||
case lcObjectPropertyId::PieceStepShow:
|
||||
case lcObjectPropertyId::PieceStepHide:
|
||||
case lcObjectPropertyId::CameraName:
|
||||
case lcObjectPropertyId::CameraType:
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::CameraFOV:
|
||||
case lcObjectPropertyId::CameraNear:
|
||||
case lcObjectPropertyId::CameraFar:
|
||||
Widget->SetSnap(lcFloatPropertySnap::Auto);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::CameraPositionX:
|
||||
case lcObjectPropertyId::CameraPositionY:
|
||||
case lcObjectPropertyId::CameraPositionZ:
|
||||
case lcObjectPropertyId::CameraTargetX:
|
||||
case lcObjectPropertyId::CameraTargetY:
|
||||
case lcObjectPropertyId::CameraTargetZ:
|
||||
Widget->SetSnap(lcFloatPropertySnap::Position);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::CameraUpX:
|
||||
case lcObjectPropertyId::CameraUpY:
|
||||
case lcObjectPropertyId::CameraUpZ:
|
||||
Widget->SetSnap(lcFloatPropertySnap::Auto);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::LightName:
|
||||
case lcObjectPropertyId::LightType:
|
||||
case lcObjectPropertyId::LightColor:
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::LightBlenderPower:
|
||||
case lcObjectPropertyId::LightPOVRayPower:
|
||||
case lcObjectPropertyId::LightCastShadow:
|
||||
case lcObjectPropertyId::LightPOVRayFadeDistance:
|
||||
case lcObjectPropertyId::LightPOVRayFadePower:
|
||||
case lcObjectPropertyId::LightPointBlenderRadius:
|
||||
case lcObjectPropertyId::LightSpotBlenderRadius:
|
||||
case lcObjectPropertyId::LightDirectionalBlenderAngle:
|
||||
case lcObjectPropertyId::LightAreaSizeX:
|
||||
case lcObjectPropertyId::LightAreaSizeY:
|
||||
case lcObjectPropertyId::LightSpotConeAngle:
|
||||
case lcObjectPropertyId::LightSpotPenumbraAngle:
|
||||
case lcObjectPropertyId::LightSpotPOVRayTightness:
|
||||
Widget->SetSnap(lcFloatPropertySnap::Auto);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::LightAreaShape:
|
||||
case lcObjectPropertyId::LightAreaPOVRayGridX:
|
||||
case lcObjectPropertyId::LightAreaPOVRayGridY:
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::ObjectPositionX:
|
||||
case lcObjectPropertyId::ObjectPositionY:
|
||||
Widget->SetSnap(mLayoutMode == LayoutMode::Piece ? lcFloatPropertySnap::PiecePositionXY : lcFloatPropertySnap::Position);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::ObjectPositionZ:
|
||||
Widget->SetSnap(mLayoutMode == LayoutMode::Piece ? lcFloatPropertySnap::PiecePositionZ : lcFloatPropertySnap::Position);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::ObjectRotationX:
|
||||
case lcObjectPropertyId::ObjectRotationY:
|
||||
case lcObjectPropertyId::ObjectRotationZ:
|
||||
Widget->SetSnap(lcFloatPropertySnap::Rotation);
|
||||
break;
|
||||
|
||||
case lcObjectPropertyId::Count:
|
||||
break;
|
||||
}
|
||||
|
||||
Widget->SetValue(Value);
|
||||
}
|
||||
|
||||
@@ -858,7 +934,6 @@ void lcPropertiesWidget::AddColorProperty(lcObjectPropertyId PropertyId, const Q
|
||||
|
||||
QToolButton* Widget = new QToolButton(this);
|
||||
Widget->setToolTip(ToolTip);
|
||||
Widget->setAutoRaise(true);
|
||||
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
@@ -955,7 +1030,6 @@ void lcPropertiesWidget::AddPieceColorProperty(lcObjectPropertyId PropertyId, co
|
||||
|
||||
QToolButton* Widget = new QToolButton(this);
|
||||
Widget->setToolTip(ToolTip);
|
||||
Widget->setAutoRaise(true);
|
||||
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
@@ -1046,7 +1120,6 @@ void lcPropertiesWidget::AddPieceIdProperty(lcObjectPropertyId PropertyId, const
|
||||
|
||||
lcElidableToolButton* Widget = new lcElidableToolButton(this);
|
||||
Widget->setToolTip(ToolTip);
|
||||
Widget->setAutoRaise(true);
|
||||
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user