diff --git a/UI/CMakeLists.txt b/UI/CMakeLists.txt index b83657c..3f282a1 100644 --- a/UI/CMakeLists.txt +++ b/UI/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(UI) +add_library(UI STATIC) find_package(Qt6 REQUIRED COMPONENTS Core SerialBus) diff --git a/UI/UI_button.cpp b/UI/UI_button.cpp index eae06c4..37cde3d 100644 --- a/UI/UI_button.cpp +++ b/UI/UI_button.cpp @@ -23,5 +23,5 @@ json UI_button::to_json(size_t id) const void UI_button::click() { - emit on_click(); + emit clicked(); } diff --git a/UI/UI_button.hpp b/UI/UI_button.hpp index 5908a9a..40a1aae 100644 --- a/UI/UI_button.hpp +++ b/UI/UI_button.hpp @@ -17,5 +17,5 @@ class UI_button : public UI_item void click() override; signals: - void on_click(); + void clicked(); }; diff --git a/UI/UI_combobox.cpp b/UI/UI_combobox.cpp index 1cd8f5b..d5ae25a 100644 --- a/UI/UI_combobox.cpp +++ b/UI/UI_combobox.cpp @@ -21,7 +21,7 @@ void UI_combobox::set_selected(size_t selected) return; m_selected = selected; emit value_changed(); - emit on_change(selected_text()); + emit changed(selected_text()); } void UI_combobox::set_selected(std::string selected) diff --git a/UI/UI_combobox.hpp b/UI/UI_combobox.hpp index 2524ca6..230c702 100644 --- a/UI/UI_combobox.hpp +++ b/UI/UI_combobox.hpp @@ -23,7 +23,7 @@ class UI_combobox : public UI_x_boxes void from_json(const json &j) override; json to_json(size_t id) const override; signals: - void on_change(std::string selected); + void changed(std::string selected); private: size_t m_selected; diff --git a/UI/UI_dial.cpp b/UI/UI_dial.cpp index 4640610..19a8a28 100644 --- a/UI/UI_dial.cpp +++ b/UI/UI_dial.cpp @@ -6,12 +6,22 @@ UI_dial::UI_dial(std::string text, std::string unit, Color fg_color, Color bg_co { } +UI_dial::UI_dial(std::string text, std::string unit, double min, double max, double value, QObject *parent) + : UI_dial(text, unit, Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_dial::UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent) : UI_dial(text, "", fg_color, bg_color, min, max, value, parent) { } +UI_dial::UI_dial(std::string text, double min, double max, double value, QObject *parent) + : UI_dial(text, "", Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_dial::UI_dial(const json &j, QObject *parent) : UI_item(UI_DIAL_TYPE, parent) { from_json(j); diff --git a/UI/UI_dial.hpp b/UI/UI_dial.hpp index f74c2a4..638f561 100644 --- a/UI/UI_dial.hpp +++ b/UI/UI_dial.hpp @@ -9,8 +9,10 @@ class UI_dial : public UI_item public: UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_dial(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_dial(std::string text, double min, double max, double value, QObject *parent = nullptr); UI_dial(const json &j, QObject *parent = nullptr); void set_value(double value) override; diff --git a/UI/UI_item.cpp b/UI/UI_item.cpp index 5897d97..6eee9c1 100644 --- a/UI/UI_item.cpp +++ b/UI/UI_item.cpp @@ -44,6 +44,12 @@ void UI_item::set_text(std::string text) } } +void UI_item::append_text(std::string text) +{ + m_text.append(text); + emit value_changed(); +} + std::string UI_item::text() const { return m_text; diff --git a/UI/UI_item.hpp b/UI/UI_item.hpp index 1d8a534..753fab9 100644 --- a/UI/UI_item.hpp +++ b/UI/UI_item.hpp @@ -26,6 +26,7 @@ class UI_item : public QObject bool is_type(json j); virtual void set_text(std::string text); + void append_text(std::string text); std::string text() const; void set_text_size(uint8_t text_size); diff --git a/UI/UI_led.cpp b/UI/UI_led.cpp index efbb929..b291dd0 100644 --- a/UI/UI_led.cpp +++ b/UI/UI_led.cpp @@ -14,9 +14,10 @@ UI_led::UI_led(const json &j, QObject *parent) : UI_item(UI_LED_TYPE, parent) from_json(j); } -void UI_led::set_led(bool state, Color on, Color off) +bool UI_led::set_led(bool state, Color on, Color off) { set_bg_color(state ? on : off); + return state; } void UI_led::from_json(const json &j) diff --git a/UI/UI_led.hpp b/UI/UI_led.hpp index 5c32b11..b9ac3e2 100644 --- a/UI/UI_led.hpp +++ b/UI/UI_led.hpp @@ -12,7 +12,7 @@ class UI_led : public UI_item UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); UI_led(const json &j, QObject *parent = nullptr); - void set_led(bool state, Color on, Color off); + bool set_led(bool state, Color on, Color off); void from_json(const json &j) override; json to_json(size_t id) const override; diff --git a/UI/UI_slider.cpp b/UI/UI_slider.cpp index 5b3d35e..6afc927 100644 --- a/UI/UI_slider.cpp +++ b/UI/UI_slider.cpp @@ -7,12 +7,22 @@ UI_slider::UI_slider(std::string text, std::string unit, Color fg_color, Color b { } +UI_slider::UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent) + : UI_slider(text, unit, Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_slider::UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent) : UI_slider(text, "", fg_color, bg_color, min, max, value, parent) { } +UI_slider::UI_slider(std::string text, double min, double max, double value, QObject *parent) + : UI_slider(text, "", Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_slider::UI_slider(const json &j, QObject *parent) : UI_item(UI_SLIDER_TYPE, parent) { from_json(j); diff --git a/UI/UI_slider.hpp b/UI/UI_slider.hpp index 7be0fb6..2e47c58 100644 --- a/UI/UI_slider.hpp +++ b/UI/UI_slider.hpp @@ -9,8 +9,10 @@ class UI_slider : public UI_item public: UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_slider(std::string text, double min, double max, double value, QObject *parent = nullptr); UI_slider(const json &j, QObject *parent = nullptr); void set_value(double value) override; diff --git a/UI/UI_thermo.cpp b/UI/UI_thermo.cpp index ded7288..882c385 100644 --- a/UI/UI_thermo.cpp +++ b/UI/UI_thermo.cpp @@ -7,12 +7,22 @@ UI_thermo::UI_thermo(std::string text, std::string unit, Color fg_color, Color b { } +UI_thermo::UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent) + : UI_thermo(text, unit, Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_thermo::UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent) : UI_thermo(text, "", fg_color, bg_color, min, max, value, parent) { } +UI_thermo::UI_thermo(std::string text, double min, double max, double value, QObject *parent) + : UI_thermo(text, "", Color::Default, Color::Default, min, max, value, parent) +{ +} + UI_thermo::UI_thermo(const json &j, QObject *parent) : UI_item(UI_THERMO_TYPE, parent) { from_json(j); diff --git a/UI/UI_thermo.hpp b/UI/UI_thermo.hpp index 0735303..27ccdba 100644 --- a/UI/UI_thermo.hpp +++ b/UI/UI_thermo.hpp @@ -10,8 +10,10 @@ class UI_thermo : public UI_item public: UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + UI_thermo(std::string text, double min, double max, double value, QObject *parent = nullptr); UI_thermo(const json &j, QObject *parent = nullptr); void set_value(double value) override; diff --git a/server/simulators/test_sim.cpp b/server/simulators/test_sim.cpp index d9af221..ec303cf 100644 --- a/server/simulators/test_sim.cpp +++ b/server/simulators/test_sim.cpp @@ -24,7 +24,7 @@ Test_Sim::Test_Sim(CAN_Wrapper *can_wrapper, QObject *parent) this->push_ui_item(&this->m_led); this->push_ui_item(&this->m_checkbox); - QObject::connect(&m_button, &UI_button::on_click, this, [=, this] { button_clicked(&m_button); }); + QObject::connect(&m_button, &UI_button::clicked, this, [=, this] { button_clicked(&m_button); }); QObject::connect(&m_slider, &UI_slider::on_change, this, [=, this](double value) { slider_changed(&m_slider, value); }); }