Move to Qt

Everything seems to be working
Only timer is not moved over
This commit is contained in:
2024-09-12 16:59:54 +02:00
parent fc181726b9
commit 9eef1fc3ff
39 changed files with 399 additions and 501 deletions
+22 -1
View File
@@ -5,6 +5,15 @@ include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
FetchContent_MakeAvailable(json)
find_package(Qt6 REQUIRED COMPONENTS Core)
set_target_properties(
UI
PROPERTIES
AUTOMOC ON
AUTORCC ON
)
target_compile_options(UI PRIVATE $<$<CONFIG:Debug>:
-Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion
>)
@@ -12,16 +21,27 @@ target_compile_options(UI PRIVATE $<$<CONFIG:Debug>:
target_sources(UI
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/UI_item.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_item.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_button.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_button.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_checkbox.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_combobox.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_combobox.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_dial.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_dial.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_label.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_label.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_led.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_led.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_slider.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_slider.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_textbox.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_textbox.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_thermo.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_thermo.hpp
${CMAKE_CURRENT_LIST_DIR}/UI_x_boxes.cpp
${CMAKE_CURRENT_LIST_DIR}/UI_x_boxes.hpp
)
target_include_directories(UI
@@ -36,4 +56,5 @@ target_link_libraries(UI
PUBLIC
Color
nlohmann_json::nlohmann_json
)
Qt::Core
)
+6 -10
View File
@@ -1,13 +1,12 @@
#include "UI_button.hpp"
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color,
std::function<void(std::string)> on_click)
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color)
UI_button::UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent)
: UI_item(id, UI_BUTTON_TYPE, text, 12, fg_color, bg_color, parrent)
{
this->m_on_click = on_click;
}
UI_button::UI_button(const json &j) : UI_item(UI_BUTTON_TYPE), m_on_click(nullptr)
UI_button::UI_button(const json &j, QObject* parrent) : UI_item(UI_BUTTON_TYPE, parrent)
{
from_json(j);
}
@@ -23,10 +22,7 @@ json UI_button::to_json() const
return j;
}
void UI_button::click() const
void UI_button::click()
{
if (m_on_click != nullptr)
{
std::thread([this] { m_on_click(m_id); }).detach();
}
emit on_click(m_id);
}
+7 -7
View File
@@ -6,16 +6,16 @@
class UI_button : public UI_item
{
Q_OBJECT
public:
UI_button(std::string id, std::string text, Color fg_color, Color bg_color,
std::function<void(std::string)> on_click = nullptr);
UI_button(const json &j);
UI_button(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent = nullptr);
UI_button(const json &j, QObject* parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
void click() const override;
void click() override;
private:
std::function<void(std::string)> m_on_click = nullptr;
};
signals:
void on_click(std::string id);
};
+6 -9
View File
@@ -1,13 +1,12 @@
#include "UI_checkbox.hpp"
UI_checkbox::UI_checkbox() : UI_x_boxes(UI_CHECKBOX_TYPE), m_selected(), m_on_change(nullptr)
UI_checkbox::UI_checkbox(QObject* parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected()
{
}
UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options,
std::function<void(std::string, std::vector<std::string>)> on_change)
: UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options), m_selected(), m_on_change(on_change)
std::vector<std::string> options, QObject* parrent)
: UI_x_boxes(id, UI_CHECKBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected()
{
for (size_t i = 0; i < m_options.size(); i++)
{
@@ -15,7 +14,7 @@ UI_checkbox::UI_checkbox(std::string id, std::string text, Color fg_color, Color
}
}
UI_checkbox::UI_checkbox(const json &j) : UI_x_boxes(UI_CHECKBOX_TYPE), m_selected(), m_on_change(nullptr)
UI_checkbox::UI_checkbox(const json &j, QObject* parrent) : UI_x_boxes(UI_CHECKBOX_TYPE, parrent), m_selected()
{
from_json(j);
}
@@ -25,10 +24,8 @@ void UI_checkbox::toggle_selected(size_t selected)
if (selected >= m_options.size())
return;
m_selected[selected] = !m_selected[selected];
if (m_on_change != nullptr)
{
std::thread([this] { m_on_change(m_id, selected_text()); }).detach();
}
emit value_changed();
emit on_change(m_id, selected_text()[selected]);
}
void UI_checkbox::toggle_selected(std::string selected)
+8 -7
View File
@@ -7,11 +7,11 @@
class UI_checkbox : public UI_x_boxes
{
Q_OBJECT
public:
UI_checkbox();
UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
std::function<void(std::string, std::vector<std::string>)> on_change = nullptr);
UI_checkbox(const json &j);
UI_checkbox(QObject* parrent = nullptr);
UI_checkbox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options, QObject* parrent = nullptr);
UI_checkbox(const json &j, QObject* parrent = nullptr);
void toggle_selected(size_t selected);
void toggle_selected(std::string selected);
@@ -21,8 +21,9 @@ class UI_checkbox : public UI_x_boxes
void from_json(const json &j) override;
json to_json() const override;
signals:
void on_change(std::string, std::string);
private:
std::vector<bool> m_selected;
std::function<void(std::string, std::vector<std::string>)> m_on_change;
};
};
+7 -10
View File
@@ -1,17 +1,16 @@
#include "UI_combobox.hpp"
UI_combobox::UI_combobox() : UI_x_boxes(UI_COMBOBOX_TYPE)
UI_combobox::UI_combobox(QObject* parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent)
{
}
UI_combobox::UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options, size_t selected,
std::function<void(std::string, std::string)> on_change)
: UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options), m_selected(selected), m_on_change(on_change)
std::vector<std::string> options, size_t selected, QObject* parrent)
: UI_x_boxes(id, UI_COMBOBOX_TYPE, text, fg_color, bg_color, options, parrent), m_selected(selected)
{
}
UI_combobox::UI_combobox(const json &j) : UI_x_boxes(UI_COMBOBOX_TYPE), m_on_change(nullptr)
UI_combobox::UI_combobox(const json &j, QObject* parrent) : UI_x_boxes(UI_COMBOBOX_TYPE, parrent)
{
from_json(j);
}
@@ -21,10 +20,8 @@ void UI_combobox::set_selected(size_t selected)
if (selected == m_selected)
return;
m_selected = selected;
if (m_on_change != nullptr)
{
std::thread([this] { m_on_change(m_id, selected_text()); }).detach();
}
emit value_changed();
emit on_change(m_id, selected_text());
}
void UI_combobox::set_selected(std::string selected)
@@ -68,4 +65,4 @@ json UI_combobox::to_json() const
json j = UI_x_boxes::to_json();
j["selected"] = m_options[m_selected];
return j;
}
}
+7 -7
View File
@@ -8,11 +8,12 @@
class UI_combobox : public UI_x_boxes
{
Q_OBJECT
public:
UI_combobox();
UI_combobox(QObject* parrent = nullptr);
UI_combobox(std::string id, std::string text, Color fg_color, Color bg_color, std::vector<std::string> options,
size_t selected = 0, std::function<void(std::string, std::string)> on_change = nullptr);
UI_combobox(const json &j);
size_t selected = 0, QObject* parrent = nullptr);
UI_combobox(const json &j, QObject* parrent = nullptr);
void set_selected(size_t selected);
void set_selected(std::string selected) override;
@@ -21,9 +22,8 @@ class UI_combobox : public UI_x_boxes
void from_json(const json &j) override;
json to_json() const override;
signals:
void on_change(std::string id, std::string selected);
private:
size_t m_selected;
std::function<void(std::string, std::string)> m_on_change;
};
};
+5 -4
View File
@@ -1,11 +1,11 @@
#include "UI_dial.hpp"
UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value)
: UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value)
UI_dial::UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent)
: UI_item(id, UI_DIAL_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
}
UI_dial::UI_dial(const json &j) : UI_item(UI_DIAL_TYPE)
UI_dial::UI_dial(const json &j, QObject* parrent) : UI_item(UI_DIAL_TYPE, parrent)
{
from_json(j);
}
@@ -18,6 +18,7 @@ void UI_dial::set_value(double value)
return;
this->m_value = value;
emit value_changed();
}
double UI_dial::value() const
@@ -51,4 +52,4 @@ json UI_dial::to_json() const
j["max"] = this->m_max;
j["value"] = this->m_value;
return j;
}
}
+4 -3
View File
@@ -5,9 +5,10 @@
class UI_dial : public UI_item
{
Q_OBJECT
public:
UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value);
UI_dial(const json &j);
UI_dial(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
UI_dial(const json &j, QObject* parrent = nullptr);
void set_value(double value) override;
double value() const;
@@ -22,4 +23,4 @@ class UI_dial : public UI_item
double m_min;
double m_max;
double m_value;
};
};
+28 -9
View File
@@ -1,22 +1,29 @@
#include "UI_item.hpp"
UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color)
: m_id(id), m_type(type), m_text(text), m_text_size(text_size), m_fg_color(fg_color), m_bg_color(bg_color),
UI_item::UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject* parrent)
: QObject(parrent),
m_id(id), 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)
: m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), m_bg_color(Color::White),
UI_item::UI_item(std::string type, QObject* parrent)
: QObject(parrent),
m_id(""), m_type(type), m_text(""), m_text_size(12), m_fg_color(Color::Black), m_bg_color(Color::White),
enabled(true), visible(true)
{
}
UI_item::UI_item(const json &j)
UI_item::UI_item(const json &j, QObject* parrent) :
QObject(parrent)
{
from_json(j);
}
UI_item::~UI_item()
{
}
std::string UI_item::id() const
{
return m_id;
@@ -41,6 +48,7 @@ void UI_item::set_text(std::string text)
if (this->m_text != text)
{
this->m_text = text;
emit value_changed();
}
}
@@ -54,6 +62,7 @@ void UI_item::set_text_size(uint8_t text_size)
if (this->m_text_size != text_size)
{
this->m_text_size = text_size;
emit value_changed();
}
}
@@ -67,6 +76,7 @@ void UI_item::set_fg_color(Color fg_color)
if (this->m_fg_color != fg_color)
{
this->m_fg_color = fg_color;
emit value_changed();
}
}
@@ -80,6 +90,7 @@ void UI_item::set_bg_color(Color bg_color)
if (this->m_bg_color != bg_color)
{
this->m_bg_color = bg_color;
emit value_changed();
}
}
@@ -90,7 +101,11 @@ Color UI_item::bg_color() const
void UI_item::set_enabled(bool enabled)
{
this->enabled = enabled;
if (this->enabled != enabled)
{
this->enabled = enabled;
emit value_changed();
}
}
bool UI_item::is_enabled() const
@@ -100,7 +115,11 @@ bool UI_item::is_enabled() const
void UI_item::set_visible(bool visible)
{
this->visible = visible;
if (this->visible != visible)
{
this->visible = visible;
emit value_changed();
}
}
bool UI_item::is_visible() const
@@ -139,7 +158,7 @@ json UI_item::to_json() const
return j;
}
void UI_item::click() const {};
void UI_item::click() {};
void UI_item::set_selected(std::string selected)
{
@@ -148,4 +167,4 @@ void UI_item::set_selected(std::string selected)
void UI_item::set_value(double value)
{
UNUSED(value);
};
};
+13 -6
View File
@@ -5,16 +5,20 @@
#include <nlohmann/json.hpp>
#include <string>
#include <thread>
#include <QObject>
using json = nlohmann::json;
#define UNUSED(x) (void)(x)
class UI_item
class UI_item : public QObject
{
Q_OBJECT
public:
UI_item(std::string type);
UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color);
UI_item(const json &j);
explicit UI_item(std::string type, QObject* parrent = nullptr);
explicit UI_item(std::string id, std::string type, std::string text, uint8_t text_size, Color fg_color, Color bg_color, QObject* parrent = nullptr);
explicit UI_item(const json &j, QObject* parrent = nullptr);
~UI_item();
std::string id() const;
std::string type() const;
@@ -42,10 +46,13 @@ class UI_item
virtual json to_json() const;
virtual void click() const;
virtual void click();
virtual void set_selected(std::string selected);
virtual void set_value(double value);
signals:
void value_changed();
protected:
std::string m_id;
std::string m_type;
@@ -55,4 +62,4 @@ class UI_item
Color m_bg_color;
bool enabled;
bool visible;
};
};
+4 -4
View File
@@ -1,11 +1,11 @@
#include "UI_label.hpp"
UI_label::UI_label(std::string id, std::string text, Color fg_color, Color bg_color)
: UI_item(id, UI_LABEL_TYPE, text, 12, fg_color, bg_color)
UI_label::UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent)
: UI_item(id, UI_LABEL_TYPE, text, 12, fg_color, bg_color, parrent)
{
}
UI_label::UI_label(const json &j) : UI_item(UI_LABEL_TYPE)
UI_label::UI_label(const json &j, QObject* parrent) : UI_item(UI_LABEL_TYPE, parrent)
{
from_json(j);
}
@@ -18,4 +18,4 @@ void UI_label::from_json(const json &j)
json UI_label::to_json() const
{
return UI_item::to_json();
}
}
+4 -3
View File
@@ -6,10 +6,11 @@
class UI_label : public UI_item
{
Q_OBJECT
public:
UI_label(std::string id, std::string text, Color fg_color, Color bg_color);
UI_label(const json &j);
UI_label(std::string id, std::string text, Color fg_color, Color bg_color, QObject* parrent = nullptr);
UI_label(const json &j, QObject* parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
};
};
+9 -5
View File
@@ -1,11 +1,11 @@
#include "UI_led.hpp"
UI_led::UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color)
: UI_item(id, UI_LED_TYPE, text, 12, fg_color, bg_color), m_led_color(led_color)
UI_led::UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject* parrent)
: UI_item(id, UI_LED_TYPE, text, 12, fg_color, bg_color, parrent), m_led_color(led_color)
{
}
UI_led::UI_led(const json &j) : UI_item(UI_LED_TYPE)
UI_led::UI_led(const json &j, QObject* parrent) : UI_item(UI_LED_TYPE, parrent)
{
from_json(j);
}
@@ -17,7 +17,11 @@ Color UI_led::led_color() const
void UI_led::set_led_color(Color led_color)
{
m_led_color = led_color;
if (m_led_color != led_color)
{
m_led_color = led_color;
emit value_changed();
}
}
void UI_led::from_json(const json &j)
@@ -33,4 +37,4 @@ json UI_led::to_json() const
json j = UI_item::to_json();
j["led_color"] = m_led_color.to_hex();
return j;
}
}
+4 -3
View File
@@ -6,9 +6,10 @@
class UI_led : public UI_item
{
Q_OBJECT
public:
UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color);
UI_led(const json &j);
UI_led(std::string id, std::string text, Color fg_color, Color bg_color, Color led_color, QObject* parrent = nullptr);
UI_led(const json &j, QObject* parrent = nullptr);
Color led_color() const;
void set_led_color(Color led_color);
@@ -18,4 +19,4 @@ class UI_led : public UI_item
private:
Color m_led_color;
};
};
+7 -9
View File
@@ -1,13 +1,13 @@
#include "UI_slider.hpp"
UI_slider::UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max,
double value, std::function<void(std::string, double)> on_change)
: UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value)
double value, QObject* parrent)
: UI_item(id, UI_SLIDER_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
this->m_on_change = on_change;
}
UI_slider::UI_slider(const json &j) : UI_item(UI_SLIDER_TYPE), m_on_change(nullptr)
UI_slider::UI_slider(const json &j, QObject* parrent) : UI_item(UI_SLIDER_TYPE, parrent)
{
from_json(j);
}
@@ -20,10 +20,8 @@ void UI_slider::set_value(double value)
return;
this->m_value = value;
if (m_on_change != nullptr)
{
std::thread([this] { m_on_change(m_id, m_value); }).detach();
}
emit value_changed();
emit on_change(m_id, m_value);
}
double UI_slider::value() const
@@ -57,4 +55,4 @@ json UI_slider::to_json() const
j["max"] = this->m_max;
j["value"] = this->m_value;
return j;
}
}
+6 -6
View File
@@ -5,10 +5,10 @@
class UI_slider : public UI_item
{
Q_OBJECT
public:
UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value,
std::function<void(std::string, double)> on_change = nullptr);
UI_slider(const json &j);
UI_slider(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
UI_slider(const json &j, QObject* parrent = nullptr);
void set_value(double value) override;
double value() const;
@@ -18,11 +18,11 @@ class UI_slider : public UI_item
void from_json(const json &j) override;
json to_json() const override;
signals:
void on_change(std::string id, double value);
private:
double m_min;
double m_max;
double m_value;
std::function<void(std::string, double)> m_on_change;
};
};
+7 -9
View File
@@ -1,12 +1,11 @@
#include "UI_textbox.hpp"
UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color,
std::function<void(std::string, std::string)> on_change)
: UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color), m_hint(hint), m_on_change(on_change)
UI_textbox::UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject* parrent)
: UI_item(id, UI_TEXTBOX_TYPE, "", 0, fg_color, bg_color, parrent), m_hint(hint)
{
}
UI_textbox::UI_textbox(const json &j) : UI_item(UI_TEXTBOX_TYPE), m_on_change(nullptr)
UI_textbox::UI_textbox(const json &j, QObject* parrent) : UI_item(UI_TEXTBOX_TYPE, parrent)
{
from_json(j);
}
@@ -16,15 +15,14 @@ void UI_textbox::set_text(std::string text)
if (text == m_text)
return;
m_text = text;
if (m_on_change != nullptr)
{
std::thread([this] { m_on_change(m_id, m_text); }).detach();
}
emit value_changed();
emit on_change(m_id, m_text);
}
void UI_textbox::set_hint(std::string hint)
{
m_hint = hint;
emit value_changed();
}
std::string UI_textbox::hint() const
@@ -43,4 +41,4 @@ json UI_textbox::to_json() const
json j = UI_item::to_json();
j["hint"] = m_hint;
return j;
}
}
+6 -5
View File
@@ -6,10 +6,10 @@
class UI_textbox : public UI_item
{
Q_OBJECT
public:
UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color,
std::function<void(std::string, std::string)> on_change = nullptr);
UI_textbox(const json &j);
UI_textbox(std::string id, std::string hint, Color fg_color, Color bg_color, QObject* parrent = nullptr);
UI_textbox(const json &j, QObject* parrent = nullptr);
void set_text(std::string text) override;
@@ -18,8 +18,9 @@ class UI_textbox : public UI_item
void from_json(const json &j) override;
json to_json() const override;
signals:
void on_change(std::string id, std::string text);
private:
std::string m_hint;
std::function<void(std::string, std::string)> m_on_change;
};
};
+11 -4
View File
@@ -1,12 +1,12 @@
#include "UI_thermo.hpp"
UI_thermo::UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max,
double value)
: UI_item(id, UI_THERMO_TYPE, text, 12, fg_color, bg_color), m_min(min), m_max(max), m_value(value)
double value, QObject* parrent)
: UI_item(id, UI_THERMO_TYPE, text, 12, fg_color, bg_color, parrent), m_min(min), m_max(max), m_value(value)
{
}
UI_thermo::UI_thermo(const json &j) : UI_item(UI_THERMO_TYPE)
UI_thermo::UI_thermo(const json &j, QObject* parrent) : UI_item(UI_THERMO_TYPE, parrent)
{
from_json(j);
}
@@ -19,6 +19,7 @@ void UI_thermo::set_value(double value)
return;
this->m_value = value;
emit value_changed();
}
double UI_thermo::value() const
@@ -39,11 +40,13 @@ double UI_thermo::max() const
void UI_thermo::set_start_color(Color color)
{
this->m_color_map[0] = color;
emit value_changed();
}
void UI_thermo::set_end_color(Color color)
{
this->m_color_map[1] = color;
emit value_changed();
}
void UI_thermo::add_color_stop(double value, Color color)
@@ -52,6 +55,7 @@ void UI_thermo::add_color_stop(double value, Color color)
return;
this->m_color_map[value] = color;
emit value_changed();
}
void UI_thermo::add_color_stop_normalized(double value, Color color)
@@ -61,6 +65,7 @@ void UI_thermo::add_color_stop_normalized(double value, Color color)
double normalized = (value - m_min) / (m_max - m_min);
this->m_color_map[normalized] = color;
emit value_changed();
}
void UI_thermo::remove_color_stop(double value)
@@ -69,6 +74,7 @@ void UI_thermo::remove_color_stop(double value)
return;
this->m_color_map.erase(value);
emit value_changed();
}
void UI_thermo::remove_color_stop_normalized(double value)
@@ -78,6 +84,7 @@ void UI_thermo::remove_color_stop_normalized(double value)
double normalized = (value - m_min) / (m_max - m_min);
this->m_color_map.erase(normalized);
emit value_changed();
}
void UI_thermo::from_json(const json &j)
@@ -111,4 +118,4 @@ json UI_thermo::to_json() const
j["color_map"].push_back(item);
}
return j;
}
}
+4 -3
View File
@@ -6,9 +6,10 @@
// TODO: Add color scale
class UI_thermo : public UI_item
{
Q_OBJECT
public:
UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value);
UI_thermo(const json &j);
UI_thermo(std::string id, std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject* parrent = nullptr);
UI_thermo(const json &j, QObject* parrent = nullptr);
void set_value(double value) override;
double value() const;
@@ -31,4 +32,4 @@ class UI_thermo : public UI_item
double m_max;
double m_value;
std::unordered_map<double, Color> m_color_map;
};
};
+4 -4
View File
@@ -1,12 +1,12 @@
#include "UI_x_boxes.hpp"
UI_x_boxes::UI_x_boxes(std::string type) : UI_item(type), m_options()
UI_x_boxes::UI_x_boxes(std::string type, QObject* parrent) : UI_item(type, parrent), m_options()
{
}
UI_x_boxes::UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options)
: UI_item(id, type, text, 12, fg_color, bg_color), m_options(options)
std::vector<std::string> options, QObject* parrent)
: UI_item(id, type, text, 12, fg_color, bg_color, parrent), m_options(options)
{
}
@@ -28,4 +28,4 @@ json UI_x_boxes::to_json() const
json j = UI_item::to_json();
j["options"] = this->m_options;
return j;
}
}
+4 -3
View File
@@ -4,14 +4,15 @@
class UI_x_boxes : public UI_item
{
Q_OBJECT
public:
UI_x_boxes(std::string type);
UI_x_boxes(std::string type, QObject* parrent = nullptr);
UI_x_boxes(std::string id, std::string type, std::string text, Color fg_color, Color bg_color,
std::vector<std::string> options);
std::vector<std::string> options, QObject* parrent = nullptr);
void from_json(const json &j) override;
json to_json() const override;
protected:
std::vector<std::string> m_options;
};
};