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>
81 template<
class t_angle_type>
84 setUnitValue(value.template as<INTERNAL_ANGLE>());
88 template<
class t_angle_type = fltp08>
94 template<
class t_type>
99 m_validator.setTypeInfo(GetTypeInfo<t_type>());
106 template<
class t_type>
111 template<
class t_type>
114 setup<t_type>(title);
115 connect(
this, &QCustomLineEdit::editingFinishedSignal,
this, [
this, &resource]
119 if (!customValidator().unit().isNull())
122 resource.
set(getAs<t_type>());
126 resource.
set(getAs<t_type>());
129 if (m_resource_changed_listener)
130 delete m_resource_changed_listener;
135 if (!customValidator().unit().isNull())
138 setValue(resource.
get());
142 setValue(resource.
get());
149 template<
class t_type>
150 t_type
getAs(
bool allow_placeholder)
const
152 return getValue(allow_placeholder).getAs<t_type>();
154 template<
class t_type>
157 return getValue(m_allow_placeholder_as_value).getAs<t_type>();
159 template<
class t_type>
160 typename std::enable_if<ObjectInfo<t_type>::Number,
void>::type
setValue(
const t_type& input_value)
162 if (m_ignore_focus_lock || !hasUserFocus())
164 if(m_validator.unit().isNull())
165 m_current_value =
String(input_value);
166 else if(!
IsInvalid(m_validator.unitDimension()))
167 m_current_value = m_validator.unit()->toString(input_value,
false, 0,
Constant<uint04>::Max, 0,
false, m_validator.unitDimension());
169 m_current_value = m_validator.unit()->toString(input_value,
false, 0,
Constant<uint04>::Max, 0,
false);
170 QString input = m_current_value.getAs<QString>();
171 m_validator.fixup(input);
172 m_fixed_up_current_value =
String(input);
174 if (m_validator.validate(input, valid_pos))
175 m_last_valid = m_fixed_up_current_value;
179 template<
class t_type>
180 typename std::enable_if<!ObjectInfo<t_type>::Number,
void>::type
setValue(
const t_type& input_value)
182 if (m_ignore_focus_lock || !hasUserFocus())
185 if (m_current_value != val)
187 m_current_value = val;
189 m_validator.fixup(input);
190 m_fixed_up_current_value =
String(input);
192 if (m_validator.validate(input, valid_pos))
193 m_last_valid = m_fixed_up_current_value;
201 setValue(
String(input_value));
205 setValue(
String(input_value));
209 template<
class t_type>
212 setAllowPlaceholderAsValue(allow_placeholder_as_value);
213 QString input =
String(input_value).
getAs<QString>();
214 m_validator.fixup(input);
215 setPlaceholderText(input);
234 void paintEvent(QPaintEvent *event)
override;
236 virtual void mousePressEvent(QMouseEvent *e)
override;
237 virtual void focusInEvent(QFocusEvent *e)
override;
238 virtual void focusOutEvent(QFocusEvent *e)
override;
239 virtual void creatUnitLister();
241 void _setBackgroundColor(
const RGBColor& color);
257 String m_fixed_up_current_value;
266 fltp04 m_font_multiplier = 1.0f;
267 bool m_is_editable =
true;
268 bool m_auto_show_tooltip =
true;
269 bool m_suppress_focus_out =
false;
270 bool m_allow_placeholder_as_value =
true;
271 bool m_is_bold =
false;
272 bool m_ignore_focus_lock =
false;
273 bool m_has_edited =
false;
278 template<
class t_type,
bool is_number>
282 static fltp08 ValueToFloat(
const t_type& value)
285 lib_assert(
false,
"Trying to convert non-number");
288 static t_type ValueFromFloat(
const fltp08& value)
291 lib_assert(
false,
"Trying to convert non-number");
295 template<
class t_type>
296 class ResourceSetter<t_type, true>
299 static fltp08 ValueToFloat(
const t_type& value)
301 return cast<fltp08>(value);
303 static t_type ValueFromFloat(
const fltp08& value)
305 return cast<t_type>(value);
309 class ResourceSetter<TimeSpan, ObjectInfo<TimeSpan>::Number>
312 static fltp08 ValueToFloat(
const TimeSpan& value)
314 return value.elapsedSeconds();
316 static TimeSpan ValueFromFloat(
const fltp08& value)
318 return TimeSpan(value);
322 class ResourceSetter<Angle<
fltp08>, ObjectInfo<Angle<
fltp08>>::Number>
325 static fltp08 ValueToFloat(
const Angle<fltp08>& value)
327 return value.internal<
false>();
329 static Angle<fltp08> ValueFromFloat(
const fltp08& value)
331 return Angle<fltp08>(INTERNAL_ANGLE, value);
335 class ResourceSetter<Angle<
sint04>, ObjectInfo<Angle<
sint04>>::Number>
338 static fltp08 ValueToFloat(
const Angle<sint04>& value)
340 return value.internal<
false>();
342 static Angle<sint04> ValueFromFloat(
const fltp08& value)
344 return Angle<sint04>(INTERNAL_ANGLE, value);
#define UNUSED(expr)
Definition BaseValues.hpp:409
#define lib_assert(expression, message)
Definition LibAssert.h:61
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
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
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
A compact way to present a list of options to the user.
Definition QCustomCombobox.h:53
A line edit allows users to enter and edit a single line of plain text with useful editing functions,...
Definition QCustomLineEdit.h:56
bool isEditable() const
Definition QCustomLineEdit.h:72
void inputHintChangedSignal()
void setup(const TranslatedString &title)
Definition QCustomLineEdit.h:95
QCustomLineEdit(const QString &value, QWidget *parent=Q_NULLPTR)
RGBColor backgroundColor() const
QSize minimumSizeHint() const override
void setUnitType(UnitCategory unit, uint01 dimension=Constant< uint01 >::Invalid)
TranslatedString m_tooltip
Definition QCustomLineEdit.h:254
const TranslatedString & inputHint() const
void setStep(fltp08 step)
void forceValue(const String &units)
QSize sizeHint() const override
t_type getAs(bool allow_placeholder) const
Definition QCustomLineEdit.h:150
void setInputHint(const TranslatedString &hint)
QCustomLineEdit(QWidget *parent=Q_NULLPTR)
void setCustomUnit(const String &unit, UnitCategory fallback_unit, uint01 dimension=Constant< uint01 >::Invalid)
const QCustomValidator & customValidator() const
fltp08 getUnitValue(bool allow_placeholder=true) const
void clearBackgroundColor()
bool event(QEvent *event) override
void setEditable(bool editable)
void setPlaceholderText(const QString &value)
void setup(const TranslatedString &title, Resource< t_type > &resource)
Definition QCustomLineEdit.h:112
TranslatedString m_title
Definition QCustomLineEdit.h:253
bool hasUserFocus() const
String getValue(bool allow_placeholder) const
void setPlaceHolderUnitValue(fltp08 value)
void setToolTip(const TranslatedString &tooltip)
void setPlaceholderValue(const TranslatedString &input_value, bool allow_placeholder_as_value=true)
std::enable_if< ObjectInfo< t_type >::Number, void >::type setValue(const t_type &input_value)
Definition QCustomLineEdit.h:160
void startUserEdit(bool select_all=true)
void setUnitValue(Angle< t_angle_type > value)
Definition QCustomLineEdit.h:82
void setBackgroundColor(const RGBColor &color)
void setValue(const Angle< sint04 > &input_value)
Definition QCustomLineEdit.h:199
void setAsKeyboardFocus()
void setup(GenericOption &option)
void setAllowPlaceholderAsValue(bool allow)
void setAutoShowTooltip(bool auto_show_tooltip)
Definition QCustomLineEdit.h:226
void setPlaceholderValue(const t_type &input_value, bool allow_placeholder_as_value=true)
Definition QCustomLineEdit.h:210
void setup(const TranslatedString &title, Resource< String > &resource)
t_type getAs() const
Definition QCustomLineEdit.h:155
void wheelEvent(QWheelEvent *event) override
void setValue(const TimeSpan &input_value)
virtual void setTitle(const TranslatedString &title)
void setup(const TranslatedString &title, UnitCategory unit_type, uint01 dim=Constant< uint01 >::Invalid)
void setUnitValue(fltp08 value)
QCustomValidator & customValidator()
void setConstantUnit(const ConstPointer< Unit > &unit, uint01 dimension=Constant< uint01 >::Invalid)
Angle< t_angle_type > getUnitAngle(bool allow_placeholder=true) const
Definition QCustomLineEdit.h:89
void setup(ApplicationOption< t_type > &option)
Definition QCustomLineEdit.h:107
std::enable_if<!ObjectInfo< t_type >::Number, void >::type setValue(const t_type &input_value)
Definition QCustomLineEdit.h:180
void setValue(const Angle< fltp08 > &input_value)
Definition QCustomLineEdit.h:203
void editingFinishedSignal()
void setup(const TranslatedString &title, const TypeInfo &type)
void setBold(bool is_bold)
void setFontMultiplier(fltp04 font_multiplier)
Responsible on most user input fields for correcting the input when possible or allerting the user th...
Definition QCustomValidator.h:47
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:54
ResourceListener * addListener(ResourceListener *listener) const
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
const T & get() const
Definition Resource.h:71
void set(const T &info, bool check_equal=true)
Definition Resource.h:53
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Logic for reading or writing to a string or a user friendly, TranslatedString.
Definition StringStream.h:230
Stores a time span, or difference between two times, with an optional start time.
Definition TimeSpan.h:46
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
const String & translation() const
Stores information about a type, relevant for certain templated functions. To get information about a...
Definition TypeInfo.h:43
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
@ INTERNAL_ANGLE
Definition Angle.h:59
UnitCategory
A category of unit describing what it relates to. Any category can have some number of units defined ...
Definition Unit.h:14
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Stores a generic option of any type as well as some information about how the user might interact wit...
Definition GenericOptions.h:57
Information about the object.
Definition ObjectInfo.h:54