mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
ui_items
Remove Text_size Add setup_item to configure if an item uses text, fg color and bg color.
This commit is contained in:
+41
-40
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user