Skip to content

Commit ff46834

Browse files
committed
Set spinbox and ladder steps based on context.
1 parent f760907 commit ff46834

File tree

6 files changed

+168
-9
lines changed

6 files changed

+168
-9
lines changed

common/lc_doublespinbox.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "lc_doublespinbox.h"
33
#include "lc_ladderwidget.h"
44
#include "lc_qutils.h"
5+
#include "lc_mainwindow.h"
56

67
lcDoubleSpinBox::lcDoubleSpinBox(QWidget* Parent)
78
: QDoubleSpinBox(Parent)
@@ -19,6 +20,34 @@ void lcDoubleSpinBox::SetValue(double Value)
1920
setValue(Value);
2021
}
2122

23+
void lcDoubleSpinBox::SetSnap(lcFloatPropertySnap Snap)
24+
{
25+
mSnap = Snap;
26+
27+
switch (Snap)
28+
{
29+
case lcFloatPropertySnap::Auto:
30+
setSingleStep(10.0);
31+
break;
32+
33+
case lcFloatPropertySnap::PiecePositionXY:
34+
setSingleStep(gMainWindow->GetMoveXYSnap());
35+
break;
36+
37+
case lcFloatPropertySnap::PiecePositionZ:
38+
setSingleStep(gMainWindow->GetMoveZSnap());
39+
break;
40+
41+
case lcFloatPropertySnap::Position:
42+
setSingleStep(10.0);
43+
break;
44+
45+
case lcFloatPropertySnap::Rotation:
46+
setSingleStep(gMainWindow->GetAngleSnap());
47+
break;
48+
}
49+
}
50+
2251
QString lcDoubleSpinBox::textFromValue(double Value) const
2352
{
2453
return lcFormatValueLocalized(Value);
@@ -71,7 +100,7 @@ void lcDoubleSpinBox::HandleMousePressEvent(QMouseEvent* MouseEvent)
71100

72101
if (MouseEvent->buttons() == Qt::MiddleButton)
73102
{
74-
lcLadderWidget* LadderWidget = new lcLadderWidget(this);
103+
lcLadderWidget* LadderWidget = new lcLadderWidget(this, mSnap);
75104

76105
connect(LadderWidget, &lcLadderWidget::EditingCanceled, this, &lcDoubleSpinBox::CancelEditing);
77106
connect(LadderWidget, &lcLadderWidget::EditingFinished, this, &lcDoubleSpinBox::FinishEditing);

common/lc_doublespinbox.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "lc_objectproperty.h"
4+
35
class lcDoubleSpinBox : public QDoubleSpinBox
46
{
57
Q_OBJECT
@@ -9,6 +11,7 @@ class lcDoubleSpinBox : public QDoubleSpinBox
911
virtual ~lcDoubleSpinBox() = default;
1012

1113
void SetValue(double Value);
14+
void SetSnap(lcFloatPropertySnap Snap);
1215

1316
QString textFromValue(double Value) const override;
1417
bool eventFilter(QObject* Object, QEvent* Event) override;
@@ -53,4 +56,5 @@ protected slots:
5356
double mInitialValue = 0.0;
5457
QPoint mLastPosition;
5558
DragMode mDragMode = DragMode::None;
59+
lcFloatPropertySnap mSnap = lcFloatPropertySnap::Auto;
5660
};

common/lc_ladderwidget.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "lc_global.h"
22
#include "lc_ladderwidget.h"
3+
#include "lc_objectproperty.h"
34

4-
lcLadderWidget::lcLadderWidget(QAbstractSpinBox* SpinBox)
5+
lcLadderWidget::lcLadderWidget(QAbstractSpinBox* SpinBox, lcFloatPropertySnap Snap)
56
: QWidget(nullptr, Qt::Popup | Qt::Sheet), mSpinBox(SpinBox)
67
{
78
mSpinBox->installEventFilter(this);
9+
10+
CalculateSteps(Snap);
811
}
912

1013
void lcLadderWidget::Show()
@@ -16,7 +19,6 @@ void lcLadderWidget::Show()
1619
const QRect Desktop = QApplication::desktop()->geometry();
1720
#endif
1821

19-
mSteps = { 100, 10, 1 };
2022
int LineHeight = QFontMetrics(font()).height();
2123
int CellSize = LineHeight * 4;
2224

@@ -48,6 +50,45 @@ void lcLadderWidget::Show()
4850
grabMouse();
4951
}
5052

53+
void lcLadderWidget::CalculateSteps(lcFloatPropertySnap Snap)
54+
{
55+
QDoubleSpinBox* SpinBox = qobject_cast<QDoubleSpinBox*>(mSpinBox);
56+
57+
switch (Snap)
58+
{
59+
case lcFloatPropertySnap::Auto:
60+
if (SpinBox)
61+
{
62+
double Max = SpinBox->maximum();
63+
64+
if (Max > 200.0)
65+
mSteps = { 1000.0, 100.0, 10.0, 1.0, 0.1 };
66+
else
67+
mSteps = { 30.0, 10.0, 1.0, 0.1, 0.01 };
68+
}
69+
break;
70+
71+
case lcFloatPropertySnap::PiecePositionXY:
72+
mSteps = { 80.0, 40.0, 24.0, 20.0, 10.0, 8.0, 1.0 };
73+
break;
74+
75+
case lcFloatPropertySnap::PiecePositionZ:
76+
mSteps = { 192.0, 96.0, 48.0, 24.0, 10.0, 8.0, 1.0 };
77+
break;
78+
79+
case lcFloatPropertySnap::Position:
80+
mSteps = { 1000.0, 100.0, 50.0, 10.0, 5.0, 1.0, 0.1 };
81+
break;
82+
83+
case lcFloatPropertySnap::Rotation:
84+
mSteps = { 90.0, 45.0, 30.0, 22.5, 15.0, 1.0, 0.1 };
85+
break;
86+
}
87+
88+
if (mSteps.empty())
89+
mSteps = { 100.0, 10.0, 1.0, 0.1, 0.01 };
90+
}
91+
5192
void lcLadderWidget::UpdateMousePosition()
5293
{
5394
QPoint MousePosition = mapFromGlobal(QCursor::pos());
@@ -128,7 +169,7 @@ void lcLadderWidget::paintEvent(QPaintEvent* Event)
128169
QTextOption TextOption(Qt::AlignCenter);
129170
QString Text = QString::number(mSteps[Step]);
130171

131-
if (Step == mCurrentStep)
172+
if (Step == mCurrentStep && mSpinBox)
132173
Text = QString("%1\n\n(%2)").arg(Text, mSpinBox->text());
133174

134175
Painter.drawText(Rect, Text, TextOption);

common/lc_ladderwidget.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

3+
enum class lcFloatPropertySnap;
4+
35
class lcLadderWidget: public QWidget
46
{
57
Q_OBJECT
68

79
public:
8-
lcLadderWidget(QAbstractSpinBox* SpinBox);
10+
lcLadderWidget(QAbstractSpinBox* SpinBox, lcFloatPropertySnap Snap);
911
virtual ~lcLadderWidget() = default;
1012

1113
void Show();
@@ -24,11 +26,12 @@ protected slots:
2426
void FinishEditing();
2527

2628
protected:
29+
void CalculateSteps(lcFloatPropertySnap Snap);
2730
void UpdateMousePosition();
2831

2932
void paintEvent(QPaintEvent* PaintEvent) override;
3033

31-
QAbstractSpinBox* mSpinBox = nullptr;
34+
QPointer<QAbstractSpinBox> mSpinBox = nullptr;
3235
std::vector<double> mSteps;
3336
int mCurrentStep = -1;
3437
int mLastMousePositionX = 0;

common/lc_objectproperty.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ enum class lcObjectPropertyId
4848
Count
4949
};
5050

51+
enum class lcFloatPropertySnap
52+
{
53+
Auto,
54+
PiecePositionXY,
55+
PiecePositionZ,
56+
Position,
57+
Rotation
58+
};
59+
5160
template<typename T>
5261
struct lcObjectPropertyKey
5362
{

common/lc_propertieswidget.cpp

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,82 @@ void lcPropertiesWidget::UpdateFloat(lcObjectPropertyId PropertyId, float Value)
481481
{
482482
QSignalBlocker Blocker(Widget);
483483

484+
switch (PropertyId)
485+
{
486+
case lcObjectPropertyId::PieceId:
487+
case lcObjectPropertyId::PieceColor:
488+
case lcObjectPropertyId::PieceStepShow:
489+
case lcObjectPropertyId::PieceStepHide:
490+
case lcObjectPropertyId::CameraName:
491+
case lcObjectPropertyId::CameraType:
492+
break;
493+
494+
case lcObjectPropertyId::CameraFOV:
495+
case lcObjectPropertyId::CameraNear:
496+
case lcObjectPropertyId::CameraFar:
497+
Widget->SetSnap(lcFloatPropertySnap::Auto);
498+
break;
499+
500+
case lcObjectPropertyId::CameraPositionX:
501+
case lcObjectPropertyId::CameraPositionY:
502+
case lcObjectPropertyId::CameraPositionZ:
503+
case lcObjectPropertyId::CameraTargetX:
504+
case lcObjectPropertyId::CameraTargetY:
505+
case lcObjectPropertyId::CameraTargetZ:
506+
Widget->SetSnap(lcFloatPropertySnap::Position);
507+
break;
508+
509+
case lcObjectPropertyId::CameraUpX:
510+
case lcObjectPropertyId::CameraUpY:
511+
case lcObjectPropertyId::CameraUpZ:
512+
Widget->SetSnap(lcFloatPropertySnap::Auto);
513+
break;
514+
515+
case lcObjectPropertyId::LightName:
516+
case lcObjectPropertyId::LightType:
517+
case lcObjectPropertyId::LightColor:
518+
break;
519+
520+
case lcObjectPropertyId::LightBlenderPower:
521+
case lcObjectPropertyId::LightPOVRayPower:
522+
case lcObjectPropertyId::LightCastShadow:
523+
case lcObjectPropertyId::LightPOVRayFadeDistance:
524+
case lcObjectPropertyId::LightPOVRayFadePower:
525+
case lcObjectPropertyId::LightPointBlenderRadius:
526+
case lcObjectPropertyId::LightSpotBlenderRadius:
527+
case lcObjectPropertyId::LightDirectionalBlenderAngle:
528+
case lcObjectPropertyId::LightAreaSizeX:
529+
case lcObjectPropertyId::LightAreaSizeY:
530+
case lcObjectPropertyId::LightSpotConeAngle:
531+
case lcObjectPropertyId::LightSpotPenumbraAngle:
532+
case lcObjectPropertyId::LightSpotPOVRayTightness:
533+
Widget->SetSnap(lcFloatPropertySnap::Auto);
534+
break;
535+
536+
case lcObjectPropertyId::LightAreaShape:
537+
case lcObjectPropertyId::LightAreaPOVRayGridX:
538+
case lcObjectPropertyId::LightAreaPOVRayGridY:
539+
break;
540+
541+
case lcObjectPropertyId::ObjectPositionX:
542+
case lcObjectPropertyId::ObjectPositionY:
543+
Widget->SetSnap(mLayoutMode == LayoutMode::Piece ? lcFloatPropertySnap::PiecePositionXY : lcFloatPropertySnap::Position);
544+
break;
545+
546+
case lcObjectPropertyId::ObjectPositionZ:
547+
Widget->SetSnap(mLayoutMode == LayoutMode::Piece ? lcFloatPropertySnap::PiecePositionZ : lcFloatPropertySnap::Position);
548+
break;
549+
550+
case lcObjectPropertyId::ObjectRotationX:
551+
case lcObjectPropertyId::ObjectRotationY:
552+
case lcObjectPropertyId::ObjectRotationZ:
553+
Widget->SetSnap(lcFloatPropertySnap::Rotation);
554+
break;
555+
556+
case lcObjectPropertyId::Count:
557+
break;
558+
}
559+
484560
Widget->SetValue(Value);
485561
}
486562

@@ -858,7 +934,6 @@ void lcPropertiesWidget::AddColorProperty(lcObjectPropertyId PropertyId, const Q
858934

859935
QToolButton* Widget = new QToolButton(this);
860936
Widget->setToolTip(ToolTip);
861-
Widget->setAutoRaise(true);
862937
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
863938
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
864939

@@ -955,7 +1030,6 @@ void lcPropertiesWidget::AddPieceColorProperty(lcObjectPropertyId PropertyId, co
9551030

9561031
QToolButton* Widget = new QToolButton(this);
9571032
Widget->setToolTip(ToolTip);
958-
Widget->setAutoRaise(true);
9591033
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
9601034
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
9611035

@@ -1046,7 +1120,6 @@ void lcPropertiesWidget::AddPieceIdProperty(lcObjectPropertyId PropertyId, const
10461120

10471121
lcElidableToolButton* Widget = new lcElidableToolButton(this);
10481122
Widget->setToolTip(ToolTip);
1049-
Widget->setAutoRaise(true);
10501123
Widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
10511124
Widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
10521125

0 commit comments

Comments
 (0)