33#include <NDEVR/QCustomValidator.h>
35#include <NDEVR/QTTools.h>
36#include <NDEVR/String.h>
37#include <NDEVR/ApplicationOptions.h>
38#include <NDEVR/ObjectInfo.h>
39#include <NDEVR/TimeSpan.h>
40#include <NDEVR/Unit.h>
41#include <NDEVR/ObjectInfo.h>
42#include <NDEVR/RGBColor.h>
47 template<
class t_type,
bool is_number>
54 lib_assert(
false,
"Trying to convert non-number");
60 lib_assert(
false,
"Trying to convert non-number");
64 template<
class t_type>
122 explicit QCustomLineEdit(
const QString& value, QWidget *parent = Q_NULLPTR);
130 void setAsKeyboardFocus();
131 bool isValid()
const;
132 void setEditable(
bool editable );
134 bool isEditing()
const;
135 bool hasUserFocus()
const;
136 void clearBackgroundColor();
138 void clearInputHint();
140 String getValue(
bool allow_placeholder)
const;
142 template<
class t_angle_type>
145 setUnitValue(value.template as<INTERNAL_ANGLE>());
147 void setUnitValue(
fltp08 value);
148 void setPlaceHolderUnitValue(
fltp08 value);
149 template<
class t_angle_type = fltp08>
154 fltp08 getUnitValue(
bool allow_placeholder =
true)
const;
155 template<
class t_type>
160 m_validator.setTypeInfo(GetTypeInfo<t_type>());
167 template<
class t_type>
172 template<
class t_type>
175 setup<t_type>(title);
176 connect(
this, &QCustomLineEdit::editingFinishedSignal,
this, [
this, &resource]
180 if (!customValidator().unit().isNull())
183 resource.
set(getAs<t_type>());
187 resource.
set(getAs<t_type>());
190 if (m_resource_changed_listener)
191 delete m_resource_changed_listener;
196 if (!customValidator().unit().isNull())
199 setValue(resource.
get());
203 setValue(resource.
get());
209 void setAllowPlaceholderAsValue(
bool allow);
210 template<
class t_type>
211 t_type
getAs(
bool allow_placeholder)
const
213 return getValue(allow_placeholder).getAs<t_type>();
215 template<
class t_type>
218 return getValue(m_allow_placeholder_as_value).getAs<t_type>();
220 template<
class t_type>
221 typename std::enable_if<ObjectInfo<t_type>::Number,
void>::type
setValue(
const t_type& input_value)
223 if (m_ignore_focus_lock || !hasUserFocus())
225 if(m_validator.unit().isNull())
226 m_current_value =
String(input_value);
227 else if(!
isNaN(m_validator.unitDimension()))
228 m_current_value = m_validator.unit()->toString(input_value,
false, 0,
Constant<uint04>::Max, 0,
false, m_validator.unitDimension());
230 m_current_value = m_validator.unit()->toString(input_value,
false, 0,
Constant<uint04>::Max, 0,
false);
231 QString input = m_current_value.getAs<QString>();
232 m_validator.fixup(input);
233 m_fixed_up_current_value =
String(input);
235 if (m_validator.validate(input, valid_pos))
236 m_last_valid = m_fixed_up_current_value;
240 template<
class t_type>
241 typename std::enable_if<!ObjectInfo<t_type>::Number,
void>::type
setValue(
const t_type& input_value)
243 if (m_ignore_focus_lock || !hasUserFocus())
246 if (m_current_value != val)
248 m_current_value = val;
250 m_validator.fixup(input);
251 m_fixed_up_current_value =
String(input);
253 if (m_validator.validate(input, valid_pos))
254 m_last_valid = m_fixed_up_current_value;
259 void setValue(
const TimeSpan& input_value);
262 setValue(
String(input_value));
266 setValue(
String(input_value));
268 void setBackgroundColor(
const RGBColor& color);
270 template<
class t_type>
273 setAllowPlaceholderAsValue(allow_placeholder_as_value);
274 QString input =
String(input_value).
getAs<QString>();
275 m_validator.fixup(input);
276 setPlaceholderText(input);
278 void setPlaceholderValue(
const TranslatedString& input_value,
bool allow_placeholder_as_value =
true);
279 QSize sizeHint()
const override;
280 QSize minimumSizeHint()
const override;
281 void wheelEvent(QWheelEvent *event)
override;
282 void forceValue(
const String& units);
283 bool event(QEvent* event)
override;
286 void setStep(
fltp08 step);
288 static bool UseKeypad();
289 void setPlaceholderText(
const QString& value);
290 void startUserEdit(
bool select_all =
true);
291 void setFontMultiplier(
fltp04 font_multiplier);
292 void setBold(
bool is_bold);
295 void paintEvent(QPaintEvent *event)
override;
297 virtual void mousePressEvent(QMouseEvent *e)
override;
298 virtual void focusInEvent(QFocusEvent *e)
override;
299 virtual void focusOutEvent(QFocusEvent *e)
override;
300 virtual void creatUnitLister();
302 void _setBackgroundColor(
const RGBColor& color);
309 void onFinishedSlot();
311 void updateCharColors();
327 bool m_is_editable =
true;
328 bool m_auto_show_tooltip =
true;
329 bool m_suppress_focus_out =
false;
330 bool m_allow_placeholder_as_value =
true;
331 bool m_is_bold =
false;
332 bool m_ignore_focus_lock =
false;
333 bool m_has_edited =
false;
#define UNUSED(expr)
Definition BaseValues.hpp:433
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Stores an angle in an optimized format.
Definition StringStream.h:352
constexpr t_type internal() const
Definition Angle.h:313
The default object to store data of any type that should persist through sessions of the application.
Definition Button.h:57
Resource< t_type > & getResource()
Definition ApplicationOptions.h:106
const TranslatedString & label() const
Definition ApplicationOptions.h:144
Definition GraphicsPipeline.h:42
Definition QCustomLineEdit.h:118
bool isEditable() const
Definition QCustomLineEdit.h:133
void inputHintChangedSignal()
void setup(const TranslatedString &title)
Definition QCustomLineEdit.h:156
TranslatedString m_tooltip
Definition QCustomLineEdit.h:321
t_type getAs(bool allow_placeholder) const
Definition QCustomLineEdit.h:211
String m_current_value
Definition QCustomLineEdit.h:314
String m_fixed_up_current_value
Definition QCustomLineEdit.h:315
void setup(const TranslatedString &title, Resource< t_type > &resource)
Definition QCustomLineEdit.h:173
QCustomValidator m_validator
Definition QCustomLineEdit.h:325
TranslatedString m_title
Definition QCustomLineEdit.h:320
String m_custom_unit
Definition QCustomLineEdit.h:317
std::enable_if< ObjectInfo< t_type >::Number, void >::type setValue(const t_type &input_value)
Definition QCustomLineEdit.h:221
void setUnitValue(Angle< t_angle_type > value)
Definition QCustomLineEdit.h:143
void setValue(const Angle< sint04 > &input_value)
Definition QCustomLineEdit.h:260
void setAutoShowTooltip(bool auto_show_tooltip)
Definition QCustomLineEdit.h:287
void setPlaceholderValue(const t_type &input_value, bool allow_placeholder_as_value=true)
Definition QCustomLineEdit.h:271
t_type getAs() const
Definition QCustomLineEdit.h:216
Angle< t_angle_type > getUnitAngle(bool allow_placeholder=true) const
Definition QCustomLineEdit.h:150
TranslatedString m_input_hint
Definition QCustomLineEdit.h:318
void setup(ApplicationOption< t_type > &option)
Definition QCustomLineEdit.h:168
std::enable_if<!ObjectInfo< t_type >::Number, void >::type setValue(const t_type &input_value)
Definition QCustomLineEdit.h:241
void setValue(const Angle< fltp08 > &input_value)
Definition QCustomLineEdit.h:264
void editingFinishedSignal()
TranslatedString m_custom_input_hint
Definition QCustomLineEdit.h:319
String m_last_valid
Definition QCustomLineEdit.h:316
Definition QCustomValidator.h:43
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
ResourceListener * addListener(ResourceListener *listener) const
Definition ResourceListener.cpp:37
const T & get() const
Definition Resource.h:67
void set(const T &info, bool check_equal=true)
Definition Resource.h:49
static fltp08 ValueToFloat(const Angle< fltp08 > &value)
Definition QCustomLineEdit.h:94
static Angle< fltp08 > ValueFromFloat(const fltp08 &value)
Definition QCustomLineEdit.h:98
static Angle< sint04 > ValueFromFloat(const fltp08 &value)
Definition QCustomLineEdit.h:111
static fltp08 ValueToFloat(const Angle< sint04 > &value)
Definition QCustomLineEdit.h:107
static fltp08 ValueToFloat(const TimeSpan &value)
Definition QCustomLineEdit.h:81
static TimeSpan ValueFromFloat(const fltp08 &value)
Definition QCustomLineEdit.h:85
static fltp08 ValueToFloat(const t_type &value)
Definition QCustomLineEdit.h:68
static t_type ValueFromFloat(const fltp08 &value)
Definition QCustomLineEdit.h:72
Definition QCustomLineEdit.h:49
static fltp08 ValueToFloat(const t_type &value)
Definition QCustomLineEdit.h:51
static t_type ValueFromFloat(const fltp08 &value)
Definition QCustomLineEdit.h:57
t_type getAs() const
Definition String.h:334
Definition StringStream.h:62
constexpr fltp08 elapsedSeconds() const
Definition TimeSpan.h:105
Definition TranslatedString.h:9
NDEVR_BASE_API const String & translation() const
Definition TranslatedString.cpp:104
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
UnitType
Definition Unit.h:10
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
@ INTERNAL_ANGLE
Definition Angle.h:67
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition BaseValues.hpp:272
Definition GenericOptions.h:53
Information about the object.
Definition ObjectInfo.h:56