Remove Text_size
Add setup_item to configure if an item uses text, fg color and bg color.
This commit is contained in:
2026-02-14 14:32:08 +01:00
parent ef4df1718b
commit efcb183682
19 changed files with 78 additions and 76 deletions
+3 -2
View File
@@ -12,13 +12,14 @@ template <class T> T ByteArrayToStdArray(const QByteArray &byteArray)
return stdArray;
}
UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_CAN_TYPE, "", 12, fg_color, bg_color, parent)
UI_can::UI_can(Color fg_color, Color bg_color, QObject *parent) : UI_item(UI_CAN_TYPE, "", fg_color, bg_color, parent)
{
setup_item(false, true, true);
}
UI_can::UI_can(const json &j, QObject *parent) : UI_item(UI_CAN_TYPE, parent)
{
setup_item(false, true, true);
from_json(j);
}
+1 -1
View File
@@ -1,7 +1,7 @@
#include "ui_button.hpp"
UI_button::UI_button(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parent)
: UI_item(UI_BUTTON_TYPE, text, fg_color, bg_color, parent)
{
}
+1 -1
View File
@@ -5,7 +5,7 @@ UI_checkbox::UI_checkbox(QObject *parent) : UI_item(UI_CHECKBOX_TYPE, parent), m
}
UI_checkbox::UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_CHECKBOX_TYPE, text, 0, fg_color, bg_color, parent), m_checked(false)
: UI_item(UI_CHECKBOX_TYPE, text, fg_color, bg_color, parent), m_checked(false)
{
}
+4 -1
View File
@@ -2,16 +2,19 @@
UI_combobox::UI_combobox(QObject *parent) : UI_item(UI_COMBOBOX_TYPE, parent), m_options()
{
setup_item(false, true, true);
}
UI_combobox::UI_combobox(Color fg_color, Color bg_color, std::vector<std::string> options, size_t selected,
QObject *parent)
: UI_item(UI_COMBOBOX_TYPE, "", 12, fg_color, bg_color, parent), m_options(options), m_selected(selected)
: UI_item(UI_COMBOBOX_TYPE, "", fg_color, bg_color, parent), m_options(options), m_selected(selected)
{
setup_item(false, true, true);
}
UI_combobox::UI_combobox(const json &j, QObject *parent) : UI_item(UI_COMBOBOX_TYPE, parent)
{
setup_item(false, true, true);
from_json(j);
}
+1 -1
View File
@@ -2,7 +2,7 @@
UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_DIAL_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
: UI_item(UI_DIAL_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
{
}
+2
View File
@@ -2,11 +2,13 @@
UI_double_spinbox::UI_double_spinbox(QObject *parent) : UI_item(UI_DOUBLE_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
}
UI_double_spinbox::UI_double_spinbox(double min, double max, double value, QObject *parent)
: UI_item(UI_DOUBLE_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
m_min = min;
m_max = max;
m_value = value;
+2
View File
@@ -2,11 +2,13 @@
UI_hex_spinbox::UI_hex_spinbox(QObject *parent) : UI_item(UI_HEX_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
}
UI_hex_spinbox::UI_hex_spinbox(double min, double max, double value, QObject *parent)
: UI_item(UI_HEX_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
m_min = min;
m_max = max;
m_value = value;
+41 -40
View File
@@ -1,14 +1,14 @@
#include "ui_item.hpp"
UI_item::UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject *parent)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color),
m_bg_color(bg_color), enabled(true), visible(true)
UI_item::UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(text), m_fg_color(fg_color), m_bg_color(bg_color),
m_enabled(true), m_visible(true)
{
}
UI_item::UI_item(std::string type, QObject *parent)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Default),
m_bg_color(Color::Default), enabled(true), visible(true)
: QObject(parent), m_id((size_t)-1), m_type(type), m_text(""), m_fg_color(Color::Default),
m_bg_color(Color::Default), m_enabled(true), m_visible(true)
{
}
@@ -55,20 +55,6 @@ std::string UI_item::text() const
return m_text;
}
void UI_item::set_text_size(uint8_t text_size)
{
if (this->m_text_size != text_size)
{
this->m_text_size = text_size;
emit ui_changed();
}
}
uint8_t UI_item::text_size() const
{
return m_text_size;
}
void UI_item::set_fg_color(Color fg_color)
{
if (this->m_fg_color != fg_color)
@@ -99,30 +85,30 @@ Color UI_item::bg_color() const
void UI_item::set_enabled(bool enabled)
{
if (this->enabled != enabled)
if (this->m_enabled != enabled)
{
this->enabled = enabled;
this->m_enabled = enabled;
emit ui_changed();
}
}
bool UI_item::is_enabled() const
{
return enabled;
return m_enabled;
}
void UI_item::set_visible(bool visible)
{
if (this->visible != visible)
if (this->m_visible != visible)
{
this->visible = visible;
this->m_visible = visible;
emit ui_changed();
}
}
bool UI_item::is_visible() const
{
return visible;
return m_visible;
}
void UI_item::from_json(const json &j)
@@ -130,16 +116,22 @@ void UI_item::from_json(const json &j)
if (!is_type(j))
return;
j.at("id").get_to(m_id);
j.at("text").get_to(m_text);
j.at("text_size").get_to(m_text_size);
if (j.contains("text"))
j.at("text").get_to(m_text);
std::string color;
j.at("fg_color").get_to(color);
m_fg_color = Color(color);
color.clear();
j.at("bg_color").get_to(color);
m_bg_color = Color(color);
j.at("enabled").get_to(enabled);
j.at("visible").get_to(visible);
if (j.contains("fg_color"))
{
j.at("fg_color").get_to(color);
m_fg_color = Color(color);
color.clear();
}
if (j.contains("bg_color"))
{
j.at("bg_color").get_to(color);
m_bg_color = Color(color);
}
j.at("enabled").get_to(m_enabled);
j.at("visible").get_to(m_visible);
}
json UI_item::to_json(size_t id) const
@@ -147,12 +139,14 @@ json UI_item::to_json(size_t id) const
json j;
j["id"] = id;
j["type"] = m_type;
j["text"] = m_text;
j["text_size"] = m_text_size;
j["fg_color"] = m_fg_color.to_hex();
j["bg_color"] = m_bg_color.to_hex();
j["enabled"] = enabled;
j["visible"] = visible;
if (m_text_enabled)
j["text"] = m_text;
if (m_fg_color_enabled)
j["fg_color"] = m_fg_color.to_hex();
if (m_bg_color_enabled)
j["bg_color"] = m_bg_color.to_hex();
j["enabled"] = m_enabled;
j["visible"] = m_visible;
return j;
}
@@ -177,3 +171,10 @@ void UI_item::can_send(uint32_t id, uint8_t dlc, std::array<uint8_t, 8> payload)
void UI_item::can_clear()
{
}
void UI_item::setup_item(bool text, bool fg_color, bool bg_color)
{
m_text_enabled = text;
m_fg_color_enabled = fg_color;
m_bg_color_enabled = bg_color;
}
+8 -8
View File
@@ -15,8 +15,7 @@ class UI_item : public QObject
Q_OBJECT
public:
explicit UI_item(std::string type, QObject *parent = nullptr);
explicit UI_item(std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color,
QObject *parent = nullptr);
explicit UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr);
explicit UI_item(const json &j, QObject *parent = nullptr);
~UI_item();
@@ -27,9 +26,6 @@ class UI_item : public QObject
void append_text(std::string text);
std::string text() const;
void set_text_size(uint8_t text_size);
uint8_t text_size() const;
void set_fg_color(Color fg_color);
Color fg_color() const;
@@ -56,12 +52,16 @@ class UI_item : public QObject
void ui_changed();
protected:
void setup_item(bool text, bool fg_color, bool bg_color);
size_t m_id;
std::string m_type;
std::string m_text;
uint8_t m_text_size;
bool m_text_enabled = true;
Color m_fg_color;
bool m_fg_color_enabled = true;
Color m_bg_color;
bool enabled;
bool visible;
bool m_bg_color_enabled = true;
bool m_enabled;
bool m_visible;
};
+1 -1
View File
@@ -1,7 +1,7 @@
#include "ui_label.hpp"
UI_label::UI_label(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_LABEL_TYPE, text, 12, fg_color, bg_color, parent)
: UI_item(UI_LABEL_TYPE, text, fg_color, bg_color, parent)
{
}
+2 -2
View File
@@ -1,11 +1,11 @@
#include "ui_led.hpp"
UI_led::UI_led(QObject *parent) : UI_item(UI_LED_TYPE, "", 12, Color::Default, Color::Default, parent)
UI_led::UI_led(QObject *parent) : UI_item(UI_LED_TYPE, "", Color::Default, Color::Default, parent)
{
}
UI_led::UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_LED_TYPE, text, 12, fg_color, bg_color, parent)
: UI_item(UI_LED_TYPE, text, fg_color, bg_color, parent)
{
}
+1 -2
View File
@@ -2,8 +2,7 @@
UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
m_unit(unit)
: UI_item(UI_SLIDER_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
{
}
+2
View File
@@ -2,10 +2,12 @@
UI_spinbox::UI_spinbox(QObject *parent) : UI_item(UI_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
}
UI_spinbox::UI_spinbox(double min, double max, double value, QObject *parent) : UI_item(UI_SPINBOX_TYPE, parent)
{
setup_item(false, false, false);
m_min = min;
m_max = max;
m_value = value;
+2
View File
@@ -2,11 +2,13 @@
UI_tab_widget::UI_tab_widget(QObject *parent) : UI_item(UI_TAB_WIDGET_TYPE, parent)
{
setup_item(false, false, false);
}
UI_tab_widget::UI_tab_widget(std::vector<std::string> tab_names, size_t selected, QObject *parent)
: UI_item(UI_TAB_WIDGET_TYPE, parent), m_selected_tab(selected), m_tab_names(tab_names)
{
setup_item(false, false, false);
m_tab_visible.resize(m_tab_names.size(), true);
}
+2
View File
@@ -2,6 +2,7 @@
UI_table::UI_table(QObject *parent) : UI_item(UI_TABLE_TYPE, parent), m_row_count(0), m_column_count(0)
{
setup_item(false, false, false);
}
UI_table::UI_table(size_t row_count, size_t column_count, std::vector<std::string> row_labels,
@@ -9,6 +10,7 @@ UI_table::UI_table(size_t row_count, size_t column_count, std::vector<std::strin
: UI_item(UI_TABLE_TYPE, parent), m_row_count(row_count), m_column_count(column_count), m_row_labels(row_labels),
m_column_labels(column_labels), m_valid(), m_table()
{
setup_item(false, false, false);
m_table.resize(m_column_count * m_row_count);
m_valid.resize(m_column_count * m_row_count);
}
+1 -1
View File
@@ -1,7 +1,7 @@
#include "ui_textbox.hpp"
UI_textbox::UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parent)
: UI_item(UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color, parent), m_hint(hint)
: UI_item(UI_TEXTBOX_TYPE, "", fg_color, bg_color, parent), m_hint(hint)
{
}
+1 -2
View File
@@ -2,8 +2,7 @@
UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max,
double value, QObject *parent)
: UI_item(UI_THERMO_TYPE, text, 12, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value),
m_unit(unit)
: UI_item(UI_THERMO_TYPE, text, fg_color, bg_color, parent), m_min(min), m_max(max), m_value(value), m_unit(unit)
{
}