Debian Codegraph @

src/Gui/EditableDatumLabel.h

raw
1 /// SPDX-License-Identifier: LGPL-2.1-or-later
2 /****************************************************************************
3 * *
4 * Copyright (c) 2023 Ondsel <[email protected]> *
5 * *
6 * This file is part of FreeCAD. *
7 * *
8 * FreeCAD is free software: you can redistribute it and/or modify it *
9 * under the terms of the GNU Lesser General Public License as *
10 * published by the Free Software Foundation, either version 2.1 of the *
11 * License, or (at your option) any later version. *
12 * *
13 * FreeCAD is distributed in the hope that it will be useful, but *
14 * WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with FreeCAD. If not, see *
20 * <https://www.gnu.org/licenses/>. *
21 * *
22 ***************************************************************************/
23
24 #ifndef GUI_EDITABLEDATUMLABEL_H
25 #define GUI_EDITABLEDATUMLABEL_H
26
27 #include <QObject>
28 #include <QPointer>
29 #include <QLabel>
30 #include <Gui/QuantitySpinBox.h>
31
32 #include "SoDatumLabel.h"
33
34 #include <FCGlobal.h>
35
36 class SoNodeSensor;
37 class SoTransform;
38 class SoAnnotation;
39 class SoSwitch;
40
41 namespace Gui
42 {
43
44 class View3DInventorViewer;
45
46
47 class GuiExport EditableDatumLabel: public QObject
48 {
49 Q_OBJECT
50 Q_DISABLE_COPY(EditableDatumLabel)
51
52 public:
53 enum class Function
54 {
55 Positioning,
56 Dimensioning,
57 Forced
58 };
59
60 EditableDatumLabel(
61 View3DInventorViewer* view,
62 const Base::Placement& plc,
63 SbColor color,
64 bool autoDistance = false,
65 bool avoidMouseCursor = false
66 );
67
68 ~EditableDatumLabel() override;
69
70 void activate();
71 void deactivate();
72
73 void startEdit(double val, QObject* eventFilteringObj = nullptr, bool visibleToMouse = false);
74 void stopEdit();
75 bool isActive() const;
76 bool isInEdit() const;
77 double getValue() const;
78 void setSpinboxValue(double val, const Base::Unit& unit = Base::Unit::Length);
79 void setPlacement(const Base::Placement& plc);
80 void setColor(SbColor color);
81 void setFocus();
82 void setPoints(SbVec3f p1, SbVec3f p2);
83 void setPoints(Base::Vector3d p1, Base::Vector3d p2);
84 void setFocusToSpinbox();
85 void clearSelection(); ///< Clears text selection in the spinbox
86 void setLabelType(SoDatumLabel::Type type, Function function = Function::Positioning);
87 void setLabelDistance(double val);
88 void setLabelStartAngle(double val);
89 void setLabelRange(double val);
90 void setLabelRecommendedDistance();
91 void setLabelAutoDistanceReverse(bool val);
92 void setSpinboxVisibleToMouse(bool val);
93 void setLockedAppearance(bool locked); ///< Sets visual appearance to indicate locked state
94 ///< (finished editing)
95 void resetLockedState(); ///< Resets both hasFinishedEditing flag and locked appearance
96
97 Function getFunction();
98
99 // NOLINTBEGIN
100 SoDatumLabel* label;
101 bool isSet; ///< used to differentiate when user has started typing inside the label
102 bool hasFinishedEditing; ///< flag to know when user has finished editing, i.e. pressed enter
103 bool autoDistance;
104 bool autoDistanceReverse;
105 bool avoidMouseCursor;
106 double value;
107 // NOLINTEND
108
109 Q_SIGNALS:
110 void valueChanged(double val);
111 void parameterUnset();
112 void finishEditingOnAllOVPs(); ///< Emitted when Ctrl+Enter is pressed to finish editing on all
113 ///< visible OVPs
114
115 protected:
116 bool eventFilter(QObject* watched, QEvent* event) override;
117
118 private:
119 void positionSpinbox();
120 SbVec3f getTextCenterPoint() const;
121
122 private:
123 SoSwitch* root;
124 SoAnnotation* annotation;
125 SoTransform* transform;
126 QPointer<View3DInventorViewer> viewer;
127 QuantitySpinBox* spinBox;
128 QLabel* lockIconLabel; ///< Label to display lock icon next to spinbox
129 SoNodeSensor* cameraSensor;
130 SbVec3f midpos;
131
132 Function function;
133 };
134
135 } // namespace Gui
136
137
138 #endif // GUI_EDITABLEDATUMLABEL_H